/[emacs]/emacs/lisp/files.el
ViewVC logotype

Diff of /emacs/lisp/files.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.643 by jpw, Fri Mar 14 22:36:57 2003 UTC revision 1.644 by handa, Wed Mar 26 04:42:29 2003 UTC
# Line 766  unlike `file-truename'." Line 766  unlike `file-truename'."
766          (setq newname (expand-file-name tem (file-name-directory newname)))          (setq newname (expand-file-name tem (file-name-directory newname)))
767          (setq count (1- count))))          (setq count (1- count))))
768      newname))      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))
821    
822  (defun switch-to-buffer-other-window (buffer &optional norecord)  (defun switch-to-buffer-other-window (buffer &optional norecord)
823    "Select buffer BUFFER in another window.    "Select buffer BUFFER in another window.

Legend:
Removed from v.1.643  
changed lines
  Added in v.1.644

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26