[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obsolete string-to-multibyte hard to replace

From: Noam Postavsky
Subject: Re: Obsolete string-to-multibyte hard to replace
Date: Mon, 29 May 2017 20:21:01 -0400

On Mon, May 29, 2017 at 9:01 AM, Stefan Monnier
<address@hidden> wrote:
> I was looking at ruler-mode.el's bytecomp warning about string-to-multibyte
> and it seems like there is no good way to write cleaner code here:
>    (let (...
>          (ruler
>           (propertize
>            (string-to-multibyte
>             (make-string w ruler-mode-basic-graduation-char))
>             ...))
>          ...)
>     [...]
>           (aset ruler k (aref c (setq m (1- m))))
> Here, the problem is as follows: make-string returns a unibyte string if
> the initial char is ASCII and a multibyte string otherwise.
> Seems innucuous, but it means that if the initial char
> (ruler-mode-basic-graduation-char above) is ASCII, you can't later
> insert a multibyte char into that string with `aset`.

We could the collect the characters in a vector and then only convert
to string at the end. Haven't you said that strings should ideally be
treated as immutable?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]