aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2008-04-09 20:17:27 +0000
committerMichael Albinus2008-04-09 20:17:27 +0000
commit9116dfe6479fd055fa37a2cbe653310ab43cb1b3 (patch)
tree59bff492cdf9031d5e2f21fc4a3579beb17787f5
parentc7ffd3f84e689f53920d88f2c896c15f92bd0645 (diff)
downloademacs-9116dfe6479fd055fa37a2cbe653310ab43cb1b3.tar.gz
emacs-9116dfe6479fd055fa37a2cbe653310ab43cb1b3.zip
* net/tramp.el (tramp-find-file-name-coding-system-alist): New
defun. (tramp-handle-insert-file-contents, tramp-handle-write-region): Use it.
-rw-r--r--lisp/net/tramp.el60
1 files changed, 41 insertions, 19 deletions
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index d6d6a524be9..aaac6bfda88 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3888,6 +3888,21 @@ This will break if COMMAND prints a newline, followed by the value of
3888 (t (tramp-make-tramp-file-name 3888 (t (tramp-make-tramp-file-name
3889 multi-method method user host ""))))))) 3889 multi-method method user host "")))))))
3890 3890
3891(defun tramp-find-file-name-coding-system-alist (filename tmpname)
3892 "Like `find-operation-coding-system' for Tramp filenames.
3893Tramp's `insert-file-contents' and `write-region' work over
3894temporary file names. If `file-coding-system-alist' contains an
3895expression, which matches more than the file name suffix, the
3896coding system might not be determined. This function repairs it."
3897 (let (result)
3898 (dolist (elt file-coding-system-alist result)
3899 (when (and (consp elt) (string-match (car elt) filename))
3900 ;; We found a matching entry in `file-coding-system-alist'.
3901 ;; So we add a similar entry, but with the temporary file name
3902 ;; as regexp.
3903 (add-to-list
3904 'result (cons (regexp-quote tmpname) (cdr elt)) 'append)))))
3905
3891(defun tramp-handle-insert-file-contents 3906(defun tramp-handle-insert-file-contents
3892 (filename &optional visit beg end replace) 3907 (filename &optional visit beg end replace)
3893 "Like `insert-file-contents' for tramp files." 3908 "Like `insert-file-contents' for tramp files."
@@ -3916,14 +3931,18 @@ This will break if COMMAND prints a newline, followed by the value of
3916 (tramp-message-for-buffer 3931 (tramp-message-for-buffer
3917 multi-method method user host 3932 multi-method method user host
3918 9 "Inserting local temp file `%s'..." local-copy) 3933 9 "Inserting local temp file `%s'..." local-copy)
3919 (setq result (insert-file-contents local-copy nil beg end replace)) 3934 ;; We must ensure that `file-coding-system-alist' matches
3920 (when visit 3935 ;; `local-copy'.
3921 (setq buffer-file-name filename) 3936 (let ((file-coding-system-alist
3922 (set-visited-file-modtime) 3937 (tramp-find-file-name-coding-system-alist filename local-copy)))
3923 (set-buffer-modified-p nil)) 3938 (setq result (insert-file-contents local-copy nil beg end replace))
3924 ;; Now `last-coding-system-used' has right value. Remember it. 3939 (when visit
3925 (when (boundp 'last-coding-system-used) 3940 (setq buffer-file-name filename)
3926 (setq coding-system-used (symbol-value 'last-coding-system-used))) 3941 (set-visited-file-modtime)
3942 (set-buffer-modified-p nil))
3943 ;; Now `last-coding-system-used' has right value. Remember it.
3944 (when (boundp 'last-coding-system-used)
3945 (setq coding-system-used (symbol-value 'last-coding-system-used))))
3927 (tramp-message-for-buffer 3946 (tramp-message-for-buffer
3928 multi-method method user host 3947 multi-method method user host
3929 9 "Inserting local temp file `%s'...done" local-copy) 3948 9 "Inserting local temp file `%s'...done" local-copy)
@@ -4072,17 +4091,20 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
4072 ;; Set current buffer. If connection wasn't open, `file-modes' has 4091 ;; Set current buffer. If connection wasn't open, `file-modes' has
4073 ;; changed it accidently. 4092 ;; changed it accidently.
4074 (set-buffer curbuf) 4093 (set-buffer curbuf)
4075 ;; We say `no-message' here because we don't want the visited file 4094 ;; We say `no-message' here because we don't want the visited
4076 ;; modtime data to be clobbered from the temp file. We call 4095 ;; file modtime data to be clobbered from the temp file. We
4077 ;; `set-visited-file-modtime' ourselves later on. 4096 ;; call `set-visited-file-modtime' ourselves later on. We must
4078 (tramp-run-real-handler 4097 ;; ensure that `file-coding-system-alist' matches `tmpfil'.
4079 'write-region 4098 (let ((file-coding-system-alist
4080 (if confirm ; don't pass this arg unless defined for backward compat. 4099 (tramp-find-file-name-coding-system-alist filename tmpfil)))
4081 (list start end tmpfil append 'no-message lockname confirm) 4100 (tramp-run-real-handler
4082 (list start end tmpfil append 'no-message lockname))) 4101 'write-region
4083 ;; Now, `last-coding-system-used' has the right value. Remember it. 4102 (if confirm ; don't pass this arg unless defined for backward compat.
4084 (when (boundp 'last-coding-system-used) 4103 (list start end tmpfil append 'no-message lockname confirm)
4085 (setq coding-system-used (symbol-value 'last-coding-system-used))) 4104 (list start end tmpfil append 'no-message lockname)))
4105 ;; Now, `last-coding-system-used' has the right value. Remember it.
4106 (when (boundp 'last-coding-system-used)
4107 (setq coding-system-used (symbol-value 'last-coding-system-used))))
4086 ;; The permissions of the temporary file should be set. If 4108 ;; The permissions of the temporary file should be set. If
4087 ;; filename does not exist (eq modes nil) it has been renamed to 4109 ;; filename does not exist (eq modes nil) it has been renamed to
4088 ;; the backup file. This case `save-buffer' handles 4110 ;; the backup file. This case `save-buffer' handles