Subject: bug#7279: 24.0.50; print-escape-multibyte not honored

From: [email-masked]
Date: Mon, 30 Jan 2017 02:12:58 -0500

tags 7279 notabug
close 7279
quit

Helmut Eller <[email-masked]> writes:

> * Andreas Schwab [2010-10-25 18:02] writes:
>
>> Helmut Eller <[email-masked]> writes:
>>
>>> This code:
>>>
>>> (with-temp-file "/tmp/x.x"
>>>   (let ((print-escape-multibyte nil))
>>>     (prin1 (string ?\x03bb) (current-buffer))))
>>>
>>> writes "\x03bb" to the file, i.e. it seems to ignore the value
>>> of print-escape-multibyte.
>>
>> I cannot reprodoce that.  I also tried setting print-escape-multibyte to
>> t and got the expected effect.  Note that print-escape-multibyte is nil
>> by default anyway.
>
> And this?
>
> (with-temp-file "/tmp/x.x"
>   (set-buffer-multibyte nil)
>   (let ((print-escape-multibyte nil))
>     (prin1 (string ?\x80) (current-buffer))))
>

You can't print a multibyte string into a unibyte buffer, this works:

(with-temp-file "/tmp/x.x"
  (set-buffer-multibyte nil)
  (let ((print-escape-multibyte nil))
    (prin1 (unibyte-string ?\x80) (current-buffer))))

or if you want to handle unicode you must choose an encoding:

(with-temp-file "/tmp/x.x"
  (set-buffer-multibyte nil)
  (let ((print-escape-multibyte nil))
    (prin1 (encode-coding-string (string ?\x03bb) 'utf-8)
           (current-buffer))))