From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/68267 Path: news.gmane.org!not-for-mail From: Dave Love Newsgroups: gmane.emacs.gnus.general Subject: Re: sanitized mm-string-to-multibyte Date: Mon, 09 Feb 2009 23:27:52 +0000 Message-ID: <8763jjchs7.fsf@liv.ac.uk> References: <8763jkg7cu.fsf@liv.ac.uk> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1234222140 27621 80.91.229.12 (9 Feb 2009 23:29:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Feb 2009 23:29:00 +0000 (UTC) Cc: "bugs\@gnus.org" , "ding\@gnus.org" To: Katsumi Yamaoka Original-X-From: ding-owner+M16707@lists.math.uh.edu Tue Feb 10 00:30:14 2009 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.50) id 1LWfZt-0006r1-Qk for ding-account@gmane.org; Tue, 10 Feb 2009 00:30:14 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1LWfYM-0006Qz-R3; Mon, 09 Feb 2009 17:28:38 -0600 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1LWfYK-0006Qe-Q9 for ding@lists.math.uh.edu; Mon, 09 Feb 2009 17:28:36 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1LWfYH-0003Gl-NW for ding@lists.math.uh.edu; Mon, 09 Feb 2009 17:28:36 -0600 Original-Received: from mxc.liv.ac.uk ([138.253.100.103]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1LWfYb-00054P-00 for ; Tue, 10 Feb 2009 00:28:53 +0100 Original-Received: from mailhubd.liv.ac.uk ([138.253.100.81]) by mxc.liv.ac.uk with esmtp (Exim 4.67) (envelope-from ) id 1LWfXm-0002Dt-4c for ding@gnus.org; Mon, 09 Feb 2009 23:28:02 +0000 Original-Received: from localhost ([127.0.0.1] helo=mailhubd.liv.ac.uk) by mailhubd.liv.ac.uk with esmtp (Exim 4.67) (envelope-from ) id 1LWfXm-0006Dz-3S; Mon, 09 Feb 2009 23:28:02 +0000 Original-Received: from pc102091.liv.ac.uk ([138.253.102.91] helo=albion) by mailhubd.liv.ac.uk with esmtps (TLSv1:AES256-SHA:256) (Exim 4.67) (envelope-from ) id 1LWfXl-0006Dw-W0; Mon, 09 Feb 2009 23:28:01 +0000 Original-Received: from dlove by albion with local (Exim 4.69) (envelope-from ) id 1LWfXc-0006O3-Bn; Mon, 09 Feb 2009 23:27:52 +0000 X-Draft-From: ("nnimap+imap.liv.ac.uk:Misc" 3786) In-Reply-To: (Katsumi Yamaoka's message of "Mon, 9 Feb 2009 10:28:03 +0000") User-Agent: Gnus/5.110011 (No Gnus v0.11) X-Spam-Score: -5.6 (-----) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:68267 Archived-At: Katsumi Yamaoka 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