diff options
| author | Kenichi Handa | 2003-03-26 04:42:29 +0000 |
|---|---|---|
| committer | Kenichi Handa | 2003-03-26 04:42:29 +0000 |
| commit | 9bdbd98e4076537d08cc92ad05018cb8b1200e54 (patch) | |
| tree | f3a082fa1be49a4bd1dd61596f1ac1400b124e04 | |
| parent | 527b7890aa58bb72b11eeb7780dbe276945bb995 (diff) | |
| download | emacs-9bdbd98e4076537d08cc92ad05018cb8b1200e54.tar.gz emacs-9bdbd98e4076537d08cc92ad05018cb8b1200e54.zip | |
(recode-file-name): New function.
| -rw-r--r-- | lisp/files.el | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lisp/files.el b/lisp/files.el index acfea07992f..9216a6b2bf1 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -766,6 +766,58 @@ unlike `file-truename'." | |||
| 766 | (setq newname (expand-file-name tem (file-name-directory newname))) | 766 | (setq newname (expand-file-name tem (file-name-directory newname))) |
| 767 | (setq count (1- count)))) | 767 | (setq count (1- count)))) |
| 768 | newname)) | 768 | newname)) |
| 769 | |||
| 770 | (defun recode-file-name (file coding new-coding &optional ok-if-already-exists) | ||
| 771 | "Change the encoding of FILE's name from CODING to NEW-CODING. | ||
| 772 | The value is a new name of FILE. | ||
| 773 | Signals a `file-already-exists' error if a file of the new name | ||
| 774 | already exists unless optional third argument OK-IF-ALREADY-EXISTS | ||
| 775 | is non-nil. A number as third arg means request confirmation if | ||
| 776 | the new name already exists. This is what happens in interactive | ||
| 777 | use with M-x." | ||
| 778 | (interactive | ||
| 779 | (let ((default-coding (or file-name-coding-system | ||
| 780 | default-file-name-coding-system)) | ||
| 781 | (filename (read-file-name "Recode filename: " nil nil t)) | ||
| 782 | from-coding to-coding) | ||
| 783 | (if (and default-coding | ||
| 784 | ;; We provide the default coding only when it seems that | ||
| 785 | ;; the filename is correctly decoded by the default | ||
| 786 | ;; coding. | ||
| 787 | (let ((charsets (find-charset-string filename))) | ||
| 788 | (and (not (memq 'eight-bit-control charsets)) | ||
| 789 | (not (memq 'eight-bit-graphic charsets))))) | ||
| 790 | (setq from-coding (read-coding-system | ||
| 791 | (format "Recode filename %s from (default %s): " | ||
| 792 | filename default-coding) | ||
| 793 | default-coding)) | ||
| 794 | (setq from-coding (read-coding-system | ||
| 795 | (format "Recode filename %s from: " filename)))) | ||
| 796 | |||
| 797 | ;; We provide the default coding only when a user is going to | ||
| 798 | ;; change the encoding not from the default coding. | ||
| 799 | (if (eq from-coding default-coding) | ||
| 800 | (setq to-coding (read-coding-system | ||
| 801 | (format "Recode filename %s from %s to: " | ||
| 802 | filename from-coding))) | ||
| 803 | (setq to-coding (read-coding-system | ||
| 804 | (format "Recode filename %s from %s to (default %s): " | ||
| 805 | filename from-coding default-coding) | ||
| 806 | default-coding))) | ||
| 807 | (list filename from-coding to-coding))) | ||
| 808 | |||
| 809 | (let* ((default-coding (or file-name-coding-system | ||
| 810 | default-file-name-coding-system)) | ||
| 811 | ;; FILE should have been decoded by DEFAULT-CODING. | ||
| 812 | (encoded (encode-coding-string file default-coding)) | ||
| 813 | (newname (decode-coding-string encoded coding)) | ||
| 814 | (new-encoded (encode-coding-string newname new-coding)) | ||
| 815 | ;; Suppress further encoding. | ||
| 816 | (file-name-coding-system nil) | ||
| 817 | (default-file-name-coding-system nil) | ||
| 818 | (locale-coding-system nil)) | ||
| 819 | (rename-file encoded new-encoded ok-if-already-exists) | ||
| 820 | newname)) | ||
| 769 | 821 | ||
| 770 | (defun switch-to-buffer-other-window (buffer &optional norecord) | 822 | (defun switch-to-buffer-other-window (buffer &optional norecord) |
| 771 | "Select buffer BUFFER in another window. | 823 | "Select buffer BUFFER in another window. |