2

In this example, there is a character bearing number 182 with a string equivalent of . When evaluating the string at issue, the character is displayed correctly in the echo area. When trying to insert the string into a buffer or generate a message, the character is converted into \266 described by Emacs as a raw-byte. How can this string be inserted into the buffer as rather than \266?

EXAMPLE:

(message (let ((str "foo")) (aset str 2 ?\¶) str))

0

1 Answer 1

3

Here's an experiment you can try:

(let ((str "foo")) (aset str 2 ?¶) str)
"fo\266"

(let ((str (string-to-multibyte "foo"))) (aset str 2 ?¶) str)
"fo¶"

If I do

(let ((str1 "foo") (str2 (string-to-multibyte "foo"))) (string-equal str1 str2))
t
(let ((str1 "foo") (str2 (string-to-multibyte "foo"))) (aset str1 2 ?¶) (aset str2 2 ?¶) (string-equal str1 str2))
nil

So there must be a difference but I don't know how to tell (I've also tried with equal instead of string-equal with no change). If it makes a difference, the language environment was UTF-8.

EDIT: Here's another experiment that actually shows the difference in a more fundamental way:

(setq str "foo")
"foo"
(multibyte-string-p str)
nil
(string-bytes str)
3
(aset str 2 ?¶)
182
(string-bytes str)
3

(setq str (string-to-multibyte "foo"))
"foo"
(multibyte-string-p str)
t
(string-bytes str)
3
(aset str 2 ?¶)
182
(string-bytes str)
4

I think now it is an answer :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.