[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ISO-8859-1 encoded file names and UTF-8
From: |
Kenichi Handa |
Subject: |
Re: ISO-8859-1 encoded file names and UTF-8 |
Date: |
Wed, 26 Mar 2003 13:47:27 +0900 (JST) |
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) |
In article <address@hidden>, Richard Stallman <address@hidden> 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
address@hidden
2003-03-26 Kenichi Handa <address@hidden>
* 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.
- Re: ISO-8859-1 encoded file names and UTF-8, (continued)
- Re: ISO-8859-1 encoded file names and UTF-8, Kenichi Handa, 2003/03/19
- Re: ISO-8859-1 encoded file names and UTF-8, Karl Eichwalder, 2003/03/20
- Re: ISO-8859-1 encoded file names and UTF-8, Kenichi Handa, 2003/03/21
- Re: ISO-8859-1 encoded file names and UTF-8, Karl Eichwalder, 2003/03/21
- Re: ISO-8859-1 encoded file names and UTF-8, Richard Stallman, 2003/03/21
- Re: ISO-8859-1 encoded file names and UTF-8, Richard Stallman, 2003/03/20