[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte b
From: |
Robert Pluim |
Subject: |
Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer |
Date: |
Mon, 27 May 2019 15:02:42 +0200 |
>>>>> On Mon, 27 May 2019 08:24:46 -0400, Stefan Monnier <address@hidden> said:
>> A related issue: C-h f string-as-unibyte
>>
>> string-as-unibyte is a built-in function in `src/fns.c'.
>>
>> (string-as-unibyte STRING)
>>
>> This function is obsolete since 26.1;
>> use `encode-coding-string'.
>> Probably introduced at or before Emacs version 20.3.
>> This function does not change global state, including the match data.
>>
>> Having trawled through the elisp manual, for the life of me itʼs not
>> clear which coding system I should use. 'raw-text'? 'us-ascii'?
>> Something Else?
Stefan> The coding that most closely corresponds to what string-as-unibyte
does
Stefan> is `emacs-internal`. In 90% of the cases, it's not what you want,
tho
Stefan> because the code shouldn't have used string-as-unibyte in the
Stefan> first place, so you'll need to find out what the code *really*
needs.
Almost all uses of string-as-unibyte are gone now, but the one I was
looking at is this one in international/mule-cmds.el:
(defun encoded-string-description (str coding-system)
"Return a pretty description of STR that is encoded by CODING-SYSTEM."
(setq str (string-as-unibyte str))
(mapconcat
(if (and coding-system (eq (coding-system-type coding-system) 'iso-2022))
;; Try to get a pretty description for ISO 2022 escape sequences.
(function (lambda (x) (or (cdr (assq x iso-2022-control-alist))
(format "#x%02X" x))))
(function (lambda (x) (format "#x%02X" x))))
str " "))
If I take a string of say "β", and replace string-as-unibyte with
(encode-coding-string 'emacs-internal), `encoded-string-description'
prints "#xCE #xB2", which is the correct UTF-8 encoded
value. 'raw-text works too. Iʼm certain that there are subtle
differences between the two that I donʼt understand.
Robert
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Robert Pluim, 2019/05/27
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Stefan Monnier, 2019/05/27
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer,
Robert Pluim <=
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Stefan Monnier, 2019/05/27
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Robert Pluim, 2019/05/27
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Eli Zaretskii, 2019/05/27
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Robert Pluim, 2019/05/28
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Eli Zaretskii, 2019/05/28
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Stefan Monnier, 2019/05/27
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Eli Zaretskii, 2019/05/28
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Stefan Monnier, 2019/05/28
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Eli Zaretskii, 2019/05/28
- Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer, Stefan Monnier, 2019/05/28