all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Re: tramp (2.0.57); file-coding-system-alist not respected
       [not found] <m2wsnaqboo.fsf@gmail.com>
@ 2008-04-07 18:32 ` Michael Albinus
  2008-04-08  3:15   ` William Xu
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Albinus @ 2008-04-07 18:32 UTC (permalink / raw)
  To: William Xu; +Cc: tramp-devel, emacs-devel

William Xu <william.xwl@gmail.com> writes:

> I try to set file encodings matching against filenames like: 
>
> ,----
> | (setq file-coding-system-alist
> |       (".*source.*" shift_jis . shift_jis)
> | 	("" utf-8 . utf-8))
> `----
>
> Visiting files like `/source/foo' locally works fine, but not in
> tramp. 

I fear this cannot work in Tramp. Tramp uses temporary files on the
local host. They are not located at ".*source.*", rather they are
somewhere at "/tmp/*". So I have no clue how to support your settings.

Sorry, and best regards, Michael.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tramp (2.0.57); file-coding-system-alist not respected
  2008-04-07 18:32 ` tramp (2.0.57); file-coding-system-alist not respected Michael Albinus
@ 2008-04-08  3:15   ` William Xu
  2008-04-08  8:14     ` Andreas Schwab
  0 siblings, 1 reply; 4+ messages in thread
From: William Xu @ 2008-04-08  3:15 UTC (permalink / raw)
  To: emacs-devel; +Cc: tramp-devel

Michael Albinus <michael.albinus@gmx.de> writes:

> I fear this cannot work in Tramp. Tramp uses temporary files on the
> local host. They are not located at ".*source.*", rather they are
> somewhere at "/tmp/*". So I have no clue how to support your settings.

How about adding file path as part(prefix, suffix, or something like
that) of the filename under /tmp/* ? For example,
"/tmp/path_to_source_foo.cpp", replacing `/' with `_'.

-- 
William

http://williamxu.net9.org





^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tramp (2.0.57); file-coding-system-alist not respected
  2008-04-08  3:15   ` William Xu
@ 2008-04-08  8:14     ` Andreas Schwab
  2008-04-08 20:37       ` Michael Albinus
  0 siblings, 1 reply; 4+ messages in thread
From: Andreas Schwab @ 2008-04-08  8:14 UTC (permalink / raw)
  To: William Xu; +Cc: tramp-devel, emacs-devel

William Xu <william.xwl@gmail.com> writes:

> Michael Albinus <michael.albinus@gmx.de> writes:
>
>> I fear this cannot work in Tramp. Tramp uses temporary files on the
>> local host. They are not located at ".*source.*", rather they are
>> somewhere at "/tmp/*". So I have no clue how to support your settings.
>
> How about adding file path as part(prefix, suffix, or something like
> that) of the filename under /tmp/* ? For example,
> "/tmp/path_to_source_foo.cpp", replacing `/' with `_'.

One problem with this is that it gives predictable file names, a bad
thing to have in a world writable directory.

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.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
PGP key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: tramp (2.0.57); file-coding-system-alist not respected
  2008-04-08  8:14     ` Andreas Schwab
@ 2008-04-08 20:37       ` Michael Albinus
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Albinus @ 2008-04-08 20:37 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: William Xu, tramp-devel, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 559 bytes --]

Andreas Schwab <schwab@suse.de> 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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 4848 bytes --]

*** 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-08 20:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <m2wsnaqboo.fsf@gmail.com>
2008-04-07 18:32 ` tramp (2.0.57); file-coding-system-alist not respected Michael Albinus
2008-04-08  3:15   ` William Xu
2008-04-08  8:14     ` Andreas Schwab
2008-04-08 20:37       ` Michael Albinus

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.