From: Robert Pluim <rpluim@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer
Date: Mon, 27 May 2019 15:02:42 +0200 [thread overview]
Message-ID: <m2k1ec9hjh.fsf@gmail.com> (raw)
In-Reply-To: <jwvr28kozn3.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Mon, 27 May 2019 08:24:46 -0400")
>>>>> On Mon, 27 May 2019 08:24:46 -0400, Stefan Monnier <monnier@iro.umontreal.ca> 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
next prev parent reply other threads:[~2019-05-27 13:02 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190525191039.14136.23307@vcs0.savannah.gnu.org>
[not found] ` <20190525191040.CCD6C207F5@vcs0.savannah.gnu.org>
2019-05-25 19:41 ` [Emacs-diffs] emacs-26 8f18d12: Improve documentation of decoding into a unibyte buffer Stefan Monnier
2019-05-25 19:59 ` Eli Zaretskii
2019-05-25 20:15 ` Eli Zaretskii
2019-05-25 21:11 ` Stefan Monnier
2019-05-25 21:27 ` Stefan Monnier
2019-05-26 2:37 ` Eli Zaretskii
2019-05-27 9:47 ` Robert Pluim
2019-05-27 12:24 ` Stefan Monnier
2019-05-27 13:02 ` Robert Pluim [this message]
2019-05-27 13:32 ` Stefan Monnier
2019-05-27 13:49 ` Robert Pluim
2019-05-27 16:53 ` Eli Zaretskii
2019-05-28 6:23 ` Robert Pluim
2019-05-28 14:57 ` Eli Zaretskii
2019-05-28 3:08 ` Stefan Monnier
2019-05-28 4:40 ` Eli Zaretskii
2019-05-28 11:55 ` Stefan Monnier
2019-05-28 15:18 ` Eli Zaretskii
2019-05-28 17:43 ` Stefan Monnier
2019-05-28 18:58 ` Eli Zaretskii
2019-05-28 19:35 ` Eli Zaretskii
2019-05-28 23:44 ` Stefan Monnier
2019-05-29 14:33 ` Eli Zaretskii
2019-05-27 16:51 ` Eli Zaretskii
2019-05-27 19:17 ` Stefan Monnier
2019-05-28 2:30 ` Eli Zaretskii
2019-05-28 2:56 ` Stefan Monnier
2019-05-28 4:17 ` Eli Zaretskii
2019-05-28 6:21 ` Robert Pluim
2019-05-28 11:53 ` Stefan Monnier
2019-05-28 11:54 ` Stefan Monnier
2019-05-28 15:11 ` Eli Zaretskii
2019-05-28 17:25 ` Stefan Monnier
2019-05-28 18:51 ` Eli Zaretskii
2019-05-28 23:39 ` Stefan Monnier
2019-05-29 2:45 ` Eli Zaretskii
2019-05-29 16:28 ` Stefan Monnier
2019-05-29 18:19 ` Eli Zaretskii
2019-05-29 18:58 ` Stefan Monnier
2019-05-29 19:09 ` Eli Zaretskii
2019-05-29 19:50 ` Stefan Monnier
2019-05-27 16:43 ` Eli Zaretskii
2019-05-27 16:42 ` Eli Zaretskii
2019-05-27 19:13 ` Stefan Monnier
2019-05-27 16:40 ` Eli Zaretskii
2019-05-27 20:17 ` Richard Stallman
2019-05-28 2:36 ` Eli Zaretskii
2019-05-28 7:06 ` Robert Pluim
2019-05-28 14:59 ` Eli Zaretskii
2019-05-28 15:11 ` Robert Pluim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2k1ec9hjh.fsf@gmail.com \
--to=rpluim@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.