summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorMichael Albinus <michael.albinus@gmx.de>2008-04-09 20:04:14 +0000
committerMichael Albinus <michael.albinus@gmx.de>2008-04-09 20:04:14 +0000
commiteb56296236e23bfb77acd3c8151d3fe252c4260a (patch)
tree6e731094dd2ec006fe980081085b950f5c0d3270 /lisp
parentba5ff07b2a19846cc8624bfe7f802bc9d38a4867 (diff)
downloademacs-eb56296236e23bfb77acd3c8151d3fe252c4260a.tar.gz
* net/tramp.el (tramp-find-file-name-coding-system-alist): New
defun. (tramp-handle-insert-file-contents, tramp-handle-write-region): Use it.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/ChangeLog7
-rw-r--r--lisp/net/tramp.el52
2 files changed, 47 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index ad1ce6d8bb4..d256a4043db 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,10 @@
+2008-04-09 Michael Albinus <michael.albinus@gmx.de>
+
+ * net/tramp.el (tramp-find-file-name-coding-system-alist): New
+ defun.
+ (tramp-handle-insert-file-contents, tramp-handle-write-region):
+ Use it.
+
2008-04-09 Stefan Monnier <monnier@iro.umontreal.ca>
* minibuffer.el (minibuffer): Move group from cus-edit.el.
diff --git a/lisp/net/tramp.el b/lisp/net/tramp.el
index 52060371d12..5f8f126b4be 100644
--- a/lisp/net/tramp.el
+++ b/lisp/net/tramp.el
@@ -3921,6 +3921,21 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
((eq identification 'localname) localname)
(t (tramp-make-tramp-file-name method user host "")))))))
+(defun tramp-find-file-name-coding-system-alist (filename tmpname)
+ "Like `find-operation-coding-system' for Tramp filenames.
+Tramp's `insert-file-contents' and `write-region' work over
+temporary file names. If `file-coding-system-alist' contains an
+expression, which matches more than the file name suffix, the
+coding system might not be determined. This function repairs it."
+ (let (result)
+ (dolist (elt file-coding-system-alist result)
+ (when (and (consp elt) (string-match (car elt) filename))
+ ;; We found a matching entry in `file-coding-system-alist'.
+ ;; So we add a similar entry, but with the temporary file name
+ ;; as regexp.
+ (add-to-list
+ 'result (cons (regexp-quote tmpname) (cdr elt)) 'append)))))
+
(defun tramp-handle-insert-file-contents
(filename &optional visit beg end replace)
"Like `insert-file-contents' for Tramp files."
@@ -3955,11 +3970,19 @@ Lisp error raised when PROGRAM is nil is trapped also, returning 1."
'file-local-copy)))
(file-local-copy filename))))
(tramp-message v 4 "Inserting local temp file `%s'..." local-copy)
- (setq result (insert-file-contents local-copy nil beg end replace))
- ;; Now `last-coding-system-used' has right value. Remember it.
- (when (boundp 'last-coding-system-used)
- (setq coding-system-used (symbol-value 'last-coding-system-used)))
- (tramp-message v 4 "Inserting local temp file `%s'...done" local-copy)
+ ;; We must ensure that `file-coding-system-alist' matches
+ ;; `local-copy'.
+ (let ((file-coding-system-alist
+ (tramp-find-file-name-coding-system-alist
+ filename local-copy)))
+ (setq result
+ (insert-file-contents local-copy nil beg end replace))
+ ;; Now `last-coding-system-used' has right value. Remember it.
+ (when (boundp 'last-coding-system-used)
+ (setq coding-system-used
+ (symbol-value 'last-coding-system-used))))
+ (tramp-message
+ v 4 "Inserting local temp file `%s'...done" local-copy)
(delete-file local-copy)
(when (boundp 'last-coding-system-used)
(set 'last-coding-system-used coding-system-used))))
@@ -4138,13 +4161,18 @@ Returns a file name in `tramp-auto-save-directory' for autosaving this file."
;; We say `no-message' here because we don't want the
;; visited file modtime data to be clobbered from the temp
;; file. We call `set-visited-file-modtime' ourselves later
- ;; on.
- (tramp-run-real-handler
- 'write-region
- (list start end tmpfile append 'no-message lockname confirm))
- ;; Now, `last-coding-system-used' has the right value. Remember it.
- (when (boundp 'last-coding-system-used)
- (setq coding-system-used (symbol-value 'last-coding-system-used)))
+ ;; on. We must ensure that `file-coding-system-alist'
+ ;; matches `tmpfile'.
+ (let ((file-coding-system-alist
+ (tramp-find-file-name-coding-system-alist filename tmpfile)))
+ (tramp-run-real-handler
+ 'write-region
+ (list start end tmpfile append 'no-message lockname confirm))
+ ;; Now, `last-coding-system-used' has the right value. Remember it.
+ (when (boundp 'last-coding-system-used)
+ (setq coding-system-used
+ (symbol-value 'last-coding-system-used))))
+
;; The permissions of the temporary file should be set. If
;; filename does not exist (eq modes nil) it has been
;; renamed to the backup file. This case `save-buffer'