From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/68269 Path: news.gmane.org!not-for-mail From: Katsumi Yamaoka Newsgroups: gmane.emacs.gnus.general Subject: Re: sanitized mm-string-to-multibyte Date: Tue, 10 Feb 2009 09:12:42 +0900 Organization: Emacsen advocacy group Message-ID: References: <8763jkg7cu.fsf@liv.ac.uk> <8763jjchs7.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 1234224851 2488 80.91.229.12 (10 Feb 2009 00:14:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 10 Feb 2009 00:14:11 +0000 (UTC) Cc: bugs@gnus.org, ding@gnus.org To: Dave Love Original-X-From: ding-owner+M16709@lists.math.uh.edu Tue Feb 10 01:15:26 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 1LWgHd-00033V-G8 for ding-account@gmane.org; Tue, 10 Feb 2009 01:15:25 +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 1LWgFm-0006jN-Na; Mon, 09 Feb 2009 18:13:30 -0600 Original-Received: from mx2.math.uh.edu ([129.7.128.33]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1LWgFl-0006j7-C8 for ding@lists.math.uh.edu; Mon, 09 Feb 2009 18:13:29 -0600 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx2.math.uh.edu with esmtp (Exim 4.69) (envelope-from ) id 1LWgFi-0000lh-A5 for ding@lists.math.uh.edu; Mon, 09 Feb 2009 18:13:29 -0600 Original-Received: from orlando.hostforweb.net ([216.246.45.90]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1LWgG1-0005hJ-00; Tue, 10 Feb 2009 01:13:45 +0100 Original-Received: from localhost ([127.0.0.1]:53144) by orlando.hostforweb.net with esmtpa (Exim 4.69) (envelope-from ) id 1LWgF6-0003dD-LK; Mon, 09 Feb 2009 18:12:49 -0600 X-Hashcash: 1:20:090210:fx@gnu.org::g/2VZbsbdhu/GTW1:00000006GuO X-Hashcash: 1:20:090210:bugs@gnus.org::UUWk5CpGFlq740mM:000006r5 X-Hashcash: 1:20:090210:ding@gnus.org::0LXfisY4FZ/Rpzfh:00001V9N X-Face: #kKnN,xUnmKia.'[pp`;Omh}odZK)?7wQSl"4o04=EixTF+V[""w~iNbM9ZL+.b*_CxUmFk B#Fu[*?MZZH@IkN:!"\w%I_zt>[$nm7nQosZ<3eu;B:$Q_:p!',P.c0-_Cy[dz4oIpw0ESA^D*1Lw= L&i*6&( User-Agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.90 (gnu/linux) Cancel-Lock: sha1:/TXmDqydArrk+PTN/Ee4hILxBAw= X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - orlando.hostforweb.net X-AntiAbuse: Original Domain - gnus.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - jpl.org X-Source: X-Source-Args: X-Source-Dir: X-Spam-Score: -2.6 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:68269 Archived-At: >>>>> Dave Love wrote: > 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. I verified how (eval-when-compile (string-as-multibyte "")) behaves with this test.el file: (defun test () (let ((s1 "") (s2 (eval-when-compile (string-as-multibyte ""))) (s3 (eval-when-compile (string-as-unibyte "")))) (message "%s %s %s" (multibyte-string-p s1) (multibyte-string-p s2) (multibyte-string-p s3)))) (test) $ emacs-21.4 -batch -q -l ./test.el => nil t nil $ emacs-21.4 -batch -q -f batch-byte-compile ./test.el $ emacs-21.4 -batch -q -l ./test.elc => nil nil nil So there seems to be no difference in those ""s in the byte compiled file. > 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