From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kenichi Handa Newsgroups: gmane.emacs.devel Subject: Re: Run coding system auto-detection manually? Date: Wed, 7 Aug 2002 17:24:55 +0900 (JST) Sender: emacs-devel-admin@gnu.org Message-ID: <200208070824.RAA17705@etlken.m17n.org> References: NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: main.gmane.org 1028708734 30995 127.0.0.1 (7 Aug 2002 08:25:34 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 7 Aug 2002 08:25:34 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17cM8L-00083o-00 for ; Wed, 07 Aug 2002 10:25:33 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17cMTr-0000JZ-00 for ; Wed, 07 Aug 2002 10:47:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.35 #1 (Debian)) id 17cM8r-0007O9-00; Wed, 07 Aug 2002 04:26:05 -0400 Original-Received: from tsukuba.m17n.org ([192.47.44.130]) by fencepost.gnu.org with smtp (Exim 3.35 #1 (Debian)) id 17cM7v-0007Fn-00 for ; Wed, 07 Aug 2002 04:25:07 -0400 Original-Received: from fs.m17n.org (fs.m17n.org [192.47.44.2]) by tsukuba.m17n.org (8.11.6/3.7W-20010518204228) with ESMTP id g778Oul11555; Wed, 7 Aug 2002 17:24:56 +0900 (JST) (envelope-from handa@m17n.org) Original-Received: from etlken.m17n.org (etlken.m17n.org [192.47.44.125]) by fs.m17n.org (8.11.3/3.7W-20010823150639) with ESMTP id g778Ot909457; Wed, 7 Aug 2002 17:24:55 +0900 (JST) Original-Received: (from handa@localhost) by etlken.m17n.org (8.8.8+Sun/3.7W-2001040620) id RAA17705; Wed, 7 Aug 2002 17:24:55 +0900 (JST) Original-To: Kai.Grossjohann@CS.Uni-Dortmund.DE User-Agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.1.30 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI) Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:6329 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:6329 In article , Kai.Grossjohann@CS.Uni-Dortmund.DE (Kai Gro=DFjohann) writes: > Kai.Grossjohann@cs.uni-dortmund.de (Kai Gro=DFjohann) writes: >> Suppose I have a buffer and hit C-x C-s. Then Emacs figures out a >> coding system to use, possibly based on the filename. >>=20 >> But I would like to use write-region to write the buffer contents to >> another file, but I would like this call to use the same coding >> system that Emacs would have used for C-x C-s. > After reading the C code, I get the impression that I can always use > find-operation-coding-system explicitly to find the right coding > system to use. Right? find-operation-coding-system does only partial task for deciding a coding system. For your task, I think you must simulate what choose_write_coding_system does which includes these things: o check the local binding of buffer-file-coding-system o check the value of enable-multibyte-characters o call find-operation-coding-system o call select-safe-coding-system-function o if end-of-line format is still undecided, use that of default-buffer-file-coding system > (write-region (point-min) (point-max) > tempname nil realname > buffer-file-truename) > This is in the "precious" case. So you can see that the real > filename is in the VISIT argument, not in the LOCKNAME argument. I > got those two confused before. > Presumably, the intent was that write-region choose the coding system > based on realname instead of tempname. > But looking in the code for write-region, I don't find any evidence > that it looks at VISIT, only at FILENAME, for detecting the coding > system. Hm. > Maybe in the above call, tempname has been devised in such a way that > choose_write_coding_system chooses the "right" coding. No, I don't think so. TEMPNAME may not match a pattern that a user specified in file-coding-system-alist for REALNAME, or TEMPNAME may match a pattern that a user specified for the other kind of files. So, for the case of a precious file, I think we must check VISIT (if that is string) instead of FILENAME in find-operation-coding-system. What do you think about the this patch? --- Ken'ichi HANDA handa@etl.go.jp *** coding.c.~1.252.~ Mon Jul 29 13:28:42 2002 --- coding.c Wed Aug 7 17:20:00 2002 *************** *** 6878,6883 **** --- 6878,6890 ---- if (nargs < 1 + XINT (target_idx)) error ("Too few arguments for operation: %s", SDATA (SYMBOL_NAME (operation))); + /* For write-region, if the 6th argument (i.e. VISIT, the 5th + argument to write-region) is string, it must be treated as a + target file name. */ + if (EQ (operation, Qwrite_region) + && nargs > 5 + && STRINGP (args[5])) + target_idx =3D 4; target =3D args[XINT (target_idx) + 1]; if (!(STRINGP (target) || (EQ (operation, Qopen_network_stream) && INTEGERP (target))))