comparison lisp/net/tramp.el @ 107820:e97568b31550

Synchronize with Tramp repository. * net/tramp.el (tramp-completion-function-alist) (tramp-file-name-regexp, tramp-chunksize) (tramp-local-coding-commands, tramp-remote-coding-commands): Fix docstring. (tramp-remote-process-environment): Use `format' instead of `concat'. (tramp-handle-directory-files-and-attributes) (tramp-get-remote-path): Use `copy-tree'. (tramp-handle-file-name-all-completions): Backward/ XEmacs compatibility: Use `completion-ignore-case' if `read-file-name-completion-ignore-case' does not exist. (tramp-do-copy-or-rename-file-directly): Do not use `tramp-handle-file-remote-p'. (tramp-do-copy-or-rename-file-out-of-band): Use `tramp-compat-delete-directory'. (tramp-do-copy-or-rename-file-out-of-band) (tramp-compute-multi-hops, tramp-maybe-open-connection): Use `format-spec-make'. (tramp-find-foreign-file-name-handler) (tramp-advice-make-auto-save-file-name) (tramp-set-auto-save-file-modes): Remove superfluous check for `stringp'. This is done inside `tramp-tramp-file-p'. (tramp-debug-outline-regexp): New defconst. (tramp-get-debug-buffer): Use it. (tramp-check-for-regexp): Use (forward-line 1). (tramp-set-auto-save-file-modes): Adapt version check. * net/tramp-compat.el (tramp-advice-file-expand-wildcards): Wrap call of `featurep' for 2nd argument. (tramp-compat-make-temp-file): Simplify fallback implementation. (tramp-compat-copy-tree): Remove function. (tramp-compat-delete-directory): Provide implementation for older Emacsen. * net/tramp-fish.el (tramp-fish-handle-directory-files-and-attributes): Do not use `tramp-fish-handle-file-attributes. * net/trampver.el: Update release number.
author Michael Albinus <albinus@detlef>
date Sat, 10 Apr 2010 14:50:31 +0200
parents 75e87467a0db
children 02b5fe4a01fe
comparison
equal deleted inserted replaced
107819:834292200403 107820:e97568b31550
34 ;; For more detailed instructions, please see the info file. 34 ;; For more detailed instructions, please see the info file.
35 ;; 35 ;;
36 ;; Notes: 36 ;; Notes:
37 ;; ----- 37 ;; -----
38 ;; 38 ;;
39 ;; This package only works for Emacs 21.1 and higher, and for XEmacs 21.4 39 ;; This package only works for Emacs 22.1 and higher, and for XEmacs 21.4
40 ;; and higher. For XEmacs 21, you need the package `fsf-compat' for 40 ;; and higher. For XEmacs 21, you need the package `fsf-compat' for
41 ;; the `with-timeout' macro. 41 ;; the `with-timeout' macro.
42 ;; 42 ;;
43 ;; Also see the todo list at the bottom of this file. 43 ;; Also see the todo list at the bottom of this file.
44 ;; 44 ;;
77 (add-hook 'tramp-unload-hook 77 (add-hook 'tramp-unload-hook
78 (lambda () 78 (lambda ()
79 (when (featurep 'tramp-compat) 79 (when (featurep 'tramp-compat)
80 (unload-feature 'tramp-compat 'force)))) 80 (unload-feature 'tramp-compat 'force))))
81 81
82 (require 'format-spec) ; from Gnus 5.8, also in tar ball 82 (require 'format-spec)
83 ;; As long as password.el is not part of (X)Emacs, it shouldn't 83 ;; As long as password.el is not part of (X)Emacs, it shouldn't
84 ;; be mandatory 84 ;; be mandatory
85 (if (featurep 'xemacs) 85 (if (featurep 'xemacs)
86 (load "password" 'noerror) 86 (load "password" 'noerror)
87 (or (require 'password-cache nil 'noerror) 87 (or (require 'password-cache nil 'noerror)
869 "HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions")) 869 "HKEY_CURRENT_USER\\Software\\SimonTatham\\PuTTY\\Sessions"))
870 "Default list of (FUNCTION REGISTRY) pairs to be examined for putty methods.") 870 "Default list of (FUNCTION REGISTRY) pairs to be examined for putty methods.")
871 871
872 (defvar tramp-completion-function-alist nil 872 (defvar tramp-completion-function-alist nil
873 "*Alist of methods for remote files. 873 "*Alist of methods for remote files.
874 This is a list of entries of the form (NAME PAIR1 PAIR2 ...). 874 This is a list of entries of the form \(NAME PAIR1 PAIR2 ...\).
875 Each NAME stands for a remote access method. Each PAIR is of the form 875 Each NAME stands for a remote access method. Each PAIR is of the form
876 \(FUNCTION FILE). FUNCTION is responsible to extract user names and host 876 \(FUNCTION FILE\). FUNCTION is responsible to extract user names and host
877 names from FILE for completion. The following predefined FUNCTIONs exists: 877 names from FILE for completion. The following predefined FUNCTIONs exists:
878 878
879 * `tramp-parse-rhosts' for \"~/.rhosts\" like files, 879 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
880 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files, 880 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
881 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files, 881 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
1023 (const :tag "Private Directories" tramp-own-remote-path) 1023 (const :tag "Private Directories" tramp-own-remote-path)
1024 (string :tag "Directory")))) 1024 (string :tag "Directory"))))
1025 1025
1026 (defcustom tramp-remote-process-environment 1026 (defcustom tramp-remote-process-environment
1027 `("HISTFILE=$HOME/.tramp_history" "HISTSIZE=1" "LC_ALL=C" 1027 `("HISTFILE=$HOME/.tramp_history" "HISTSIZE=1" "LC_ALL=C"
1028 ,(concat "TERM=" tramp-terminal-type) 1028 ,(format "TERM=%s" tramp-terminal-type)
1029 "EMACS=t" ;; Deprecated. 1029 "EMACS=t" ;; Deprecated.
1030 ,(format "INSIDE_EMACS=%s,tramp:%s" emacs-version tramp-version) 1030 ,(format "INSIDE_EMACS=%s,tramp:%s" emacs-version tramp-version)
1031 "CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH=" 1031 "CDPATH=" "HISTORY=" "MAIL=" "MAILCHECK=" "MAILPATH="
1032 "autocorrect=" "correct=") 1032 "autocorrect=" "correct=")
1033 1033
1427 ((equal tramp-syntax 'sep) tramp-file-name-regexp-separate) 1427 ((equal tramp-syntax 'sep) tramp-file-name-regexp-separate)
1428 ((equal tramp-syntax 'url) tramp-file-name-regexp-url) 1428 ((equal tramp-syntax 'url) tramp-file-name-regexp-url)
1429 (t (error "Wrong `tramp-syntax' defined"))) 1429 (t (error "Wrong `tramp-syntax' defined")))
1430 "*Regular expression matching file names handled by Tramp. 1430 "*Regular expression matching file names handled by Tramp.
1431 This regexp should match Tramp file names but no other file names. 1431 This regexp should match Tramp file names but no other file names.
1432 \(When tramp.el is loaded, this regular expression is prepended to 1432 When tramp.el is loaded, this regular expression is prepended to
1433 `file-name-handler-alist', and that is searched sequentially. Thus, 1433 `file-name-handler-alist', and that is searched sequentially. Thus,
1434 if the Tramp entry appears rather early in the `file-name-handler-alist' 1434 if the Tramp entry appears rather early in the `file-name-handler-alist'
1435 and is a bit too general, then some files might be considered Tramp 1435 and is a bit too general, then some files might be considered Tramp
1436 files which are not really Tramp files. 1436 files which are not really Tramp files.
1437 1437
1438 Please note that the entry in `file-name-handler-alist' is made when 1438 Please note that the entry in `file-name-handler-alist' is made when
1439 this file (tramp.el) is loaded. This means that this variable must be set 1439 this file \(tramp.el\) is loaded. This means that this variable must be set
1440 before loading tramp.el. Alternatively, `file-name-handler-alist' can be 1440 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
1441 updated after changing this variable. 1441 updated after changing this variable.
1442 1442
1443 Also see `tramp-file-name-structure'.") 1443 Also see `tramp-file-name-structure'.")
1444 1444
1564 (display-buffer (current-buffer)) 1564 (display-buffer (current-buffer))
1565 (sit-for 30)))) 1565 (sit-for 30))))
1566 1566
1567 In the Emacs normally running Tramp, evaluate the above code 1567 In the Emacs normally running Tramp, evaluate the above code
1568 \(replace \"xxx\" and \"yyy\" by the remote user and host name, 1568 \(replace \"xxx\" and \"yyy\" by the remote user and host name,
1569 respectively). You can do this, for example, by pasting it into 1569 respectively\). You can do this, for example, by pasting it into
1570 the `*scratch*' buffer and then hitting C-j with the cursor after the 1570 the `*scratch*' buffer and then hitting C-j with the cursor after the
1571 last closing parenthesis. Note that it works only if you have configured 1571 last closing parenthesis. Note that it works only if you have configured
1572 \"ssh\" to run without password query, see ssh-agent(1). 1572 \"ssh\" to run without password query, see ssh-agent\(1\).
1573 1573
1574 You will see the number of bytes sent successfully to the remote host. 1574 You will see the number of bytes sent successfully to the remote host.
1575 If that number exceeds 1000, you can stop the execution by hitting 1575 If that number exceeds 1000, you can stop the execution by hitting
1576 C-g, because your Emacs is likely clean. 1576 C-g, because your Emacs is likely clean.
1577 1577
1578 When it is necessary to set `tramp-chunksize', you might consider to 1578 When it is necessary to set `tramp-chunksize', you might consider to
1579 use an out-of-the-band method (like \"scp\") instead of an internal one 1579 use an out-of-the-band method \(like \"scp\"\) instead of an internal one
1580 \(like \"ssh\"), because setting `tramp-chunksize' to non-nil decreases 1580 \(like \"ssh\"\), because setting `tramp-chunksize' to non-nil decreases
1581 performance. 1581 performance.
1582 1582
1583 If your Emacs is buggy, the code stops and gives you an indication 1583 If your Emacs is buggy, the code stops and gives you an indication
1584 about the value `tramp-chunksize' should be set. Maybe you could just 1584 about the value `tramp-chunksize' should be set. Maybe you could just
1585 experiment a bit, e.g. changing the values of `init' and `step' 1585 experiment a bit, e.g. changing the values of `init' and `step'
3164 "Like `directory-files-and-attributes' for Tramp files." 3164 "Like `directory-files-and-attributes' for Tramp files."
3165 (unless id-format (setq id-format 'integer)) 3165 (unless id-format (setq id-format 'integer))
3166 (when (file-directory-p directory) 3166 (when (file-directory-p directory)
3167 (setq directory (expand-file-name directory)) 3167 (setq directory (expand-file-name directory))
3168 (let* ((temp 3168 (let* ((temp
3169 (tramp-compat-copy-tree 3169 (copy-tree
3170 (with-parsed-tramp-file-name directory nil 3170 (with-parsed-tramp-file-name directory nil
3171 (with-file-property 3171 (with-file-property
3172 v localname 3172 v localname
3173 (format "directory-files-and-attributes-%s" id-format) 3173 (format "directory-files-and-attributes-%s" id-format)
3174 (save-excursion 3174 (save-excursion
3295 "tramp_perl_file_name_all_completions") 3295 "tramp_perl_file_name_all_completions")
3296 (format "tramp_perl_file_name_all_completions %s %s %d" 3296 (format "tramp_perl_file_name_all_completions %s %s %d"
3297 (tramp-shell-quote-argument localname) 3297 (tramp-shell-quote-argument localname)
3298 (tramp-shell-quote-argument filename) 3298 (tramp-shell-quote-argument filename)
3299 (if (symbol-value 3299 (if (symbol-value
3300 'read-file-name-completion-ignore-case) 3300 ;; `read-file-name-completion-ignore-case'
3301 ;; is introduced with Emacs 22.1.
3302 (if (boundp
3303 'read-file-name-completion-ignore-case)
3304 'read-file-name-completion-ignore-case
3305 'completion-ignore-case))
3301 1 0))) 3306 1 0)))
3302 3307
3303 (format (concat 3308 (format (concat
3304 "(\\cd %s 2>&1 && (%s %s -a 2>/dev/null" 3309 "(\\cd %s 2>&1 && (%s %s -a 2>/dev/null"
3305 ;; `ls' with wildcard might fail with `Argument 3310 ;; `ls' with wildcard might fail with `Argument
3380 (tramp-set-file-property 3385 (tramp-set-file-property
3381 v (concat localname filename) 3386 v (concat localname filename)
3382 "file-name-all-completions" 3387 "file-name-all-completions"
3383 result)))))))) 3388 result))))))))
3384 3389
3385 ;; The following isn't needed for Emacs 20 but for 19.34?
3386 (defun tramp-handle-file-name-completion 3390 (defun tramp-handle-file-name-completion
3387 (filename directory &optional predicate) 3391 (filename directory &optional predicate)
3388 "Like `file-name-completion' for Tramp files." 3392 "Like `file-name-completion' for Tramp files."
3389 (unless (tramp-tramp-file-p directory) 3393 (unless (tramp-tramp-file-p directory)
3390 (error 3394 (error
3648 (t (tramp-error 3652 (t (tramp-error
3649 v 'file-error 3653 v 'file-error
3650 "Unknown operation `%s', must be `copy' or `rename'" 3654 "Unknown operation `%s', must be `copy' or `rename'"
3651 op)))) 3655 op))))
3652 (localname1 3656 (localname1
3653 (if t1 (tramp-handle-file-remote-p filename 'localname) filename)) 3657 (if t1
3658 (tramp-file-name-handler 'file-remote-p filename 'localname)
3659 filename))
3654 (localname2 3660 (localname2
3655 (if t2 (tramp-handle-file-remote-p newname 'localname) newname)) 3661 (if t2
3662 (tramp-file-name-handler 'file-remote-p newname 'localname)
3663 newname))
3656 (prefix (file-remote-p (if t1 filename newname))) 3664 (prefix (file-remote-p (if t1 filename newname)))
3657 cmd-result) 3665 cmd-result)
3658 3666
3659 (cond 3667 (cond
3660 ;; Both files are on a remote host, with same user. 3668 ;; Both files are on a remote host, with same user.
3812 (tramp-do-copy-or-rename-file-out-of-band 3820 (tramp-do-copy-or-rename-file-out-of-band
3813 'rename tmpfile newname keep-date)) 3821 'rename tmpfile newname keep-date))
3814 ;; Save exit. 3822 ;; Save exit.
3815 (condition-case nil 3823 (condition-case nil
3816 (if dir-flag 3824 (if dir-flag
3817 (delete-directory 3825 (tramp-compat-delete-directory
3818 (expand-file-name ".." tmpfile) 'recursive) 3826 (expand-file-name ".." tmpfile) 'recursive)
3819 (delete-file tmpfile)) 3827 (delete-file tmpfile))
3820 (error)))) 3828 (error))))
3821 3829
3822 ;; Expand hops. Might be necessary for gateway methods. 3830 ;; Expand hops. Might be necessary for gateway methods.
3839 (setq host (tramp-file-name-real-host v) 3847 (setq host (tramp-file-name-real-host v)
3840 port (tramp-file-name-port v) 3848 port (tramp-file-name-port v)
3841 port (or (and port (number-to-string port)) "")) 3849 port (or (and port (number-to-string port)) ""))
3842 3850
3843 ;; Compose copy command. 3851 ;; Compose copy command.
3844 (setq spec `((?h . ,host) (?u . ,user) (?p . ,port) 3852 (setq spec (format-spec-make
3845 (?t . ,(tramp-get-connection-property 3853 ?h host ?u user ?p port
3846 (tramp-get-connection-process v) "temp-file" "")) 3854 ?t (tramp-get-connection-property
3847 (?k . ,(if keep-date " " ""))) 3855 (tramp-get-connection-process v) "temp-file" "")
3856 ?k (if keep-date " " ""))
3848 copy-program (tramp-get-method-parameter 3857 copy-program (tramp-get-method-parameter
3849 method 'tramp-copy-program) 3858 method 'tramp-copy-program)
3850 copy-keep-date (tramp-get-method-parameter 3859 copy-keep-date (tramp-get-method-parameter
3851 method 'tramp-copy-keep-date) 3860 method 'tramp-copy-keep-date)
3852 copy-args 3861 copy-args
3932 3941
3933 ;; If the operation was `rename', delete the original file. 3942 ;; If the operation was `rename', delete the original file.
3934 (unless (eq op 'copy) 3943 (unless (eq op 'copy)
3935 (if (file-regular-p filename) 3944 (if (file-regular-p filename)
3936 (delete-file filename) 3945 (delete-file filename)
3937 (delete-directory filename 'recursive)))))) 3946 (tramp-compat-delete-directory filename 'recursive))))))
3938 3947
3939 (defun tramp-handle-make-directory (dir &optional parents) 3948 (defun tramp-handle-make-directory (dir &optional parents)
3940 "Like `make-directory' for Tramp files." 3949 "Like `make-directory' for Tramp files."
3941 (setq dir (expand-file-name dir)) 3950 (setq dir (expand-file-name dir))
3942 (with-parsed-tramp-file-name dir nil 3951 (with-parsed-tramp-file-name dir nil
4861 4870
4862 (defun tramp-handle-find-backup-file-name (filename) 4871 (defun tramp-handle-find-backup-file-name (filename)
4863 "Like `find-backup-file-name' for Tramp files." 4872 "Like `find-backup-file-name' for Tramp files."
4864 (with-parsed-tramp-file-name filename nil 4873 (with-parsed-tramp-file-name filename nil
4865 ;; We set both variables. It doesn't matter whether it is 4874 ;; We set both variables. It doesn't matter whether it is
4866 ;; Emacs or XEmacs 4875 ;; Emacs or XEmacs.
4867 (let ((backup-directory-alist 4876 (let ((backup-directory-alist
4868 ;; Emacs case 4877 ;; Emacs case.
4869 (when (boundp 'backup-directory-alist) 4878 (when (boundp 'backup-directory-alist)
4870 (if (symbol-value 'tramp-backup-directory-alist) 4879 (if (symbol-value 'tramp-backup-directory-alist)
4871 (mapcar 4880 (mapcar
4872 (lambda (x) 4881 (lambda (x)
4873 (cons 4882 (cons
4879 (cdr x)))) 4888 (cdr x))))
4880 (symbol-value 'tramp-backup-directory-alist)) 4889 (symbol-value 'tramp-backup-directory-alist))
4881 (symbol-value 'backup-directory-alist)))) 4890 (symbol-value 'backup-directory-alist))))
4882 4891
4883 (bkup-backup-directory-info 4892 (bkup-backup-directory-info
4884 ;; XEmacs case 4893 ;; XEmacs case.
4885 (when (boundp 'bkup-backup-directory-info) 4894 (when (boundp 'bkup-backup-directory-info)
4886 (if (symbol-value 'tramp-bkup-backup-directory-info) 4895 (if (symbol-value 'tramp-bkup-backup-directory-info)
4887 (mapcar 4896 (mapcar
4888 (lambda (x) 4897 (lambda (x)
4889 (nconc 4898 (nconc
5293 ;; function as well but regexp only. 5302 ;; function as well but regexp only.
5294 (defun tramp-file-name-for-operation (operation &rest args) 5303 (defun tramp-file-name-for-operation (operation &rest args)
5295 "Return file name related to OPERATION file primitive. 5304 "Return file name related to OPERATION file primitive.
5296 ARGS are the arguments OPERATION has been called with." 5305 ARGS are the arguments OPERATION has been called with."
5297 (cond 5306 (cond
5298 ; FILE resp DIRECTORY 5307 ;; FILE resp DIRECTORY.
5299 ((member operation 5308 ((member operation
5300 (list 'access-file 'byte-compiler-base-file-name 'delete-directory 5309 (list 'access-file 'byte-compiler-base-file-name 'delete-directory
5301 'delete-file 'diff-latest-backup-file 'directory-file-name 5310 'delete-file 'diff-latest-backup-file 'directory-file-name
5302 'directory-files 'directory-files-and-attributes 5311 'directory-files 'directory-files-and-attributes
5303 'dired-compress-file 'dired-uncache 5312 'dired-compress-file 'dired-uncache
5311 'file-writable-p 'find-backup-file-name 'find-file-noselect 5320 'file-writable-p 'find-backup-file-name 'find-file-noselect
5312 'get-file-buffer 'insert-directory 'insert-file-contents 5321 'get-file-buffer 'insert-directory 'insert-file-contents
5313 'load 'make-directory 'make-directory-internal 5322 'load 'make-directory 'make-directory-internal
5314 'set-file-modes 'substitute-in-file-name 5323 'set-file-modes 'substitute-in-file-name
5315 'unhandled-file-name-directory 'vc-registered 5324 'unhandled-file-name-directory 'vc-registered
5316 ; Emacs 22 only 5325 ;; Emacs 22+ only.
5317 'set-file-times 5326 'set-file-times
5318 ; XEmacs only 5327 ;; XEmacs only.
5319 'abbreviate-file-name 'create-file-buffer 5328 'abbreviate-file-name 'create-file-buffer
5320 'dired-file-modtime 'dired-make-compressed-filename 5329 'dired-file-modtime 'dired-make-compressed-filename
5321 'dired-recursive-delete-directory 'dired-set-file-modtime 5330 'dired-recursive-delete-directory 'dired-set-file-modtime
5322 'dired-shell-unhandle-file-name 'dired-uucode-file 5331 'dired-shell-unhandle-file-name 'dired-uucode-file
5323 'insert-file-contents-literally 'make-temp-name 'recover-file 5332 'insert-file-contents-literally 'make-temp-name 'recover-file
5324 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail)) 5333 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail))
5325 (if (file-name-absolute-p (nth 0 args)) 5334 (if (file-name-absolute-p (nth 0 args))
5326 (nth 0 args) 5335 (nth 0 args)
5327 (expand-file-name (nth 0 args)))) 5336 (expand-file-name (nth 0 args))))
5328 ; FILE DIRECTORY resp FILE1 FILE2 5337 ;; FILE DIRECTORY resp FILE1 FILE2.
5329 ((member operation 5338 ((member operation
5330 (list 'add-name-to-file 'copy-file 'expand-file-name 5339 (list 'add-name-to-file 'copy-file 'expand-file-name
5331 'file-name-all-completions 'file-name-completion 5340 'file-name-all-completions 'file-name-completion
5332 'file-newer-than-file-p 'make-symbolic-link 'rename-file 5341 'file-newer-than-file-p 'make-symbolic-link 'rename-file
5333 ; Emacs 23 only 5342 ;; Emacs 23+ only.
5334 'copy-directory 5343 'copy-directory
5335 ; XEmacs only 5344 ;; XEmacs only.
5336 'dired-make-relative-symlink 5345 'dired-make-relative-symlink
5337 'vm-imap-move-mail 'vm-pop-move-mail 'vm-spool-move-mail)) 5346 'vm-imap-move-mail 'vm-pop-move-mail 'vm-spool-move-mail))
5338 (save-match-data 5347 (save-match-data
5339 (cond 5348 (cond
5340 ((string-match tramp-file-name-regexp (nth 0 args)) (nth 0 args)) 5349 ((string-match tramp-file-name-regexp (nth 0 args)) (nth 0 args))
5341 ((string-match tramp-file-name-regexp (nth 1 args)) (nth 1 args)) 5350 ((string-match tramp-file-name-regexp (nth 1 args)) (nth 1 args))
5342 (t (buffer-file-name (current-buffer)))))) 5351 (t (buffer-file-name (current-buffer))))))
5343 ; START END FILE 5352 ;; START END FILE.
5344 ((eq operation 'write-region) 5353 ((eq operation 'write-region)
5345 (nth 2 args)) 5354 (nth 2 args))
5346 ; BUF 5355 ;; BUFFER.
5347 ((member operation 5356 ((member operation
5348 (list 'set-visited-file-modtime 'verify-visited-file-modtime 5357 (list 'set-visited-file-modtime 'verify-visited-file-modtime
5349 ; since Emacs 22 only 5358 ;; Emacs 22+ only.
5350 'make-auto-save-file-name 5359 'make-auto-save-file-name
5351 ; XEmacs only 5360 ;; XEmacs only.
5352 'backup-buffer)) 5361 'backup-buffer))
5353 (buffer-file-name 5362 (buffer-file-name
5354 (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer)))) 5363 (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer))))
5355 ; COMMAND 5364 ;; COMMAND.
5356 ((member operation 5365 ((member operation
5357 (list ; not in Emacs 23 5366 (list ;; not in Emacs 23+.
5358 'dired-call-process 5367 'dired-call-process
5359 ; Emacs only 5368 ;; Emacs only.
5360 'shell-command 5369 'shell-command
5361 ; since Emacs 22 only 5370 ;; Emacs 22+ only.
5362 'process-file 5371 'process-file
5363 ; since Emacs 23 only 5372 ;; Emacs 23+ only.
5364 'start-file-process 5373 'start-file-process
5365 ; XEmacs only 5374 ;; XEmacs only.
5366 'dired-print-file 'dired-shell-call-process 5375 'dired-print-file 'dired-shell-call-process
5367 ; nowhere yet 5376 ;; nowhere yet.
5368 'executable-find 'start-process 'call-process)) 5377 'executable-find 'start-process 'call-process))
5369 default-directory) 5378 default-directory)
5370 ; unknown file primitive 5379 ;; Unknown file primitive.
5371 (t (error "unknown file I/O primitive: %s" operation)))) 5380 (t (error "unknown file I/O primitive: %s" operation))))
5372 5381
5373 (defun tramp-find-foreign-file-name-handler (filename) 5382 (defun tramp-find-foreign-file-name-handler (filename)
5374 "Return foreign file name handler if exists." 5383 "Return foreign file name handler if exists."
5375 (when (and (stringp filename) (tramp-tramp-file-p filename)) 5384 (when (tramp-tramp-file-p filename)
5376 (let ((v (tramp-dissect-file-name filename t)) 5385 (let ((v (tramp-dissect-file-name filename t))
5377 (handler tramp-foreign-file-name-handler-alist) 5386 (handler tramp-foreign-file-name-handler-alist)
5378 elt res) 5387 elt res)
5379 ;; When we are not fully sure that filename completion is safe, 5388 ;; When we are not fully sure that filename completion is safe,
5380 ;; we should not return a handler. 5389 ;; we should not return a handler.
6255 (host (tramp-file-name-real-host vec))) 6264 (host (tramp-file-name-real-host vec)))
6256 (if (not (zerop (length user))) 6265 (if (not (zerop (length user)))
6257 (format "*debug tramp/%s %s@%s*" method user host) 6266 (format "*debug tramp/%s %s@%s*" method user host)
6258 (format "*debug tramp/%s %s*" method host)))) 6267 (format "*debug tramp/%s %s*" method host))))
6259 6268
6269 (defconst tramp-debug-outline-regexp
6270 "[0-9]+:[0-9]+:[0-9]+\\.[0-9]+ [a-z0-9-]+ (\\([0-9]+\\)) #")
6271
6260 (defun tramp-get-debug-buffer (vec) 6272 (defun tramp-get-debug-buffer (vec)
6261 "Get the debug buffer for VEC." 6273 "Get the debug buffer for VEC."
6262 (with-current-buffer 6274 (with-current-buffer
6263 (get-buffer-create (tramp-debug-buffer-name vec)) 6275 (get-buffer-create (tramp-debug-buffer-name vec))
6264 (when (bobp) 6276 (when (bobp)
6265 (setq buffer-undo-list t) 6277 (setq buffer-undo-list t)
6266 ;; Activate outline-mode. This runs `text-mode-hook' and 6278 ;; Activate `outline-mode'. This runs `text-mode-hook' and
6267 ;; `outline-mode-hook'. We must prevent that local processes 6279 ;; `outline-mode-hook'. We must prevent that local processes
6268 ;; die. Yes: I've seen `flyspell-mode', which starts "ispell" 6280 ;; die. Yes: I've seen `flyspell-mode', which starts "ispell".
6269 ;; ... 6281 ;; Furthermore, `outline-regexp' must have the correct value
6270 (let ((default-directory (tramp-compat-temporary-file-directory))) 6282 ;; already, because it is used by `font-lock-compile-keywords'.
6283 (let ((default-directory (tramp-compat-temporary-file-directory))
6284 (outline-regexp tramp-debug-outline-regexp))
6271 (outline-mode)) 6285 (outline-mode))
6272 (set (make-local-variable 'outline-regexp) 6286 (set (make-local-variable 'outline-regexp) tramp-debug-outline-regexp)
6273 "[0-9]+:[0-9]+:[0-9]+\\.[0-9]+ [a-z0-9-]+ (\\([0-9]+\\)) #")
6274 ; (set (make-local-variable 'outline-regexp)
6275 ; "[a-z.-]+:[0-9]+: [a-z0-9-]+ (\\([0-9]+\\)) #")
6276 (set (make-local-variable 'outline-level) 'tramp-outline-level)) 6287 (set (make-local-variable 'outline-level) 'tramp-outline-level))
6277 (current-buffer))) 6288 (current-buffer)))
6278 6289
6279 (defun tramp-outline-level () 6290 (defun tramp-outline-level ()
6280 "Return the depth to which a statement is nested in the outline. 6291 "Return the depth to which a statement is nested in the outline.
6305 (goto-char (point-min)) 6316 (goto-char (point-min))
6306 (if (looking-at "^\\s-*1$") 6317 (if (looking-at "^\\s-*1$")
6307 (setq result (concat "\\" progname)))) 6318 (setq result (concat "\\" progname))))
6308 (unless result 6319 (unless result
6309 (when ignore-tilde 6320 (when ignore-tilde
6310 ;; Remove all ~/foo directories from dirlist. In Emacs 20, 6321 ;; Remove all ~/foo directories from dirlist. In XEmacs,
6311 ;; `remove' is in CL, and we want to avoid CL dependencies. 6322 ;; `remove' is in CL, and we want to avoid CL dependencies.
6312 (let (newdl d) 6323 (let (newdl d)
6313 (while dirlist 6324 (while dirlist
6314 (setq d (car dirlist)) 6325 (setq d (car dirlist))
6315 (setq dirlist (cdr dirlist)) 6326 (setq dirlist (cdr dirlist))
6622 (let ((begin (match-beginning 0))) 6633 (let ((begin (match-beginning 0)))
6623 (when (re-search-forward tramp-echoed-echo-mark-regexp nil t) 6634 (when (re-search-forward tramp-echoed-echo-mark-regexp nil t)
6624 ;; Discard echo from remote output. 6635 ;; Discard echo from remote output.
6625 (tramp-set-connection-property proc "check-remote-echo" nil) 6636 (tramp-set-connection-property proc "check-remote-echo" nil)
6626 (tramp-message proc 5 "echo-mark found") 6637 (tramp-message proc 5 "echo-mark found")
6627 (forward-line) 6638 (forward-line 1)
6628 (delete-region begin (point)) 6639 (delete-region begin (point))
6629 (goto-char (point-min))))) 6640 (goto-char (point-min)))))
6630 6641
6631 (when (or (not (tramp-get-connection-property proc "check-remote-echo" nil)) 6642 (when (or (not (tramp-get-connection-property proc "check-remote-echo" nil))
6632 ;; Sometimes, the echo string is suppressed on the remote side. 6643 ;; Sometimes, the echo string is suppressed on the remote side.
6893 "perl -e 'binmode STDIN; binmode STDOUT; print pack(q{u*}, join q{}, <>)'" 6904 "perl -e 'binmode STDIN; binmode STDOUT; print pack(q{u*}, join q{}, <>)'"
6894 "perl -e 'binmode STDIN; binmode STDOUT; print unpack(q{u*}, join q{}, <>)'")) 6905 "perl -e 'binmode STDIN; binmode STDOUT; print unpack(q{u*}, join q{}, <>)'"))
6895 "List of local coding commands for inline transfer. 6906 "List of local coding commands for inline transfer.
6896 Each item is a list that looks like this: 6907 Each item is a list that looks like this:
6897 6908
6898 \(FORMAT ENCODING DECODING) 6909 \(FORMAT ENCODING DECODING\)
6899 6910
6900 FORMAT is symbol describing the encoding/decoding format. It can be 6911 FORMAT is symbol describing the encoding/decoding format. It can be
6901 `b64' for base64 encoding, `uu' for uu encoding, or `pack' for simple packing. 6912 `b64' for base64 encoding, `uu' for uu encoding, or `pack' for simple packing.
6902 6913
6903 ENCODING and DECODING can be strings, giving commands, or symbols, 6914 ENCODING and DECODING can be strings, giving commands, or symbols,
6926 "perl -e 'binmode STDIN; binmode STDOUT; print pack(q{u*}, join q{}, <>)'" 6937 "perl -e 'binmode STDIN; binmode STDOUT; print pack(q{u*}, join q{}, <>)'"
6927 "perl -e 'binmode STDIN; binmode STDOUT; print unpack(q{u*}, join q{}, <>)'")) 6938 "perl -e 'binmode STDIN; binmode STDOUT; print unpack(q{u*}, join q{}, <>)'"))
6928 "List of remote coding commands for inline transfer. 6939 "List of remote coding commands for inline transfer.
6929 Each item is a list that looks like this: 6940 Each item is a list that looks like this:
6930 6941
6931 \(FORMAT ENCODING DECODING) 6942 \(FORMAT ENCODING DECODING\)
6932 6943
6933 FORMAT is symbol describing the encoding/decoding format. It can be 6944 FORMAT is symbol describing the encoding/decoding format. It can be
6934 `b64' for base64 encoding, `uu' for uu encoding, or `pack' for simple packing. 6945 `b64' for base64 encoding, `uu' for uu encoding, or `pack' for simple packing.
6935 6946
6936 ENCODING and DECODING can be strings, giving commands, or symbols, 6947 ENCODING and DECODING can be strings, giving commands, or symbols,
7087 (setq choices nil) 7098 (setq choices nil)
7088 ;; Replace placeholders. 7099 ;; Replace placeholders.
7089 (setq proxy 7100 (setq proxy
7090 (format-spec 7101 (format-spec
7091 proxy 7102 proxy
7092 `((?u . ,(or (tramp-file-name-user (car target-alist)) "")) 7103 (format-spec-make
7093 (?h . ,(or (tramp-file-name-host (car target-alist)) ""))))) 7104 ?u (or (tramp-file-name-user (car target-alist)) "")
7105 ?h (or (tramp-file-name-host (car target-alist)) ""))))
7094 (with-parsed-tramp-file-name proxy l 7106 (with-parsed-tramp-file-name proxy l
7095 ;; Add the hop. 7107 ;; Add the hop.
7096 (add-to-list 'target-alist l) 7108 (add-to-list 'target-alist l)
7097 ;; Start next search. 7109 ;; Start next search.
7098 (setq choices tramp-default-proxies-alist))))) 7110 (setq choices tramp-default-proxies-alist)))))
7306 ;; Replace login-args place holders. 7318 ;; Replace login-args place holders.
7307 (setq 7319 (setq
7308 l-host (or l-host "") 7320 l-host (or l-host "")
7309 l-user (or l-user "") 7321 l-user (or l-user "")
7310 l-port (or l-port "") 7322 l-port (or l-port "")
7311 spec `((?h . ,l-host) (?u . ,l-user) (?p . ,l-port) 7323 spec (format-spec-make ?h l-host ?u l-user ?p l-port ?t tmpfile)
7312 (?t . ,tmpfile))
7313 command 7324 command
7314 (concat 7325 (concat
7315 ;; We do not want to see the trailing local prompt in 7326 ;; We do not want to see the trailing local prompt in
7316 ;; `start-file-process'. 7327 ;; `start-file-process'.
7317 (unless (memq system-type '(windows-nt)) "exec ") 7328 (unless (memq system-type '(windows-nt)) "exec ")
7979 ;; is cached persistently. 7990 ;; is cached persistently.
7980 (if (memq 'tramp-own-remote-path tramp-remote-path) 7991 (if (memq 'tramp-own-remote-path tramp-remote-path)
7981 (tramp-get-connection-process vec) 7992 (tramp-get-connection-process vec)
7982 vec) 7993 vec)
7983 "remote-path" 7994 "remote-path"
7984 (let* ((remote-path (tramp-compat-copy-tree tramp-remote-path)) 7995 (let* ((remote-path (copy-tree tramp-remote-path))
7985 (elt1 (memq 'tramp-default-remote-path remote-path)) 7996 (elt1 (memq 'tramp-default-remote-path remote-path))
7986 (elt2 (memq 'tramp-own-remote-path remote-path)) 7997 (elt2 (memq 'tramp-own-remote-path remote-path))
7987 (default-remote-path 7998 (default-remote-path
7988 (when elt1 7999 (when elt1
7989 (condition-case nil 8000 (condition-case nil
8278 8289
8279 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name) 8290 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name)
8280 (defadvice make-auto-save-file-name 8291 (defadvice make-auto-save-file-name
8281 (around tramp-advice-make-auto-save-file-name () activate) 8292 (around tramp-advice-make-auto-save-file-name () activate)
8282 "Invoke `tramp-handle-make-auto-save-file-name' for Tramp files." 8293 "Invoke `tramp-handle-make-auto-save-file-name' for Tramp files."
8283 (if (and (buffer-file-name) (tramp-tramp-file-p (buffer-file-name))) 8294 (if (tramp-tramp-file-p (buffer-file-name))
8284 ;; We cannot call `tramp-handle-make-auto-save-file-name' 8295 ;; We cannot call `tramp-handle-make-auto-save-file-name'
8285 ;; directly, because this would bypass the locking mechanism. 8296 ;; directly, because this would bypass the locking mechanism.
8286 (setq ad-return-value 8297 (setq ad-return-value
8287 (tramp-file-name-handler 'make-auto-save-file-name)) 8298 (tramp-file-name-handler 'make-auto-save-file-name))
8288 ad-do-it)) 8299 ad-do-it))
8292 (ad-remove-advice 8303 (ad-remove-advice
8293 'make-auto-save-file-name 8304 'make-auto-save-file-name
8294 'around 'tramp-advice-make-auto-save-file-name) 8305 'around 'tramp-advice-make-auto-save-file-name)
8295 (ad-activate 'make-auto-save-file-name)))) 8306 (ad-activate 'make-auto-save-file-name))))
8296 8307
8297 ;; In Emacs < 22 and XEmacs < 21.5 autosaved remote files have 8308 ;; In XEmacs < 21.5, autosaved remote files have permission 0666 minus
8298 ;; permission 0666 minus umask. This is a security threat. 8309 ;; umask. This is a security threat.
8299 8310
8300 (defun tramp-set-auto-save-file-modes () 8311 (defun tramp-set-auto-save-file-modes ()
8301 "Set permissions of autosaved remote files to the original permissions." 8312 "Set permissions of autosaved remote files to the original permissions."
8302 (let ((bfn (buffer-file-name))) 8313 (let ((bfn (buffer-file-name)))
8303 (when (and (stringp bfn) 8314 (when (and (tramp-tramp-file-p bfn)
8304 (tramp-tramp-file-p bfn)
8305 (buffer-modified-p) 8315 (buffer-modified-p)
8306 (stringp buffer-auto-save-file-name) 8316 (stringp buffer-auto-save-file-name)
8307 (not (equal bfn buffer-auto-save-file-name))) 8317 (not (equal bfn buffer-auto-save-file-name)))
8308 (unless (file-exists-p buffer-auto-save-file-name) 8318 (unless (file-exists-p buffer-auto-save-file-name)
8309 (write-region "" nil buffer-auto-save-file-name)) 8319 (write-region "" nil buffer-auto-save-file-name))
8311 ;; auto-saved file belonging to another original file. This could 8321 ;; auto-saved file belonging to another original file. This could
8312 ;; be a security threat. 8322 ;; be a security threat.
8313 (set-file-modes buffer-auto-save-file-name 8323 (set-file-modes buffer-auto-save-file-name
8314 (or (file-modes bfn) (tramp-octal-to-decimal "0600")))))) 8324 (or (file-modes bfn) (tramp-octal-to-decimal "0600"))))))
8315 8325
8316 (unless (or (> emacs-major-version 21) 8326 (unless (and (featurep 'xemacs)
8317 (and (featurep 'xemacs) 8327 (= emacs-major-version 21)
8318 (= emacs-major-version 21) 8328 (> emacs-minor-version 4))
8319 (> emacs-minor-version 4)))
8320 (add-hook 'auto-save-hook 'tramp-set-auto-save-file-modes) 8329 (add-hook 'auto-save-hook 'tramp-set-auto-save-file-modes)
8321 (add-hook 'tramp-unload-hook 8330 (add-hook 'tramp-unload-hook
8322 (lambda () 8331 (lambda ()
8323 (remove-hook 'auto-save-hook 'tramp-set-auto-save-file-modes)))) 8332 (remove-hook 'auto-save-hook 'tramp-set-auto-save-file-modes))))
8324 8333
8623 ;; improve Tramp to set LC_ALL to "C" only for commands where Tramp 8632 ;; improve Tramp to set LC_ALL to "C" only for commands where Tramp
8624 ;; expects English? Or just to set LC_MESSAGES to "C" if Tramp 8633 ;; expects English? Or just to set LC_MESSAGES to "C" if Tramp
8625 ;; expects only English messages? (Juri Linkov) 8634 ;; expects only English messages? (Juri Linkov)
8626 ;; * Make shadowfile.el grok Tramp filenames. (Bug#4526, Bug#4846) 8635 ;; * Make shadowfile.el grok Tramp filenames. (Bug#4526, Bug#4846)
8627 ;; * Do not handle files with drive letter as remote. (Bug#5447) 8636 ;; * Do not handle files with drive letter as remote. (Bug#5447)
8628 ;; * Load Tramp subpackages only when needed. (Bug#1529, Bug#5448) 8637 ;; * Load Tramp subpackages only when needed. (Bug#1529, Bug#5448, Bug#5705)
8629 ;; * Try telnet+curl as new method. It might be useful for busybox, 8638 ;; * Try telnet+curl as new method. It might be useful for busybox,
8630 ;; without built-in uuencode/uudecode. 8639 ;; without built-in uuencode/uudecode.
8631 ;; * Let `shell-dynamic-complete-*' and `comint-dynamic-complete' work 8640 ;; * Let `shell-dynamic-complete-*' and `comint-dynamic-complete' work
8632 ;; on remote hosts. 8641 ;; on remote hosts.
8633 ;; * Use secrets.el for password handling. 8642 ;; * Use secrets.el for password handling.