From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.devel Subject: Re: tramp (2.0.57); file-coding-system-alist not respected Date: Tue, 08 Apr 2008 22:37:17 +0200 Message-ID: <871w5gulqa.fsf@gmx.de> References: <87zls5v7lb.fsf@gmx.de> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1207690508 26775 80.91.229.12 (8 Apr 2008 21:35:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 8 Apr 2008 21:35:08 +0000 (UTC) Cc: William Xu , tramp-devel@gnu.org, emacs-devel@gnu.org To: Andreas Schwab Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Apr 08 23:35:40 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JjLTd-0000RI-As for ged-emacs-devel@m.gmane.org; Tue, 08 Apr 2008 23:35:37 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JjLSz-00053W-V5 for ged-emacs-devel@m.gmane.org; Tue, 08 Apr 2008 17:34:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JjKXK-0005QB-E7 for emacs-devel@gnu.org; Tue, 08 Apr 2008 16:35:22 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JjKXJ-0005PQ-95 for emacs-devel@gnu.org; Tue, 08 Apr 2008 16:35:21 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JjKXJ-0005PL-3G for emacs-devel@gnu.org; Tue, 08 Apr 2008 16:35:21 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JjKXI-0006wG-Hi for emacs-devel@gnu.org; Tue, 08 Apr 2008 16:35:20 -0400 Original-Received: (qmail invoked by alias); 08 Apr 2008 20:35:18 -0000 Original-Received: from p57A22A37.dip0.t-ipconnect.de (EHLO arthur.local) [87.162.42.55] by mail.gmx.net (mp003) with SMTP; 08 Apr 2008 22:35:18 +0200 X-Authenticated: #3708877 X-Provags-ID: V01U2FsdGVkX1/pMy1mHZfpex5xcGDaON1jYi+bcIAigYPKfYIB53 c843XGB4Hiji2r In-Reply-To: (Andreas Schwab's message of "Tue, 08 Apr 2008 10:14:51 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:94736 Archived-At: --=-=-= Andreas Schwab writes: > Probably a better way to solve that is to create a way to tell > insert-file-contents the original file name to be used for deciding the > coding system. I've compiled a patch, which checks during insert-file-contents and write-region, whether a remote file name matches an expression in file-name-coding-system-alist. If yes, a new entry is prepended for the same coding system, but matching the temporary file name. William, could you, please, test whether it works for you? > Andreas. Best regards, Michael. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment *** tramp.el.~2.359.2.117.~ 2008-03-26 20:50:18.000000000 +0100 --- tramp.el 2008-04-08 22:28:26.000000000 +0200 *************** *** 3888,3893 **** --- 3888,3908 ---- (t (tramp-make-tramp-file-name multi-method 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." *************** *** 3916,3929 **** (tramp-message-for-buffer multi-method method user host 9 "Inserting local temp file `%s'..." local-copy) ! (setq result (insert-file-contents local-copy nil beg end replace)) ! (when visit ! (setq buffer-file-name filename) ! (set-visited-file-modtime) ! (set-buffer-modified-p nil)) ! ;; 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-for-buffer multi-method method user host 9 "Inserting local temp file `%s'...done" local-copy) --- 3931,3948 ---- (tramp-message-for-buffer multi-method method user host 9 "Inserting local temp file `%s'..." 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)) ! (when visit ! (setq buffer-file-name filename) ! (set-visited-file-modtime) ! (set-buffer-modified-p nil)) ! ;; 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-for-buffer multi-method method user host 9 "Inserting local temp file `%s'...done" local-copy) *************** *** 4072,4088 **** ;; Set current buffer. If connection wasn't open, `file-modes' has ;; changed it accidently. (set-buffer curbuf) ! ;; 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 ! (if confirm ; don't pass this arg unless defined for backward compat. ! (list start end tmpfil append 'no-message lockname confirm) ! (list start end tmpfil append 'no-message lockname))) ! ;; 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' handles --- 4091,4110 ---- ;; Set current buffer. If connection wasn't open, `file-modes' has ;; changed it accidently. (set-buffer curbuf) ! ;; 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. 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 ! (if confirm ; don't pass this arg unless defined for backward compat. ! (list start end tmpfil append 'no-message lockname confirm) ! (list start end tmpfil append 'no-message lockname))) ! ;; 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' handles --=-=-=--