[Top][All Lists]

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

Re: Why does using aset sometimes output raw bytes?

From: Eli Zaretskii
Subject: Re: Why does using aset sometimes output raw bytes?
Date: Sun, 09 Dec 2018 19:12:32 +0200

> From: Stephen Berman <>
> Cc:
> Date: Sun, 09 Dec 2018 16:46:01 +0100
> > s0 and s2 originally include only pure ASCII characters, so they are
> > unibyte strings.  Try making them multibyte before using aset.
> Thanks, that works.  But why are raw bytes inserted only with some
> multibyte strings (e.g. with "äöüß" but not with "ſðđŋ")?

Because ſ doesn't fit in a single byte, so when you insert it, the
entire string is made multibyte, and then the other characters are
inserted into a multibyte string.

> Also, is there some way to ensure a string is handled as multibyte
> if it's not known what characters it contains?  E.g., s0 in my
> example sexp could be bound to some string by a function call and
> before applying the function it is not known if the string is
> multibyte;

You should generally keep away of such situations, but you don't tell
enough about what you are trying to accomplish to give more practical

To answer your question: you can test whether a string is multibyte
with multibyte-string-p, and you can make it multibyte if not.  The
only problematic situation is when a unibyte string includes non-ASCII
bytes; what is TRT in that situation depends on the situation.

> is there some way in Lisp to say "treat the value of s0 as multibyte
> (regardless of what characters it contains)"?

Not that I know of, no.  And I don't really understand how could such
a thing exist: how do you "treat as multibyte" an arbitrary byte that
is beyond 127 decimal?

> Also "aous" is also pure ASCII, so why don't raw bytes get inserted with
> (insert (aset "aous" i (aref "äöüß" i)))?

This inserts characters one by one into the current buffer, and the
buffer is multibyte, so Emacs does the conversion.  IOW, you don't
insert the string, you insert individual characters which aset

reply via email to

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