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: ISO-8859-1 encoded file names and UTF-8 Date: Wed, 26 Mar 2003 13:47:27 +0900 (JST) Sender: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Message-ID: <200303260447.NAA08818@etlken.m17n.org> References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 (generated by SEMI 1.14.3 - "Ushinoya") Content-Type: text/plain; charset=US-ASCII X-Trace: main.gmane.org 1048654189 6508 80.91.224.249 (26 Mar 2003 04:49:49 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Wed, 26 Mar 2003 04:49:49 +0000 (UTC) Cc: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Wed Mar 26 05:49:47 2003 Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18y2rD-0001go-00 for ; Wed, 26 Mar 2003 05:49:47 +0100 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 18y2sR-0005Cl-00 for ; Wed, 26 Mar 2003 05:51:04 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18y2qp-0004wH-04 for emacs-devel@quimby.gnus.org; Tue, 25 Mar 2003 23:49:23 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18y2q9-0004ON-00 for emacs-devel@gnu.org; Tue, 25 Mar 2003 23:48:41 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18y2pd-0002gO-00 for emacs-devel@gnu.org; Tue, 25 Mar 2003 23:48:13 -0500 Original-Received: from tsukuba.m17n.org ([192.47.44.130]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18y2p0-0000zm-00; Tue, 25 Mar 2003 23:47:31 -0500 Original-Received: from fs.m17n.org (fs.m17n.org [192.47.44.2])h2Q4lR908222; Wed, 26 Mar 2003 13:47:27 +0900 (JST) (envelope-from handa@m17n.org) Original-Received: from etlken.m17n.org (etlken.m17n.org [192.47.44.125]) h2Q4lRA28017; Wed, 26 Mar 2003 13:47:27 +0900 (JST) Original-Received: (from handa@localhost) by etlken.m17n.org (8.8.8+Sun/3.7W-2001040620) id NAA08818; Wed, 26 Mar 2003 13:47:27 +0900 (JST) Original-To: rms@gnu.org In-reply-to: (message from Richard Stallman on Mon, 24 Mar 2003 14:27:32 -0500) User-Agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.2.92 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI) Original-cc: keichwa@gmx.net X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: Emacs development discussions. List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: emacs-devel-bounces+emacs-devel=quimby.gnus.org@gnu.org Xref: main.gmane.org gmane.emacs.devel:12627 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:12627 In article , Richard Stallman writes: > So, I wanted to hear other people's opinions about which is > better; enhancing the existing rename-file directly (perhaps > by making use of the prefix argument), or making a new > command recode-file-name. > It should be a new command. I've just installed the attached change. --- Ken'ichi HANDA handa@m17n.org 2003-03-26 Kenichi Handa * files.el (recode-file-name): New function. Index: files.el =================================================================== RCS file: /cvsroot/emacs/emacs/lisp/files.el,v retrieving revision 1.643 retrieving revision 1.644 diff -u -c -r1.643 -r1.644 cvs server: conflicting specifications of output style *** files.el 14 Mar 2003 22:36:57 -0000 1.643 --- files.el 26 Mar 2003 04:42:29 -0000 1.644 *************** *** 766,771 **** --- 766,823 ---- (setq newname (expand-file-name tem (file-name-directory newname))) (setq count (1- count)))) newname)) + + (defun recode-file-name (file coding new-coding &optional ok-if-already-exists) + "Change the encoding of FILE's name from CODING to NEW-CODING. + The value is a new name of FILE. + Signals a `file-already-exists' error if a file of the new name + already exists unless optional third argument OK-IF-ALREADY-EXISTS + is non-nil. A number as third arg means request confirmation if + the new name already exists. This is what happens in interactive + use with M-x." + (interactive + (let ((default-coding (or file-name-coding-system + default-file-name-coding-system)) + (filename (read-file-name "Recode filename: " nil nil t)) + from-coding to-coding) + (if (and default-coding + ;; We provide the default coding only when it seems that + ;; the filename is correctly decoded by the default + ;; coding. + (let ((charsets (find-charset-string filename))) + (and (not (memq 'eight-bit-control charsets)) + (not (memq 'eight-bit-graphic charsets))))) + (setq from-coding (read-coding-system + (format "Recode filename %s from (default %s): " + filename default-coding) + default-coding)) + (setq from-coding (read-coding-system + (format "Recode filename %s from: " filename)))) + + ;; We provide the default coding only when a user is going to + ;; change the encoding not from the default coding. + (if (eq from-coding default-coding) + (setq to-coding (read-coding-system + (format "Recode filename %s from %s to: " + filename from-coding))) + (setq to-coding (read-coding-system + (format "Recode filename %s from %s to (default %s): " + filename from-coding default-coding) + default-coding))) + (list filename from-coding to-coding))) + + (let* ((default-coding (or file-name-coding-system + default-file-name-coding-system)) + ;; FILE should have been decoded by DEFAULT-CODING. + (encoded (encode-coding-string file default-coding)) + (newname (decode-coding-string encoded coding)) + (new-encoded (encode-coding-string newname new-coding)) + ;; Suppress further encoding. + (file-name-coding-system nil) + (default-file-name-coding-system nil) + (locale-coding-system nil)) + (rename-file encoded new-encoded ok-if-already-exists) + newname)) (defun switch-to-buffer-other-window (buffer &optional norecord) "Select buffer BUFFER in another window. Index: NEWS =================================================================== RCS file: /cvsroot/emacs/emacs/etc/NEWS,v retrieving revision 1.799 retrieving revision 1.800 diff -u -c -r1.799 -r1.800 cvs server: conflicting specifications of output style *** NEWS 8 Mar 2003 02:13:59 -0000 1.799 --- NEWS 26 Mar 2003 04:45:00 -0000 1.800 *************** *** 138,143 **** --- 138,146 ---- ** The new command `revert-buffer-with-coding-system' (C-x RET r) revisits the current file using a coding system that you specify. + ** The new command `recode-file-name' changes the encoding of the name + of a file. + --- ** `ps-print' can now print characters from the mule-unicode charsets.