From: Kenichi Handa <handa@m17n.org>
Cc: emacs-devel@gnu.org
Subject: Re: ISO-8859-1 encoded file names and UTF-8
Date: Wed, 26 Mar 2003 13:47:27 +0900 (JST) [thread overview]
Message-ID: <200303260447.NAA08818@etlken.m17n.org> (raw)
In-Reply-To: <E18xXbY-0005rn-00@fencepost.gnu.org> (message from Richard Stallman on Mon, 24 Mar 2003 14:27:32 -0500)
In article <E18xXbY-0005rn-00@fencepost.gnu.org>, Richard Stallman <rms@gnu.org> 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 <handa@etlken2>
* 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))
\f
(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.
next prev parent reply other threads:[~2003-03-26 4:47 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-03-08 6:15 ISO-8859-1 encoded file names and UTF-8 Karl Eichwalder
2003-03-08 9:16 ` Eli Zaretskii
2003-03-08 10:05 ` Karl Eichwalder
2003-03-08 17:06 ` Eli Zaretskii
2003-03-08 18:25 ` Karl Eichwalder
2003-03-08 22:35 ` Eli Zaretskii
2003-03-09 4:38 ` Karl Eichwalder
2003-03-19 13:33 ` Kenichi Handa
2003-03-19 16:15 ` Karl Eichwalder
2003-03-19 23:52 ` Kenichi Handa
2003-03-20 17:32 ` Karl Eichwalder
2003-03-21 6:01 ` Kenichi Handa
2003-03-21 19:53 ` Karl Eichwalder
2003-03-21 19:06 ` Richard Stallman
2003-03-20 8:46 ` Richard Stallman
2003-03-20 9:11 ` Kenichi Handa
2003-03-23 2:52 ` Richard Stallman
2003-03-24 0:28 ` Kenichi Handa
2003-03-24 19:27 ` Richard Stallman
2003-03-26 4:47 ` Kenichi Handa [this message]
2003-04-01 21:17 ` etags and UTF-8 encoded file names (Re: ISO-8859-1 encoded file names and UTF-8) Karl Eichwalder
2003-04-02 1:34 ` Kenichi Handa
2003-04-02 19:26 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200303260447.NAA08818@etlken.m17n.org \
--to=handa@m17n.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.