From: Dave Love <fx@gnu.org>
To: Katsumi Yamaoka <yamaoka@jpl.org>
Cc: "bugs\@gnus.org" <bugs@gnus.org>, "ding\@gnus.org" <ding@gnus.org>
Subject: Re: sanitized mm-string-to-multibyte
Date: Mon, 09 Feb 2009 23:27:52 +0000 [thread overview]
Message-ID: <8763jjchs7.fsf@liv.ac.uk> (raw)
In-Reply-To: <b4m7i3zx5u4.fsf@jpl.org> (Katsumi Yamaoka's message of "Mon, 9 Feb 2009 10:28:03 +0000")
Katsumi Yamaoka <yamaoka@jpl.org> writes:
> Your version of `mm-string-to-multibyte' doesn't seem to convert
> a unibyte string to a multibyte string. In Emacs 21.1~21.4 I got:
>
> (let* ((s1 (string-as-unibyte "a"))
> (s2 (mm-with-preserved-unibyte (string-make-multibyte s1))))
> (list (multibyte-string-p s1) (multibyte-string-p s2)))
> => (nil nil)
>
> (let* ((s1 (string-as-multibyte "a"))
> (s2 (mm-with-preserved-unibyte (string-make-multibyte s1))))
> (list (multibyte-string-p s1) (multibyte-string-p s2)))
> => (t t)
>
> Did I miss something?
I think it doesn't cons a new string in the trivial case like that, when
it won't matter. Use this version if you want always to cons a
multibyte string.
Index: mm-util.el
===================================================================
RCS file: /usr/local/cvsroot/gnus/lisp/mm-util.el,v
retrieving revision 7.91
diff -u -r7.91 mm-util.el
--- mm-util.el 14 Jan 2009 00:52:01 -0000 7.91
+++ mm-util.el 9 Feb 2009 23:26:20 -0000
@@ -202,6 +202,22 @@
(defalias 'mm-decode-coding-region 'decode-coding-region)
(defalias 'mm-encode-coding-region 'encode-coding-region)))
+(defconst mm-identity-nat (let (l)
+ (dotimes (i 256)
+ (push (cons i i) l))
+ (make-translation-table l))
+ "Non-ASCII translation table that applies the identity translation.")
+
+(defmacro mm-with-preserved-unibyte (&rest body)
+ "Execute BODY forms while preserving unibyte characters.
+Such characters are not converted automatically to multibyte ones
+when, for instance, inserted into a multibyte buffer within the
+BODY forms."
+ `(let ((nonascii-translation-table mm-identity-nat))
+ ,@body))
+(put 'mm-with-preserved-unibyte 'lisp-indent-function 0)
+(put 'mm-with-preserved-unibyte 'edebug-form-spec '(body))
+
;; `string-to-multibyte' is available only in Emacs 22.1 or greater.
(defalias 'mm-string-to-multibyte
(cond
@@ -210,11 +226,9 @@
((fboundp 'string-to-multibyte)
'string-to-multibyte)
(t
- (lambda (string)
- "Return a multibyte string with the same individual chars as STRING."
- (mapconcat
- (lambda (ch) (mm-string-as-multibyte (char-to-string ch)))
- string "")))))
+ (lambda (s)
+ (mm-with-preserved-unibyte
+ (concat s (eval-when-compile (string-as-multibyte ""))))))))
;; `char-or-char-int-p' is an XEmacs function, not available in Emacs.
(eval-and-compile
next prev parent reply other threads:[~2009-02-09 23:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <8763jkg7cu.fsf@liv.ac.uk>
2009-02-09 10:28 ` Katsumi Yamaoka
2009-02-09 23:27 ` Dave Love [this message]
2009-02-10 0:12 ` Katsumi Yamaoka
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=8763jjchs7.fsf@liv.ac.uk \
--to=fx@gnu.org \
--cc=bugs@gnus.org \
--cc=ding@gnus.org \
--cc=yamaoka@jpl.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).