1 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol
3 ;; Copyright (C) 1998-2011 Free Software Foundation, Inc.
5 ;; Author: Kai Großjohann <kai.grossjohann@gmx.net>
6 ;; Michael Albinus <michael.albinus@gmx.de>
7 ;; Keywords: comm, processes
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
27 ;; This package provides remote file editing, similar to ange-ftp.
28 ;; The difference is that ange-ftp uses FTP to transfer files between
29 ;; the local and the remote host, whereas tramp.el uses a combination
30 ;; of rsh and rcp or other work-alike programs, such as ssh/scp.
32 ;; For more detailed instructions, please see the info file.
37 ;; This package only works for Emacs 22.1 and higher, and for XEmacs 21.4
38 ;; and higher. For XEmacs 21, you need the package `fsf-compat' for
39 ;; the `with-timeout' macro.
41 ;; Also see the todo list at the bottom of this file.
43 ;; The current version of Tramp can be retrieved from the following URL:
44 ;; http://ftp.gnu.org/gnu/tramp/
46 ;; There's a mailing list for this, as well. Its name is:
47 ;; tramp-devel@gnu.org
48 ;; You can use the Web to subscribe, under the following URL:
49 ;; http://lists.gnu.org/mailman/listinfo/tramp-devel
51 ;; For the adventurous, the current development sources are available
52 ;; via CVS. You can find instructions about this at the following URL:
53 ;; http://savannah.gnu.org/projects/tramp/
54 ;; Click on "CVS" in the navigation bar near the top.
56 ;; Don't forget to put on your asbestos longjohns, first!
60 (require 'tramp-compat
)
62 ;;; User Customizable Internal Variables:
65 "Edit remote files with a combination of rsh and rcp or similar programs."
70 ;; Maybe we need once a real Tramp mode, with key bindings etc.
72 (defcustom tramp-mode t
73 "*Whether Tramp is enabled.
74 If it is set to nil, all remote file names are used literally."
78 (defcustom tramp-verbose
3
79 "*Verbosity level for Tramp messages.
80 Any level x includes messages for all levels 1 .. x-1. The levels are
82 0 silent (no tramp messages at all)
85 3 connection to remote hosts (default level)
88 6 sent and received strings
90 8 connection properties
98 (when (boundp 'backup-directory-alist
)
99 (defcustom tramp-backup-directory-alist nil
100 "Alist of filename patterns and backup directory names.
101 Each element looks like (REGEXP . DIRECTORY), with the same meaning like
102 in `backup-directory-alist'. If a Tramp file is backed up, and DIRECTORY
103 is a local file name, the backup directory is prepended with Tramp file
104 name prefix \(method, user, host\) of file.
106 \(setq tramp-backup-directory-alist backup-directory-alist\)
108 gives the same backup policy for Tramp files on their hosts like the
109 policy for local files."
111 :type
'(repeat (cons (regexp :tag
"Regexp matching filename")
112 (directory :tag
"Backup directory name"))))))
114 ;; XEmacs case. We cannot check for `bkup-backup-directory-info', because
115 ;; the package "backup-dir" might not be loaded yet.
117 (when (featurep 'xemacs
)
118 (defcustom tramp-bkup-backup-directory-info nil
119 "*Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
120 It has the same meaning like `bkup-backup-directory-info' from package
121 `backup-dir'. If a Tramp file is backed up, and BACKUP-DIR is a local
122 file name, the backup directory is prepended with Tramp file name prefix
123 \(method, user, host\) of file.
125 \(setq tramp-bkup-backup-directory-info bkup-backup-directory-info\)
127 gives the same backup policy for Tramp files on their hosts like the
128 policy for local files."
130 (list (regexp :tag
"File regexp")
131 (string :tag
"Backup Dir")
136 (const search-upward
))))
139 (defcustom tramp-auto-save-directory nil
140 "*Put auto-save files in this directory, if set.
141 The idea is to use a local directory so that auto-saving is faster."
143 :type
'(choice (const nil
) string
))
145 (defcustom tramp-encoding-shell
146 (if (memq system-type
'(windows-nt))
149 "*Use this program for encoding and decoding commands on the local host.
150 This shell is used to execute the encoding and decoding command on the
151 local host, so if you want to use `~' in those commands, you should
152 choose a shell here which groks tilde expansion. `/bin/sh' normally
153 does not understand tilde expansion.
155 For encoding and deocding, commands like the following are executed:
157 /bin/sh -c COMMAND < INPUT > OUTPUT
159 This variable can be used to change the \"/bin/sh\" part. See the
160 variable `tramp-encoding-command-switch' for the \"-c\" part.
162 Note that this variable is not used for remote commands. There are
163 mechanisms in tramp.el which automatically determine the right shell to
164 use for the remote host."
166 :type
'(file :must-match t
))
168 (defcustom tramp-encoding-command-switch
169 (if (string-match "cmd\\.exe" tramp-encoding-shell
)
172 "*Use this switch together with `tramp-encoding-shell' for local commands.
173 See the variable `tramp-encoding-shell' for more information."
178 (defvar tramp-methods nil
179 "*Alist of methods for remote files.
180 This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
181 Each NAME stands for a remote access method. Each PARAM is a
182 pair of the form (KEY VALUE). The following KEYs are defined:
184 This specifies the Bourne shell to use on the remote host. This
185 MUST be a Bourne-like shell. It is normally not necessary to set
186 this to any value other than \"/bin/sh\": Tramp wants to use a shell
187 which groks tilde expansion, but it can search for it. Also note
188 that \"/bin/sh\" exists on all Unixen, this might not be true for
189 the value that you decide to use. You Have Been Warned.
190 * `tramp-login-program'
191 This specifies the name of the program to use for logging in to the
192 remote host. This may be the name of rsh or a workalike program,
193 or the name of telnet or a workalike, or the name of su or a workalike.
195 This specifies the list of arguments to pass to the above
196 mentioned program. Please note that this is a list of list of arguments,
197 that is, normally you don't want to put \"-a -b\" or \"-f foo\"
198 here. Instead, you want a list (\"-a\" \"-b\"), or (\"-f\" \"foo\").
199 There are some patterns: \"%h\" in this list is replaced by the host
200 name, \"%u\" is replaced by the user name, \"%p\" is replaced by the
201 port number, and \"%%\" can be used to obtain a literal percent character.
202 If a list containing \"%h\", \"%u\" or \"%p\" is unchanged during
203 expansion (i.e. no host or no user specified), this list is not used as
204 argument. By this, arguments like (\"-l\" \"%u\") are optional.
205 \"%t\" is replaced by the temporary file name produced with
206 `tramp-make-tramp-temp-file'. \"%k\" indicates the keep-date
207 parameter of a program, if exists.
209 When an asynchronous process is started, we know already that
210 the connection works. Therefore, we can pass additional
211 parameters to suppress diagnostic messages, in order not to
212 tamper the process output.
213 * `tramp-copy-program'
214 This specifies the name of the program to use for remotely copying
215 the file; this might be the absolute filename of rcp or the name of
218 This specifies the list of parameters to pass to the above mentioned
219 program, the hints for `tramp-login-args' also apply here.
220 * `tramp-copy-keep-date'
221 This specifies whether the copying program when the preserves the
222 timestamp of the original file.
223 * `tramp-copy-keep-tmpfile'
224 This specifies whether a temporary local file shall be kept
225 for optimization reasons (useful for \"rsync\" methods).
226 * `tramp-copy-recursive'
227 Whether the operation copies directories recursively.
228 * `tramp-default-port'
229 The default port of a method is needed in case of gateway connections.
230 Additionally, it is used as indication which method is prepared for
233 As the attribute name says, additional arguments are specified here
234 when a method is applied via a gateway.
235 * `tramp-password-end-of-line'
236 This specifies the string to use for terminating the line after
237 submitting the password. If this method parameter is nil, then the
238 value of the normal variable `tramp-default-password-end-of-line'
239 is used. This parameter is necessary because the \"plink\" program
240 requires any two characters after sending the password. These do
241 not have to be newline or carriage return characters. Other login
242 programs are happy with just one character, the newline character.
243 We use \"xy\" as the value for methods using \"plink\".
245 What does all this mean? Well, you should specify `tramp-login-program'
246 for all methods; this program is used to log in to the remote site. Then,
247 there are two ways to actually transfer the files between the local and the
248 remote side. One way is using an additional rcp-like program. If you want
249 to do this, set `tramp-copy-program' in the method.
251 Another possibility for file transfer is inline transfer, i.e. the
252 file is passed through the same buffer used by `tramp-login-program'. In
253 this case, the file contents need to be protected since the
254 `tramp-login-program' might use escape codes or the connection might not
255 be eight-bit clean. Therefore, file contents are encoded for transit.
256 See the variables `tramp-local-coding-commands' and
257 `tramp-remote-coding-commands' for details.
259 So, to summarize: if the method is an out-of-band method, then you
260 must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
261 inline method, then these two parameters should be nil. Methods which
262 are fit for gateways must have `tramp-default-port' at least.
266 When using `su' or `sudo' the phrase `open connection to a remote
267 host' sounds strange, but it is used nevertheless, for consistency.
268 No connection is opened to a remote host, but `su' or `sudo' is
269 started on the local host. You should specify a remote host
270 `localhost' or the name of the local host. Another host name is
271 useful only in combination with `tramp-default-proxies-alist'.")
273 (defun tramp-detect-ssh-controlmaster ()
274 "Call ssh to detect whether it supports the ControlMaster argument.
275 This function may return nil when the argument is supported, but
276 shouldn't return t when it isn't."
279 (call-process "ssh" nil t nil
"-o" "ControlMaster")
280 (goto-char (point-min))
281 (search-forward-regexp "Missing ControlMaster argument" nil t
))))
283 (defcustom tramp-default-method
284 ;; An external copy method seems to be preferred, because it is much
285 ;; more performant for large files, and it hasn't too serious delays
286 ;; for small files. But it must be ensured that there aren't
287 ;; permanent password queries. Either a password agent like
288 ;; "ssh-agent" or "Pageant" shall run, or the optional
289 ;; password-cache.el or auth-sources.el packages shall be active for
290 ;; password caching. "scpc" is chosen if we detect that the user is
291 ;; running OpenSSH 4.0 or newer.
293 ;; PuTTY is installed. We don't take it, if it is installed on a
294 ;; non-windows system, or pscp from the pssh (parallel ssh) package
296 ((and (eq system-type
'windows-nt
)
297 (executable-find "pscp"))
298 (if (or (fboundp 'password-read
)
299 (fboundp 'auth-source-user-or-password
)
300 (fboundp 'auth-source-search
)
301 ;; Pageant is running.
302 (tramp-compat-process-running-p "Pageant"))
305 ;; There is an ssh installation.
306 ((executable-find "scp")
308 ((tramp-detect-ssh-controlmaster) "scpc")
309 ((or (fboundp 'password-read
)
310 (fboundp 'auth-source-user-or-password
)
311 (fboundp 'auth-source-search
)
312 ;; ssh-agent is running.
313 (getenv "SSH_AUTH_SOCK")
314 (getenv "SSH_AGENT_PID"))
319 "*Default method to use for transferring files.
320 See `tramp-methods' for possibilities.
321 Also see `tramp-default-method-alist'."
326 (defcustom tramp-default-method-alist nil
327 "*Default method to use for specific host/user pairs.
328 This is an alist of items (HOST USER METHOD). The first matching item
329 specifies the method to use for a file name which does not specify a
330 method. HOST and USER are regular expressions or nil, which is
331 interpreted as a regular expression which always matches. If no entry
332 matches, the variable `tramp-default-method' takes effect.
334 If the file name does not specify the user, lookup is done using the
335 empty string for the user name.
337 See `tramp-methods' for a list of possibilities for METHOD."
339 :type
'(repeat (list (choice :tag
"Host regexp" regexp sexp
)
340 (choice :tag
"User regexp" regexp sexp
)
341 (choice :tag
"Method name" string
(const nil
)))))
343 (defcustom tramp-default-user nil
344 "*Default user to use for transferring files.
345 It is nil by default; otherwise settings in configuration files like
346 \"~/.ssh/config\" would be overwritten. Also see `tramp-default-user-alist'.
348 This variable is regarded as obsolete, and will be removed soon."
350 :type
'(choice (const nil
) string
))
353 (defcustom tramp-default-user-alist nil
354 "*Default user to use for specific method/host pairs.
355 This is an alist of items (METHOD HOST USER). The first matching item
356 specifies the user to use for a file name which does not specify a
357 user. METHOD and USER are regular expressions or nil, which is
358 interpreted as a regular expression which always matches. If no entry
359 matches, the variable `tramp-default-user' takes effect.
361 If the file name does not specify the method, lookup is done using the
362 empty string for the method name."
364 :type
'(repeat (list (choice :tag
"Method regexp" regexp sexp
)
365 (choice :tag
" Host regexp" regexp sexp
)
366 (choice :tag
" User name" string
(const nil
)))))
368 (defcustom tramp-default-host
(system-name)
369 "*Default host to use for transferring files.
370 Useful for su and sudo methods mostly."
374 (defcustom tramp-default-proxies-alist nil
375 "*Route to be followed for specific host/user pairs.
376 This is an alist of items (HOST USER PROXY). The first matching
377 item specifies the proxy to be passed for a file name located on
378 a remote target matching USER@HOST. HOST and USER are regular
379 expressions. PROXY must be a Tramp filename without a localname
380 part. Method and user name on PROXY are optional, which is
381 interpreted with the default values. PROXY can contain the
382 patterns %h and %u, which are replaced by the strings matching
383 HOST or USER, respectively.
385 HOST, USER or PROXY could also be Lisp forms, which will be
386 evaluated. The result must be a string or nil, which is
387 interpreted as a regular expression which always matches."
389 :type
'(repeat (list (choice :tag
"Host regexp" regexp sexp
)
390 (choice :tag
"User regexp" regexp sexp
)
391 (choice :tag
" Proxy name" string
(const nil
)))))
394 (defconst tramp-local-host-regexp
398 (list "localhost" "localhost6" (system-name) "127\.0\.0\.1" "::1") t
)
400 "*Host names which are regarded as local host.")
402 (defvar tramp-completion-function-alist nil
403 "*Alist of methods for remote files.
404 This is a list of entries of the form \(NAME PAIR1 PAIR2 ...\).
405 Each NAME stands for a remote access method. Each PAIR is of the form
406 \(FUNCTION FILE\). FUNCTION is responsible to extract user names and host
407 names from FILE for completion. The following predefined FUNCTIONs exists:
409 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
410 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
411 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
412 * `tramp-parse-shostkeys' for \"~/.ssh2/hostkeys/*\" like files,
413 * `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
414 * `tramp-parse-hosts' for \"/etc/hosts\" like files,
415 * `tramp-parse-passwd' for \"/etc/passwd\" like files.
416 * `tramp-parse-netrc' for \"~/.netrc\" like files.
417 * `tramp-parse-putty' for PuTTY registry keys.
419 FUNCTION can also be a customer defined function. For more details see
422 (defconst tramp-echo-mark-marker
"_echo"
423 "String marker to surround echoed commands.")
425 (defconst tramp-echo-mark-marker-length
(length tramp-echo-mark-marker
)
426 "String length of `tramp-echo-mark-marker'.")
428 (defconst tramp-echo-mark
429 (concat tramp-echo-mark-marker
430 (make-string tramp-echo-mark-marker-length ?
\b))
431 "String mark to be transmitted around shell commands.
432 Used to separate their echo from the output they produce. This
433 will only be used if we cannot disable remote echo via stty.
434 This string must have no effect on the remote shell except for
435 producing some echo which can later be detected by
436 `tramp-echoed-echo-mark-regexp'. Using `tramp-echo-mark-marker',
437 followed by an equal number of backspaces to erase them will
440 (defconst tramp-echoed-echo-mark-regexp
441 (format "%s\\(\b\\( \b\\)?\\)\\{%d\\}"
442 tramp-echo-mark-marker tramp-echo-mark-marker-length
)
443 "Regexp which matches `tramp-echo-mark' as it gets echoed by
446 (defcustom tramp-rsh-end-of-line
"\n"
447 "*String used for end of line in rsh connections.
448 I don't think this ever needs to be changed, so please tell me about it
449 if you need to change this.
450 Also see the method parameter `tramp-password-end-of-line' and the normal
451 variable `tramp-default-password-end-of-line'."
455 (defcustom tramp-default-password-end-of-line
456 tramp-rsh-end-of-line
457 "*String used for end of line after sending a password.
458 This variable provides the default value for the method parameter
459 `tramp-password-end-of-line', see `tramp-methods' for more details.
461 It seems that people using plink under Windows need to send
462 \"\\r\\n\" (carriage-return, then newline) after a password, but just
463 \"\\n\" after all other lines. This variable can be used for the
464 password, see `tramp-rsh-end-of-line' for the other cases.
466 The default value is to use the same value as `tramp-rsh-end-of-line'."
470 (defcustom tramp-login-prompt-regexp
471 ".*ogin\\( .*\\)?: *"
472 "*Regexp matching login-like prompts.
473 The regexp should match at end of buffer.
475 Sometimes the prompt is reported to look like \"login as:\"."
479 (defcustom tramp-shell-prompt-pattern
480 ;; Allow a prompt to start right after a ^M since it indeed would be
481 ;; displayed at the beginning of the line (and Zsh uses it). This
482 ;; regexp works only for GNU Emacs.
483 (concat (if (featurep 'xemacs
) "" "\\(?:^\\|\r\\)")
484 "[^#$%>\n]*#?[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*")
485 "Regexp to match prompts from remote shell.
486 Normally, Tramp expects you to configure `shell-prompt-pattern'
487 correctly, but sometimes it happens that you are connecting to a
488 remote host which sends a different kind of shell prompt. Therefore,
489 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
490 and also things matched by this variable. The default value of this
491 variable is similar to the default value of `shell-prompt-pattern',
492 which should work well in many cases.
494 This regexp must match both `tramp-initial-end-of-output' and
495 `tramp-end-of-output'."
499 (defcustom tramp-password-prompt-regexp
500 "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
501 "*Regexp matching password-like prompts.
502 The regexp should match at end of buffer.
504 The `sudo' program appears to insert a `^@' character into the prompt."
508 (defcustom tramp-wrong-passwd-regexp
510 ;; These strings should be on the last line
511 (regexp-opt '("Permission denied"
516 "Timeout, server not responding."
518 "Name or service not known"
519 "Host key verification failed."
520 "No supported authentication methods left to try!") t
)
524 ;; Here comes a list of regexes, separated by \\|
525 "Received signal [0-9]+"
527 "*Regexp matching a `login failed' message.
528 The regexp should match at end of buffer."
532 (defcustom tramp-yesno-prompt-regexp
534 (regexp-opt '("Are you sure you want to continue connecting (yes/no)?") t
)
536 "Regular expression matching all yes/no queries which need to be confirmed.
537 The confirmation should be done with yes or no.
538 The regexp should match at end of buffer.
539 See also `tramp-yn-prompt-regexp'."
543 (defcustom tramp-yn-prompt-regexp
545 (regexp-opt '("Store key in cache? (y/n)"
546 "Update cached key? (y/n, Return cancels connection)") t
)
548 "Regular expression matching all y/n queries which need to be confirmed.
549 The confirmation should be done with y or n.
550 The regexp should match at end of buffer.
551 See also `tramp-yesno-prompt-regexp'."
555 (defcustom tramp-terminal-prompt-regexp
559 "Terminal type\\? \\[.*\\]"
561 "Regular expression matching all terminal setting prompts.
562 The regexp should match at end of buffer.
563 The answer will be provided by `tramp-action-terminal', which see."
567 (defcustom tramp-operation-not-permitted-regexp
568 (concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
569 (regexp-opt '("Operation not permitted") t
))
570 "Regular expression matching keep-date problems in (s)cp operations.
571 Copying has been performed successfully already, so this message can
576 (defcustom tramp-copy-failed-regexp
578 (regexp-opt '("Permission denied"
581 "No such file or directory") t
)
583 "Regular expression matching copy problems in (s)cp operations."
587 (defcustom tramp-process-alive-regexp
589 "Regular expression indicating a process has finished.
590 In fact this expression is empty by intention, it will be used only to
591 check regularly the status of the associated process.
592 The answer will be provided by `tramp-action-process-alive',
593 `tramp-action-out-of-band', which see."
597 (defconst tramp-temp-name-prefix
"tramp."
598 "*Prefix to use for temporary files.
599 If this is a relative file name (such as \"tramp.\"), it is considered
600 relative to the directory name returned by the function
601 `tramp-compat-temporary-file-directory' (which see). It may also be an
602 absolute file name; don't forget to include a prefix for the filename
605 (defconst tramp-temp-buffer-name
" *tramp temp*"
606 "Buffer name for a temporary buffer.
607 It shall be used in combination with `generate-new-buffer-name'.")
609 (defvar tramp-temp-buffer-file-name nil
610 "File name of a persistent local temporary file.
611 Useful for \"rsync\" like methods.")
612 (make-variable-buffer-local 'tramp-temp-buffer-file-name
)
613 (put 'tramp-temp-buffer-file-name
'permanent-local t
)
615 ;; XEmacs is distributed with few Lisp packages. Further packages are
616 ;; installed using EFS. If we use a unified filename format, then
617 ;; Tramp is required in addition to EFS. (But why can't Tramp just
618 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
619 ;; just like before.) Another reason for using a separate filename
620 ;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
621 ;; Tramp only knows how to deal with `file-name-handler-alist', not
624 ;; Currently, we have the choice between 'ftp, 'sep, and 'url.
626 (defcustom tramp-syntax
627 (if (featurep 'xemacs
) 'sep
'ftp
)
628 "Tramp filename syntax to be used.
630 It can have the following values:
632 'ftp -- Ange-FTP respective EFS like syntax (GNU Emacs default)
633 'sep -- Syntax as defined for XEmacs (not available yet for GNU Emacs)
634 'url -- URL-like syntax."
636 :type
(if (featurep 'xemacs
)
637 '(choice (const :tag
"EFS" ftp
)
638 (const :tag
"XEmacs" sep
)
639 (const :tag
"URL" url
))
640 '(choice (const :tag
"Ange-FTP" ftp
)
641 (const :tag
"URL" url
))))
643 (defconst tramp-prefix-format
644 (cond ((equal tramp-syntax
'ftp
) "/")
645 ((equal tramp-syntax
'sep
) "/[")
646 ((equal tramp-syntax
'url
) "/")
647 (t (error "Wrong `tramp-syntax' defined")))
648 "*String matching the very beginning of Tramp file names.
649 Used in `tramp-make-tramp-file-name'.")
651 (defconst tramp-prefix-regexp
652 (concat "^" (regexp-quote tramp-prefix-format
))
653 "*Regexp matching the very beginning of Tramp file names.
654 Should always start with \"^\". Derived from `tramp-prefix-format'.")
656 (defconst tramp-method-regexp
658 "*Regexp matching methods identifiers.")
660 (defconst tramp-postfix-method-format
661 (cond ((equal tramp-syntax
'ftp
) ":")
662 ((equal tramp-syntax
'sep
) "/")
663 ((equal tramp-syntax
'url
) "://")
664 (t (error "Wrong `tramp-syntax' defined")))
665 "*String matching delimiter between method and user or host names.
666 Used in `tramp-make-tramp-file-name'.")
668 (defconst tramp-postfix-method-regexp
669 (regexp-quote tramp-postfix-method-format
)
670 "*Regexp matching delimiter between method and user or host names.
671 Derived from `tramp-postfix-method-format'.")
673 (defconst tramp-user-regexp
"[^:/ \t]+"
674 "*Regexp matching user names.")
677 (defconst tramp-prefix-domain-format
"%"
678 "*String matching delimiter between user and domain names.")
681 (defconst tramp-prefix-domain-regexp
682 (regexp-quote tramp-prefix-domain-format
)
683 "*Regexp matching delimiter between user and domain names.
684 Derived from `tramp-prefix-domain-format'.")
686 (defconst tramp-domain-regexp
"[-a-zA-Z0-9_.]+"
687 "*Regexp matching domain names.")
689 (defconst tramp-user-with-domain-regexp
690 (concat "\\(" tramp-user-regexp
"\\)"
691 tramp-prefix-domain-regexp
692 "\\(" tramp-domain-regexp
"\\)")
693 "*Regexp matching user names with domain names.")
695 (defconst tramp-postfix-user-format
"@"
696 "*String matching delimiter between user and host names.
697 Used in `tramp-make-tramp-file-name'.")
699 (defconst tramp-postfix-user-regexp
700 (regexp-quote tramp-postfix-user-format
)
701 "*Regexp matching delimiter between user and host names.
702 Derived from `tramp-postfix-user-format'.")
704 (defconst tramp-host-regexp
"[a-zA-Z0-9_.-]+"
705 "*Regexp matching host names.")
707 (defconst tramp-prefix-ipv6-format
708 (cond ((equal tramp-syntax
'ftp
) "[")
709 ((equal tramp-syntax
'sep
) "")
710 ((equal tramp-syntax
'url
) "[")
711 (t (error "Wrong `tramp-syntax' defined")))
712 "*String matching left hand side of IPv6 addresses.
713 Used in `tramp-make-tramp-file-name'.")
715 (defconst tramp-prefix-ipv6-regexp
716 (regexp-quote tramp-prefix-ipv6-format
)
717 "*Regexp matching left hand side of IPv6 addresses.
718 Derived from `tramp-prefix-ipv6-format'.")
720 ;; The following regexp is a bit sloppy. But it shall serve our
721 ;; purposes. It covers also IPv4 mapped IPv6 addresses, like in
722 ;; "::ffff:192.168.0.1".
723 (defconst tramp-ipv6-regexp
724 "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9.]+"
725 "*Regexp matching IPv6 addresses.")
727 (defconst tramp-postfix-ipv6-format
728 (cond ((equal tramp-syntax
'ftp
) "]")
729 ((equal tramp-syntax
'sep
) "")
730 ((equal tramp-syntax
'url
) "]")
731 (t (error "Wrong `tramp-syntax' defined")))
732 "*String matching right hand side of IPv6 addresses.
733 Used in `tramp-make-tramp-file-name'.")
735 (defconst tramp-postfix-ipv6-regexp
736 (regexp-quote tramp-postfix-ipv6-format
)
737 "*Regexp matching right hand side of IPv6 addresses.
738 Derived from `tramp-postfix-ipv6-format'.")
740 (defconst tramp-prefix-port-format
741 (cond ((equal tramp-syntax
'ftp
) "#")
742 ((equal tramp-syntax
'sep
) "#")
743 ((equal tramp-syntax
'url
) ":")
744 (t (error "Wrong `tramp-syntax' defined")))
745 "*String matching delimiter between host names and port numbers.")
747 (defconst tramp-prefix-port-regexp
748 (regexp-quote tramp-prefix-port-format
)
749 "*Regexp matching delimiter between host names and port numbers.
750 Derived from `tramp-prefix-port-format'.")
752 (defconst tramp-port-regexp
"[0-9]+"
753 "*Regexp matching port numbers.")
755 (defconst tramp-host-with-port-regexp
756 (concat "\\(" tramp-host-regexp
"\\)"
757 tramp-prefix-port-regexp
758 "\\(" tramp-port-regexp
"\\)")
759 "*Regexp matching host names with port numbers.")
761 (defconst tramp-postfix-host-format
762 (cond ((equal tramp-syntax
'ftp
) ":")
763 ((equal tramp-syntax
'sep
) "]")
764 ((equal tramp-syntax
'url
) "")
765 (t (error "Wrong `tramp-syntax' defined")))
766 "*String matching delimiter between host names and localnames.
767 Used in `tramp-make-tramp-file-name'.")
769 (defconst tramp-postfix-host-regexp
770 (regexp-quote tramp-postfix-host-format
)
771 "*Regexp matching delimiter between host names and localnames.
772 Derived from `tramp-postfix-host-format'.")
774 (defconst tramp-localname-regexp
".*$"
775 "*Regexp matching localnames.")
777 ;;; File name format:
779 (defconst tramp-file-name-structure
783 "\\(" "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
"\\)?"
784 "\\(" "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
"\\)?"
785 "\\(" "\\(" tramp-host-regexp
787 tramp-prefix-ipv6-regexp tramp-ipv6-regexp
788 tramp-postfix-ipv6-regexp
"\\)"
789 "\\(" tramp-prefix-port-regexp tramp-port-regexp
"\\)?" "\\)?"
790 tramp-postfix-host-regexp
791 "\\(" tramp-localname-regexp
"\\)")
794 "*List of five elements (REGEXP METHOD USER HOST FILE), detailing \
795 the Tramp file name structure.
797 The first element REGEXP is a regular expression matching a Tramp file
798 name. The regex should contain parentheses around the method name,
799 the user name, the host name, and the file name parts.
801 The second element METHOD is a number, saying which pair of
802 parentheses matches the method name. The third element USER is
803 similar, but for the user name. The fourth element HOST is similar,
804 but for the host name. The fifth element FILE is for the file name.
805 These numbers are passed directly to `match-string', which see. That
806 means the opening parentheses are counted to identify the pair.
808 See also `tramp-file-name-regexp'.")
811 (defconst tramp-file-name-regexp-unified
812 (if (memq system-type
'(cygwin windows-nt
))
813 "\\`/\\([^[/:]\\{2,\\}\\|[^/]\\{2,\\}]\\):"
814 "\\`/\\([^[/:]+\\|[^/]+]\\):")
815 "Value for `tramp-file-name-regexp' for unified remoting.
816 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
817 Tramp. See `tramp-file-name-structure' for more explanations.
819 On W32 systems, the volume letter must be ignored.")
822 (defconst tramp-file-name-regexp-separate
"\\`/\\[.*\\]"
823 "Value for `tramp-file-name-regexp' for separate remoting.
824 XEmacs uses a separate filename syntax for Tramp and EFS.
825 See `tramp-file-name-structure' for more explanations.")
828 (defconst tramp-file-name-regexp-url
"\\`/[^/:]+://"
829 "Value for `tramp-file-name-regexp' for URL-like remoting.
830 See `tramp-file-name-structure' for more explanations.")
833 (defconst tramp-file-name-regexp
834 (cond ((equal tramp-syntax
'ftp
) tramp-file-name-regexp-unified
)
835 ((equal tramp-syntax
'sep
) tramp-file-name-regexp-separate
)
836 ((equal tramp-syntax
'url
) tramp-file-name-regexp-url
)
837 (t (error "Wrong `tramp-syntax' defined")))
838 "*Regular expression matching file names handled by Tramp.
839 This regexp should match Tramp file names but no other file names.
840 When tramp.el is loaded, this regular expression is prepended to
841 `file-name-handler-alist', and that is searched sequentially. Thus,
842 if the Tramp entry appears rather early in the `file-name-handler-alist'
843 and is a bit too general, then some files might be considered Tramp
844 files which are not really Tramp files.
846 Please note that the entry in `file-name-handler-alist' is made when
847 this file \(tramp.el\) is loaded. This means that this variable must be set
848 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
849 updated after changing this variable.
851 Also see `tramp-file-name-structure'.")
854 (defconst tramp-root-regexp
855 (if (memq system-type
'(cygwin windows-nt
))
856 "\\`\\([a-zA-Z]:\\)?/"
858 "Beginning of an incomplete Tramp file name.
859 Usually, it is just \"\\\\`/\". On W32 systems, there might be a
860 volume letter, which will be removed by `tramp-drop-volume-letter'.")
863 (defconst tramp-completion-file-name-regexp-unified
864 (if (memq system-type
'(cygwin windows-nt
))
865 (concat tramp-root-regexp
"[^/]\\{2,\\}\\'")
866 (concat tramp-root-regexp
"[^/]*\\'"))
867 "Value for `tramp-completion-file-name-regexp' for unified remoting.
868 GNU Emacs uses a unified filename syntax for Tramp and Ange-FTP.
869 See `tramp-file-name-structure' for more explanations.
871 On W32 systems, the volume letter must be ignored.")
874 (defconst tramp-completion-file-name-regexp-separate
875 (concat tramp-root-regexp
"\\([[][^]]*\\)?\\'")
876 "Value for `tramp-completion-file-name-regexp' for separate remoting.
877 XEmacs uses a separate filename syntax for Tramp and EFS.
878 See `tramp-file-name-structure' for more explanations.")
881 (defconst tramp-completion-file-name-regexp-url
882 (concat tramp-root-regexp
"[^/:]+\\(:\\(/\\(/[^/]*\\)?\\)?\\)?\\'")
883 "Value for `tramp-completion-file-name-regexp' for URL-like remoting.
884 See `tramp-file-name-structure' for more explanations.")
887 (defconst tramp-completion-file-name-regexp
888 (cond ((equal tramp-syntax
'ftp
) tramp-completion-file-name-regexp-unified
)
889 ((equal tramp-syntax
'sep
) tramp-completion-file-name-regexp-separate
)
890 ((equal tramp-syntax
'url
) tramp-completion-file-name-regexp-url
)
891 (t (error "Wrong `tramp-syntax' defined")))
892 "*Regular expression matching file names handled by Tramp completion.
893 This regexp should match partial Tramp file names only.
895 Please note that the entry in `file-name-handler-alist' is made when
896 this file (tramp.el) is loaded. This means that this variable must be set
897 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
898 updated after changing this variable.
900 Also see `tramp-file-name-structure'.")
902 ;; Chunked sending kludge. We set this to 500 for black-listed constellations
903 ;; known to have a bug in `process-send-string'; some ssh connections appear
904 ;; to drop bytes when data is sent too quickly. There is also a connection
905 ;; buffer local variable, which is computed depending on remote host properties
906 ;; when `tramp-chunksize' is zero or nil.
907 (defcustom tramp-chunksize
908 (when (and (not (featurep 'xemacs
))
909 (memq system-type
'(hpux)))
911 ;; Parentheses in docstring starting at beginning of line are escaped.
912 ;; Fontification is messed up when
913 ;; `open-paren-in-column-0-is-defun-start' set to t.
914 "*If non-nil, chunksize for sending input to local process.
915 It is necessary only on systems which have a buggy `process-send-string'
916 implementation. The necessity, whether this variable must be set, can be
917 checked via the following code:
920 (let* ((user \"xxx\") (host \"yyy\")
922 (sent init) (received init))
923 (while (= sent received)
924 (setq sent (+ sent step))
926 (let ((proc (start-process (buffer-name) (current-buffer)
927 \"ssh\" \"-l\" user host \"wc\" \"-c\")))
928 (when (memq (process-status proc) '(run open))
929 (process-send-string proc (make-string sent ?\\ ))
930 (process-send-eof proc)
931 (process-send-eof proc))
932 (while (not (progn (goto-char (point-min))
933 (re-search-forward \"\\\\w+\" (point-max) t)))
934 (accept-process-output proc 1))
935 (when (memq (process-status proc) '(run open))
936 (setq received (string-to-number (match-string 0)))
937 (delete-process proc)
938 (message \"Bytes sent: %s\\tBytes received: %s\" sent received)
940 (if (> sent (+ init step))
941 (message \"You should set `tramp-chunksize' to a maximum of %s\"
943 (message \"Test does not work\")
944 (display-buffer (current-buffer))
947 In the Emacs normally running Tramp, evaluate the above code
948 \(replace \"xxx\" and \"yyy\" by the remote user and host name,
949 respectively\). You can do this, for example, by pasting it into
950 the `*scratch*' buffer and then hitting C-j with the cursor after the
951 last closing parenthesis. Note that it works only if you have configured
952 \"ssh\" to run without password query, see ssh-agent\(1\).
954 You will see the number of bytes sent successfully to the remote host.
955 If that number exceeds 1000, you can stop the execution by hitting
956 C-g, because your Emacs is likely clean.
958 When it is necessary to set `tramp-chunksize', you might consider to
959 use an out-of-the-band method \(like \"scp\"\) instead of an internal one
960 \(like \"ssh\"\), because setting `tramp-chunksize' to non-nil decreases
963 If your Emacs is buggy, the code stops and gives you an indication
964 about the value `tramp-chunksize' should be set. Maybe you could just
965 experiment a bit, e.g. changing the values of `init' and `step'
966 in the third line of the code.
968 Please raise a bug report via \"M-x tramp-bug\" if your system needs
969 this variable to be set as well."
971 :type
'(choice (const nil
) integer
))
973 ;; Logging in to a remote host normally requires obtaining a pty. But
974 ;; Emacs on MacOS X has process-connection-type set to nil by default,
975 ;; so on those systems Tramp doesn't obtain a pty. Here, we allow
976 ;; for an override of the system default.
977 (defcustom tramp-process-connection-type t
978 "Overrides `process-connection-type' for connections from Tramp.
979 Tramp binds process-connection-type to the value given here before
980 opening a connection to a remote host."
982 :type
'(choice (const nil
) (const t
) (const pty
)))
984 (defcustom tramp-completion-reread-directory-timeout
10
985 "Defines seconds since last remote command before rereading a directory.
986 A remote directory might have changed its contents. In order to
987 make it visible during file name completion in the minibuffer,
988 Tramp flushes its cache and rereads the directory contents when
989 more than `tramp-completion-reread-directory-timeout' seconds
990 have been gone since last remote command execution. A value of `t'
991 would require an immediate reread during filename completion, `nil'
992 means to use always cached values for the directory contents."
994 :type
'(choice (const nil
) integer
))
996 ;;; Internal Variables:
998 (defvar tramp-current-method nil
999 "Connection method for this *tramp* buffer.")
1001 (defvar tramp-current-user nil
1002 "Remote login name for this *tramp* buffer.")
1004 (defvar tramp-current-host nil
1005 "Remote host for this *tramp* buffer.")
1008 (defconst tramp-completion-file-name-handler-alist
1009 '((file-name-all-completions . tramp-completion-handle-file-name-all-completions
)
1010 (file-name-completion . tramp-completion-handle-file-name-completion
))
1011 "Alist of completion handler functions.
1012 Used for file names matching `tramp-file-name-regexp'. Operations
1013 not mentioned here will be handled by Tramp's file name handler
1014 functions, or the normal Emacs functions.")
1016 ;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
1017 ;;;###tramp-autoload
1018 (defvar tramp-foreign-file-name-handler-alist nil
1019 "Alist of elements (FUNCTION . HANDLER) for foreign methods handled specially.
1020 If (FUNCTION FILENAME) returns non-nil, then all I/O on that file is done by
1023 ;;; Internal functions which must come first:
1025 ;; Conversion functions between external representation and
1026 ;; internal data structure. Convenience functions for internal
1029 (defun tramp-file-name-p (vec)
1030 "Check, whether VEC is a Tramp object."
1031 (and (vectorp vec
) (= 4 (length vec
))))
1033 (defun tramp-file-name-method (vec)
1034 "Return method component of VEC."
1035 (and (tramp-file-name-p vec
) (aref vec
0)))
1037 (defun tramp-file-name-user (vec)
1038 "Return user component of VEC."
1039 (and (tramp-file-name-p vec
) (aref vec
1)))
1041 (defun tramp-file-name-host (vec)
1042 "Return host component of VEC."
1043 (and (tramp-file-name-p vec
) (aref vec
2)))
1045 (defun tramp-file-name-localname (vec)
1046 "Return localname component of VEC."
1047 (and (tramp-file-name-p vec
) (aref vec
3)))
1049 ;; The user part of a Tramp file name vector can be of kind
1050 ;; "user%domain". Sometimes, we must extract these parts.
1051 (defun tramp-file-name-real-user (vec)
1052 "Return the user name of VEC without domain."
1054 (let ((user (tramp-file-name-user vec
)))
1055 (if (and (stringp user
)
1056 (string-match tramp-user-with-domain-regexp user
))
1057 (match-string 1 user
)
1060 (defun tramp-file-name-domain (vec)
1061 "Return the domain name of VEC."
1063 (let ((user (tramp-file-name-user vec
)))
1065 (string-match tramp-user-with-domain-regexp user
)
1066 (match-string 2 user
)))))
1068 ;; The host part of a Tramp file name vector can be of kind
1069 ;; "host#port". Sometimes, we must extract these parts.
1070 (defun tramp-file-name-real-host (vec)
1071 "Return the host name of VEC without port."
1073 (let ((host (tramp-file-name-host vec
)))
1074 (if (and (stringp host
)
1075 (string-match tramp-host-with-port-regexp host
))
1076 (match-string 1 host
)
1079 (defun tramp-file-name-port (vec)
1080 "Return the port number of VEC."
1082 (let ((method (tramp-file-name-method vec
))
1083 (host (tramp-file-name-host vec
)))
1084 (or (and (stringp host
)
1085 (string-match tramp-host-with-port-regexp host
)
1086 (string-to-number (match-string 2 host
)))
1087 (tramp-get-method-parameter method
'tramp-default-port
)))))
1089 ;;;###tramp-autoload
1090 (defun tramp-tramp-file-p (name)
1091 "Return t if NAME is a string with Tramp file name syntax."
1093 (and (stringp name
) (string-match tramp-file-name-regexp name
))))
1095 (defun tramp-find-method (method user host
)
1096 "Return the right method string to use.
1097 This is METHOD, if non-nil. Otherwise, do a lookup in
1098 `tramp-default-method-alist'."
1100 (let ((choices tramp-default-method-alist
)
1103 (setq item
(pop choices
))
1104 (when (and (string-match (or (nth 0 item
) "") (or host
""))
1105 (string-match (or (nth 1 item
) "") (or user
"")))
1106 (setq lmethod
(nth 2 item
))
1107 (setq choices nil
)))
1109 tramp-default-method
))
1111 (defun tramp-find-user (method user host
)
1112 "Return the right user string to use.
1113 This is USER, if non-nil. Otherwise, do a lookup in
1114 `tramp-default-user-alist'."
1116 (let ((choices tramp-default-user-alist
)
1119 (setq item
(pop choices
))
1120 (when (and (string-match (or (nth 0 item
) "") (or method
""))
1121 (string-match (or (nth 1 item
) "") (or host
"")))
1122 (setq luser
(nth 2 item
))
1123 (setq choices nil
)))
1125 tramp-default-user
))
1127 (defun tramp-find-host (method user host
)
1128 "Return the right host string to use.
1129 This is HOST, if non-nil. Otherwise, it is `tramp-default-host'."
1130 (or (and (> (length host
) 0) host
)
1131 tramp-default-host
))
1133 (defun tramp-dissect-file-name (name &optional nodefault
)
1134 "Return a `tramp-file-name' structure.
1135 The structure consists of remote method, remote user, remote host
1136 and localname (file name on remote host). If NODEFAULT is
1137 non-nil, the file name parts are not expanded to their default
1140 (let ((match (string-match (nth 0 tramp-file-name-structure
) name
)))
1141 (unless match
(error "Not a Tramp file name: %s" name
))
1142 (let ((method (match-string (nth 1 tramp-file-name-structure
) name
))
1143 (user (match-string (nth 2 tramp-file-name-structure
) name
))
1144 (host (match-string (nth 3 tramp-file-name-structure
) name
))
1145 (localname (match-string (nth 4 tramp-file-name-structure
) name
)))
1147 (when (string-match tramp-prefix-ipv6-regexp host
)
1148 (setq host
(replace-match "" nil t host
)))
1149 (when (string-match tramp-postfix-ipv6-regexp host
)
1150 (setq host
(replace-match "" nil t host
))))
1152 (vector method user host localname
)
1154 (tramp-find-method method user host
)
1155 (tramp-find-user method user host
)
1156 (tramp-find-host method user host
)
1159 (defun tramp-buffer-name (vec)
1160 "A name for the connection buffer VEC."
1161 ;; We must use `tramp-file-name-real-host', because for gateway
1162 ;; methods the default port will be expanded later on, which would
1164 (let ((method (tramp-file-name-method vec
))
1165 (user (tramp-file-name-user vec
))
1166 (host (tramp-file-name-real-host vec
)))
1167 (if (not (zerop (length user
)))
1168 (format "*tramp/%s %s@%s*" method user host
)
1169 (format "*tramp/%s %s*" method host
))))
1171 (defun tramp-make-tramp-file-name (method user host localname
)
1172 "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME."
1173 (concat tramp-prefix-format
1174 (when (not (zerop (length method
)))
1175 (concat method tramp-postfix-method-format
))
1176 (when (not (zerop (length user
)))
1177 (concat user tramp-postfix-user-format
))
1179 (if (string-match tramp-ipv6-regexp host
)
1180 (concat tramp-prefix-ipv6-format host tramp-postfix-ipv6-format
)
1182 tramp-postfix-host-format
1183 (when localname localname
)))
1185 (defun tramp-completion-make-tramp-file-name (method user host localname
)
1186 "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME.
1187 It must not be a complete Tramp file name, but as long as there are
1188 necessary only. This function will be used in file name completion."
1189 (concat tramp-prefix-format
1190 (when (not (zerop (length method
)))
1191 (concat method tramp-postfix-method-format
))
1192 (when (not (zerop (length user
)))
1193 (concat user tramp-postfix-user-format
))
1194 (when (not (zerop (length host
)))
1196 (if (string-match tramp-ipv6-regexp host
)
1198 tramp-prefix-ipv6-format host tramp-postfix-ipv6-format
)
1200 tramp-postfix-host-format
))
1201 (when localname localname
)))
1203 (defun tramp-get-buffer (vec)
1204 "Get the connection buffer to be used for VEC."
1205 (or (get-buffer (tramp-buffer-name vec
))
1206 (with-current-buffer (get-buffer-create (tramp-buffer-name vec
))
1207 (setq buffer-undo-list t
)
1208 (setq default-directory
1209 (tramp-make-tramp-file-name
1210 (tramp-file-name-method vec
)
1211 (tramp-file-name-user vec
)
1212 (tramp-file-name-host vec
)
1216 (defun tramp-get-connection-buffer (vec)
1217 "Get the connection buffer to be used for VEC.
1218 In case a second asynchronous communication has been started, it is different
1219 from `tramp-get-buffer'."
1220 (or (tramp-get-connection-property vec
"process-buffer" nil
)
1221 (tramp-get-buffer vec
)))
1223 (defun tramp-get-connection-name (vec)
1224 "Get the connection name to be used for VEC.
1225 In case a second asynchronous communication has been started, it is different
1226 from the default one."
1227 (or (tramp-get-connection-property vec
"process-name" nil
)
1228 (tramp-buffer-name vec
)))
1230 (defun tramp-get-connection-process (vec)
1231 "Get the connection process to be used for VEC.
1232 In case a second asynchronous communication has been started, it is different
1233 from the default one."
1234 (get-process (tramp-get-connection-name vec
)))
1236 (defun tramp-debug-buffer-name (vec)
1237 "A name for the debug buffer for VEC."
1238 ;; We must use `tramp-file-name-real-host', because for gateway
1239 ;; methods the default port will be expanded later on, which would
1241 (let ((method (tramp-file-name-method vec
))
1242 (user (tramp-file-name-user vec
))
1243 (host (tramp-file-name-real-host vec
)))
1244 (if (not (zerop (length user
)))
1245 (format "*debug tramp/%s %s@%s*" method user host
)
1246 (format "*debug tramp/%s %s*" method host
))))
1248 (defconst tramp-debug-outline-regexp
1249 "[0-9]+:[0-9]+:[0-9]+\\.[0-9]+ [a-z0-9-]+ (\\([0-9]+\\)) #"
1250 "Used for highlighting Tramp debug buffers in `outline-mode'.")
1252 (defun tramp-debug-outline-level ()
1253 "Return the depth to which a statement is nested in the outline.
1254 Point must be at the beginning of a header line.
1256 The outline level is equal to the verbosity of the Tramp message."
1257 (1+ (string-to-number (match-string 1))))
1259 (defun tramp-get-debug-buffer (vec)
1260 "Get the debug buffer for VEC."
1261 (with-current-buffer
1262 (get-buffer-create (tramp-debug-buffer-name vec
))
1264 (setq buffer-undo-list t
)
1265 ;; Activate `outline-mode'. This runs `text-mode-hook' and
1266 ;; `outline-mode-hook'. We must prevent that local processes
1267 ;; die. Yes: I've seen `flyspell-mode', which starts "ispell".
1268 ;; Furthermore, `outline-regexp' must have the correct value
1269 ;; already, because it is used by `font-lock-compile-keywords'.
1270 (let ((default-directory (tramp-compat-temporary-file-directory))
1271 (outline-regexp tramp-debug-outline-regexp
))
1273 (set (make-local-variable 'outline-regexp
) tramp-debug-outline-regexp
)
1274 (set (make-local-variable 'outline-level
) 'tramp-debug-outline-level
))
1277 (defsubst tramp-debug-message
(vec fmt-string
&rest args
)
1278 "Append message to debug buffer.
1279 Message is formatted with FMT-STRING as control string and the remaining
1280 ARGS to actually emit the message (if applicable)."
1281 (when (get-buffer (tramp-buffer-name vec
))
1282 (with-current-buffer (tramp-get-debug-buffer vec
)
1283 (goto-char (point-max))
1288 ";; %sEmacs: %s Tramp: %s -*- mode: outline; -*-"
1289 (if (featurep 'sxemacs
) "SX" (if (featurep 'xemacs
) "X" "GNU "))
1290 emacs-version tramp-version
)))
1294 (let ((now (current-time)))
1295 (insert (format-time-string "%T." now
))
1296 (insert (format "%06d " (nth 2 now
))))
1297 ;; Calling Tramp function. We suppress compat and trace
1298 ;; functions from being displayed.
1299 (let ((btn 1) btf fn
)
1301 (setq btf
(nth 1 (backtrace-frame btn
)))
1305 (setq fn
(symbol-name btf
))
1308 (string-match "^tramp" fn
)
1314 '("tramp-compat-funcall"
1315 "tramp-compat-with-temp-message"
1316 "tramp-debug-message"
1318 "tramp-error-with-buffer"
1324 (setq btn
(1+ btn
))))
1325 ;; The following code inserts filename and line number.
1326 ;; Should be deactivated by default, because it is time
1328 ; (let ((ffn (find-function-noselect (intern fn))))
1332 ; (file-name-nondirectory (buffer-file-name (car ffn)))
1333 ; (with-current-buffer (car ffn)
1334 ; (1+ (count-lines (point-min) (cdr ffn)))))))
1335 (insert (format "%s " fn
)))
1337 (insert (apply 'format fmt-string args
)))))
1339 (defvar tramp-message-show-message t
1340 "Show Tramp message in the minibuffer.
1341 This variable is used to disable messages from `tramp-error'.
1342 The messages are visible anyway, because an error is raised.")
1344 (defsubst tramp-message
(vec-or-proc level fmt-string
&rest args
)
1345 "Emit a message depending on verbosity level.
1346 VEC-OR-PROC identifies the Tramp buffer to use. It can be either a
1347 vector or a process. LEVEL says to be quiet if `tramp-verbose' is
1348 less than LEVEL. The message is emitted only if `tramp-verbose' is
1349 greater than or equal to LEVEL.
1351 The message is also logged into the debug buffer when `tramp-verbose'
1352 is greater than or equal 4.
1354 Calls functions `message' and `tramp-debug-message' with FMT-STRING as
1355 control string and the remaining ARGS to actually emit the message (if
1358 (when (<= level tramp-verbose
)
1359 ;; Match data must be preserved!
1361 ;; Display only when there is a minimum level.
1362 (when (and tramp-message-show-message
(<= level
3))
1368 ((= level
2) "Warning: ")
1372 ;; Log only when there is a minimum level.
1373 (when (>= tramp-verbose
4)
1374 (when (and vec-or-proc
1375 (processp vec-or-proc
)
1376 (buffer-name (process-buffer vec-or-proc
)))
1377 (with-current-buffer (process-buffer vec-or-proc
)
1378 ;; Translate proc to vec.
1379 (setq vec-or-proc
(tramp-dissect-file-name default-directory
))))
1380 (when (and vec-or-proc
(vectorp vec-or-proc
))
1381 (apply 'tramp-debug-message
1383 (concat (format "(%d) # " level
) fmt-string
)
1386 (defsubst tramp-error
(vec-or-proc signal fmt-string
&rest args
)
1388 VEC-OR-PROC identifies the connection to use, SIGNAL is the
1389 signal identifier to be raised, remaining args passed to
1390 `tramp-message'. Finally, signal SIGNAL is raised."
1391 (let (tramp-message-show-message)
1394 (error-message-string
1396 (get signal
'error-message
)
1397 (apply 'format fmt-string args
))))
1398 (signal signal
(list (apply 'format fmt-string args
)))))
1400 (defsubst tramp-error-with-buffer
1401 (buffer vec-or-proc signal fmt-string
&rest args
)
1402 "Emit an error, and show BUFFER.
1403 If BUFFER is nil, show the connection buffer. Wait for 30\", or until
1404 an input event arrives. The other arguments are passed to `tramp-error'."
1405 (save-window-excursion
1407 (apply 'tramp-error vec-or-proc signal fmt-string args
)
1408 (when (and vec-or-proc
1409 (not (zerop tramp-verbose
))
1410 (not (tramp-completion-mode-p)))
1411 (let ((enable-recursive-minibuffers t
))
1413 (or (and (bufferp buffer
) buffer
)
1414 (and (processp vec-or-proc
) (process-buffer vec-or-proc
))
1415 (tramp-get-buffer vec-or-proc
)))
1418 (defmacro with-parsed-tramp-file-name
(filename var
&rest body
)
1419 "Parse a Tramp filename and make components available in the body.
1421 First arg FILENAME is evaluated and dissected into its components.
1422 Second arg VAR is a symbol. It is used as a variable name to hold
1423 the filename structure. It is also used as a prefix for the variables
1424 holding the components. For example, if VAR is the symbol `foo', then
1425 `foo' will be bound to the whole structure, `foo-method' will be bound to
1426 the method component, and so on for `foo-user', `foo-host', `foo-localname'.
1428 Remaining args are Lisp expressions to be evaluated (inside an implicit
1431 If VAR is nil, then we bind `v' to the structure and `method', `user',
1432 `host', `localname' to the components."
1433 `(let* ((,(or var
'v
) (tramp-dissect-file-name ,filename
))
1434 (,(if var
(intern (concat (symbol-name var
) "-method")) 'method
)
1435 (tramp-file-name-method ,(or var
'v
)))
1436 (,(if var
(intern (concat (symbol-name var
) "-user")) 'user
)
1437 (tramp-file-name-user ,(or var
'v
)))
1438 (,(if var
(intern (concat (symbol-name var
) "-host")) 'host
)
1439 (tramp-file-name-host ,(or var
'v
)))
1440 (,(if var
(intern (concat (symbol-name var
) "-localname")) 'localname
)
1441 (tramp-file-name-localname ,(or var
'v
))))
1444 (put 'with-parsed-tramp-file-name
'lisp-indent-function
2)
1445 (put 'with-parsed-tramp-file-name
'edebug-form-spec
'(form symbolp body
))
1446 (tramp-compat-font-lock-add-keywords
1447 'emacs-lisp-mode
'("\\<with-parsed-tramp-file-name\\>"))
1449 (defun tramp-progress-reporter-update (reporter &optional value
)
1450 (let* ((parameters (cdr reporter
))
1451 (message (aref parameters
3)))
1452 (when (string-match message
(or (current-message) ""))
1453 (tramp-compat-funcall 'progress-reporter-update reporter value
))))
1455 (defmacro with-progress-reporter
(vec level message
&rest body
)
1456 "Executes BODY, spinning a progress reporter with MESSAGE.
1457 If LEVEL does not fit for visible messages, or if this is a
1458 nested call of the macro, there are only traces without a visible
1461 (tramp-message ,vec
,level
"%s..." ,message
)
1462 ;; We start a pulsing progress reporter after 3 seconds. Feature
1463 ;; introduced in Emacs 24.1.
1464 (when (and tramp-message-show-message
1465 ;; Display only when there is a minimum level.
1466 (<= ,level
(min tramp-verbose
3)))
1468 (setq pr
(tramp-compat-funcall 'make-progress-reporter
,message
)
1470 (run-at-time 3 0.1 'tramp-progress-reporter-update pr
)))))
1472 ;; Execute the body. Unset `tramp-message-show-message' when
1473 ;; the timer object is created, in order to suppress
1474 ;; concurrent timers.
1475 (let ((tramp-message-show-message
1476 (and tramp-message-show-message
(not tm
))))
1478 ;; Stop progress reporter.
1479 (if tm
(tramp-compat-funcall 'cancel-timer tm
))
1480 (tramp-message ,vec
,level
"%s...done" ,message
))))
1482 (put 'with-progress-reporter
'lisp-indent-function
3)
1483 (put 'with-progress-reporter
'edebug-form-spec t
)
1484 (tramp-compat-font-lock-add-keywords
1485 'emacs-lisp-mode
'("\\<with-progress-reporter\\>"))
1487 (eval-and-compile ;; Silence compiler.
1488 (if (memq system-type
'(cygwin windows-nt
))
1489 (defun tramp-drop-volume-letter (name)
1490 "Cut off unnecessary drive letter from file NAME.
1491 The functions `tramp-*-handle-expand-file-name' call `expand-file-name'
1492 locally on a remote file name. When the local system is a W32 system
1493 but the remote system is Unix, this introduces a superfluous drive
1494 letter into the file name. This function removes it."
1496 (if (string-match tramp-root-regexp name
)
1497 (replace-match "/" nil t name
)
1500 (defalias 'tramp-drop-volume-letter
'identity
)))
1502 ;;; Config Manipulation Functions:
1504 (defun tramp-set-completion-function (method function-list
)
1505 "Sets the list of completion functions for METHOD.
1506 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
1507 The FUNCTION is intended to parse FILE according its syntax.
1508 It might be a predefined FUNCTION, or a user defined FUNCTION.
1509 Predefined FUNCTIONs are `tramp-parse-rhosts', `tramp-parse-shosts',
1510 `tramp-parse-sconfig', `tramp-parse-hosts', `tramp-parse-passwd',
1511 and `tramp-parse-netrc'.
1515 (tramp-set-completion-function
1517 '((tramp-parse-sconfig \"/etc/ssh_config\")
1518 (tramp-parse-sconfig \"~/.ssh/config\")))"
1520 (let ((r function-list
)
1522 (setq tramp-completion-function-alist
1523 (delete (assoc method tramp-completion-function-alist
)
1524 tramp-completion-function-alist
))
1527 ;; Remove double entries.
1528 (when (member (car v
) (cdr v
))
1529 (setcdr v
(delete (car v
) (cdr v
))))
1530 ;; Check for function and file or registry key.
1531 (unless (and (functionp (nth 0 (car v
)))
1532 (if (string-match "^HKEY_CURRENT_USER" (nth 1 (car v
)))
1533 ;; Windows registry.
1534 (and (memq system-type
'(cygwin windows-nt
))
1536 (tramp-compat-call-process
1537 "reg" nil nil nil
"query" (nth 1 (car v
)))))
1538 ;; Configuration file.
1539 (file-exists-p (nth 1 (car v
)))))
1540 (setq r
(delete (car v
) r
)))
1544 (add-to-list 'tramp-completion-function-alist
1547 (defun tramp-get-completion-function (method)
1548 "Returns a list of completion functions for METHOD.
1549 For definition of that list see `tramp-set-completion-function'."
1551 ;; Hosts visited once shall be remembered.
1552 `(tramp-parse-connection-properties ,method
)
1553 ;; The method related defaults.
1554 (cdr (assoc method tramp-completion-function-alist
))))
1557 ;;; Fontification of `read-file-name':
1559 ;; rfn-eshadow.el is part of Emacs 22. It is autoloaded.
1560 (defvar tramp-rfn-eshadow-overlay
)
1561 (make-variable-buffer-local 'tramp-rfn-eshadow-overlay
)
1563 (defun tramp-rfn-eshadow-setup-minibuffer ()
1564 "Set up a minibuffer for `file-name-shadow-mode'.
1565 Adds another overlay hiding filename parts according to Tramp's
1566 special handling of `substitute-in-file-name'."
1567 (when (symbol-value 'minibuffer-completing-file-name
)
1568 (setq tramp-rfn-eshadow-overlay
1569 (tramp-compat-funcall
1571 (tramp-compat-funcall 'minibuffer-prompt-end
)
1572 (tramp-compat-funcall 'minibuffer-prompt-end
)))
1573 ;; Copy rfn-eshadow-overlay properties.
1574 (let ((props (tramp-compat-funcall
1575 'overlay-properties
(symbol-value 'rfn-eshadow-overlay
))))
1577 ;; The `field' property prevents correct minibuffer
1578 ;; completion; we exclude it.
1579 (if (not (eq (car props
) 'field
))
1580 (tramp-compat-funcall
1581 'overlay-put tramp-rfn-eshadow-overlay
(pop props
) (pop props
))
1582 (pop props
) (pop props
))))))
1584 (when (boundp 'rfn-eshadow-setup-minibuffer-hook
)
1585 (add-hook 'rfn-eshadow-setup-minibuffer-hook
1586 'tramp-rfn-eshadow-setup-minibuffer
)
1587 (add-hook 'tramp-unload-hook
1589 (remove-hook 'rfn-eshadow-setup-minibuffer-hook
1590 'tramp-rfn-eshadow-setup-minibuffer
))))
1592 (defconst tramp-rfn-eshadow-update-overlay-regexp
1593 (format "[^%s/~]*\\(/\\|~\\)" tramp-postfix-host-format
))
1595 (defun tramp-rfn-eshadow-update-overlay ()
1596 "Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input.
1597 This is intended to be used as a minibuffer `post-command-hook' for
1598 `file-name-shadow-mode'; the minibuffer should have already
1599 been set up by `rfn-eshadow-setup-minibuffer'."
1600 ;; In remote files name, there is a shadowing just for the local part.
1601 (let ((end (or (tramp-compat-funcall
1602 'overlay-end
(symbol-value 'rfn-eshadow-overlay
))
1603 (tramp-compat-funcall 'minibuffer-prompt-end
))))
1606 (tramp-compat-funcall 'buffer-substring-no-properties end
(point-max)))
1610 (1+ (or (string-match
1611 tramp-rfn-eshadow-update-overlay-regexp
(buffer-string) end
)
1614 (let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay
)
1615 (rfn-eshadow-update-overlay-hook nil
))
1616 (tramp-compat-funcall
1617 'move-overlay rfn-eshadow-overlay
(point-max) (point-max))
1618 (tramp-compat-funcall 'rfn-eshadow-update-overlay
)))))))
1620 (when (boundp 'rfn-eshadow-update-overlay-hook
)
1621 (add-hook 'rfn-eshadow-update-overlay-hook
1622 'tramp-rfn-eshadow-update-overlay
)
1623 (add-hook 'tramp-unload-hook
1625 (remove-hook 'rfn-eshadow-update-overlay-hook
1626 'tramp-rfn-eshadow-update-overlay
))))
1628 ;; Inodes don't exist for some file systems. Therefore we must
1629 ;; generate virtual ones. Used in `find-buffer-visiting'. The method
1630 ;; applied might be not so efficient (Ange-FTP uses hashes). But
1631 ;; performance isn't the major issue given that file transfer will
1633 (defvar tramp-inodes nil
1634 "Keeps virtual inodes numbers.")
1636 ;; Devices must distinguish physical file systems. The device numbers
1637 ;; provided by "lstat" aren't unique, because we operate on different hosts.
1638 ;; So we use virtual device numbers, generated by Tramp. Both Ange-FTP and
1639 ;; EFS use device number "-1". In order to be different, we use device number
1640 ;; (-1 . x), whereby "x" is unique for a given (method user host).
1641 (defvar tramp-devices nil
1642 "Keeps virtual device numbers.")
1644 (defun tramp-default-file-modes (filename)
1645 "Return file modes of FILENAME as integer.
1646 If the file modes of FILENAME cannot be determined, return the
1647 value of `default-file-modes', without execute permissions."
1648 (or (file-modes filename
)
1649 (logand (default-file-modes) (tramp-compat-octal-to-decimal "0666"))))
1651 (defun tramp-replace-environment-variables (filename)
1652 "Replace environment variables in FILENAME.
1653 Return the string with the replaced variables."
1655 (let ((idx (string-match "$\\(\\w+\\)" filename
)))
1656 ;; `$' is coded as `$$'.
1658 (or (zerop idx
) (not (eq ?$
(aref filename
(1- idx
)))))
1659 (getenv (match-string 1 filename
)))
1662 (substitute-in-file-name (match-string 0 filename
))
1666 ;; In XEmacs, electricity is implemented via a key map for ?/ and ?~,
1667 ;; which calls corresponding functions (see minibuf.el).
1668 (when (fboundp 'minibuffer-electric-separator
)
1673 (around ,(intern (format "tramp-advice-%s" x
)) activate
)
1674 "Invoke `substitute-in-file-name' for Tramp files."
1675 (if (and (symbol-value 'minibuffer-electric-file-name-behavior
)
1676 (tramp-tramp-file-p (buffer-substring)))
1677 ;; We don't need to handle `last-input-event', because
1678 ;; due to the key map we know it must be ?/ or ?~.
1679 (let ((s (concat (buffer-substring (point-min) (point))
1680 (string last-command-char
))))
1681 (delete-region (point-min) (point))
1682 (insert (substitute-in-file-name s
))
1683 (setq ad-return-value last-command-char
))
1689 (ad-remove-advice ',x
'around
',(intern (format "tramp-advice-%s" x
)))
1690 (ad-activate ',x
)))))
1692 '(minibuffer-electric-separator
1693 minibuffer-electric-tilde
)))
1695 (defun tramp-find-file-name-coding-system-alist (filename tmpname
)
1696 "Like `find-operation-coding-system' for Tramp filenames.
1697 Tramp's `insert-file-contents' and `write-region' work over
1698 temporary file names. If `file-coding-system-alist' contains an
1699 expression, which matches more than the file name suffix, the
1700 coding system might not be determined. This function repairs it."
1702 (dolist (elt file-coding-system-alist result
)
1703 (when (and (consp elt
) (string-match (car elt
) filename
))
1704 ;; We found a matching entry in `file-coding-system-alist'.
1705 ;; So we add a similar entry, but with the temporary file name
1708 'result
(cons (regexp-quote tmpname
) (cdr elt
)) 'append
)))))
1711 (progn (defun tramp-run-real-handler (operation args
)
1712 "Invoke normal file name handler for OPERATION.
1713 First arg specifies the OPERATION, second arg is a list of arguments to
1714 pass to the OPERATION."
1715 (let* ((inhibit-file-name-handlers
1716 `(tramp-file-name-handler
1717 tramp-vc-file-name-handler
1718 tramp-completion-file-name-handler
1719 cygwin-mount-name-hook-function
1720 cygwin-mount-map-drive-hook-function
1722 ,(and (eq inhibit-file-name-operation operation
)
1723 inhibit-file-name-handlers
)))
1724 (inhibit-file-name-operation operation
))
1725 (apply operation args
))))
1728 (progn (defun tramp-completion-run-real-handler (operation args
)
1729 "Invoke `tramp-file-name-handler' for OPERATION.
1730 First arg specifies the OPERATION, second arg is a list of arguments to
1731 pass to the OPERATION."
1732 (let* ((inhibit-file-name-handlers
1733 `(tramp-completion-file-name-handler
1734 cygwin-mount-name-hook-function
1735 cygwin-mount-map-drive-hook-function
1737 ,(and (eq inhibit-file-name-operation operation
)
1738 inhibit-file-name-handlers
)))
1739 (inhibit-file-name-operation operation
))
1740 (apply operation args
))))
1742 ;; We handle here all file primitives. Most of them have the file
1743 ;; name as first parameter; nevertheless we check for them explicitly
1744 ;; in order to be signaled if a new primitive appears. This
1745 ;; scenario is needed because there isn't a way to decide by
1746 ;; syntactical means whether a foreign method must be called. It would
1747 ;; ease the life if `file-name-handler-alist' would support a decision
1748 ;; function as well but regexp only.
1749 (defun tramp-file-name-for-operation (operation &rest args
)
1750 "Return file name related to OPERATION file primitive.
1751 ARGS are the arguments OPERATION has been called with."
1753 ;; FILE resp DIRECTORY.
1755 (list 'access-file
'byte-compiler-base-file-name
'delete-directory
1756 'delete-file
'diff-latest-backup-file
'directory-file-name
1757 'directory-files
'directory-files-and-attributes
1758 'dired-compress-file
'dired-uncache
1759 'file-accessible-directory-p
'file-attributes
1760 'file-directory-p
'file-executable-p
'file-exists-p
1761 'file-local-copy
'file-remote-p
'file-modes
1762 'file-name-as-directory
'file-name-directory
1763 'file-name-nondirectory
'file-name-sans-versions
1764 'file-ownership-preserved-p
'file-readable-p
1765 'file-regular-p
'file-symlink-p
'file-truename
1766 'file-writable-p
'find-backup-file-name
'find-file-noselect
1767 'get-file-buffer
'insert-directory
'insert-file-contents
1768 'load
'make-directory
'make-directory-internal
1769 'set-file-modes
'substitute-in-file-name
1770 'unhandled-file-name-directory
'vc-registered
1774 'file-selinux-context
'set-file-selinux-context
1776 'abbreviate-file-name
'create-file-buffer
1777 'dired-file-modtime
'dired-make-compressed-filename
1778 'dired-recursive-delete-directory
'dired-set-file-modtime
1779 'dired-shell-unhandle-file-name
'dired-uucode-file
1780 'insert-file-contents-literally
'make-temp-name
'recover-file
1781 'vm-imap-check-mail
'vm-pop-check-mail
'vm-spool-check-mail
))
1782 (if (file-name-absolute-p (nth 0 args
))
1784 (expand-file-name (nth 0 args
))))
1785 ;; FILE DIRECTORY resp FILE1 FILE2.
1787 (list 'add-name-to-file
'copy-file
'expand-file-name
1788 'file-name-all-completions
'file-name-completion
1789 'file-newer-than-file-p
'make-symbolic-link
'rename-file
1793 'dired-make-relative-symlink
1794 'vm-imap-move-mail
'vm-pop-move-mail
'vm-spool-move-mail
))
1797 ((string-match tramp-file-name-regexp
(nth 0 args
)) (nth 0 args
))
1798 ((string-match tramp-file-name-regexp
(nth 1 args
)) (nth 1 args
))
1799 (t (buffer-file-name (current-buffer))))))
1801 ((eq operation
'write-region
)
1805 (list 'set-visited-file-modtime
'verify-visited-file-modtime
1807 'make-auto-save-file-name
1811 (if (bufferp (nth 0 args
)) (nth 0 args
) (current-buffer))))
1814 (list ;; not in Emacs 23+.
1823 'dired-print-file
'dired-shell-call-process
1825 'executable-find
'start-process
1826 'call-process
'call-process-region
))
1828 ;; Unknown file primitive.
1829 (t (error "unknown file I/O primitive: %s" operation
))))
1831 (defun tramp-find-foreign-file-name-handler (filename)
1832 "Return foreign file name handler if exists."
1833 (when (tramp-tramp-file-p filename
)
1834 (let ((v (tramp-dissect-file-name filename t
))
1835 (handler tramp-foreign-file-name-handler-alist
)
1837 ;; When we are not fully sure that filename completion is safe,
1838 ;; we should not return a handler.
1839 (when (or (tramp-file-name-method v
) (tramp-file-name-user v
)
1840 (and (tramp-file-name-host v
)
1841 (not (member (tramp-file-name-host v
)
1842 (mapcar 'car tramp-methods
))))
1843 (not (tramp-completion-mode-p)))
1845 (setq elt
(car handler
)
1846 handler
(cdr handler
))
1847 (when (funcall (car elt
) filename
)
1854 (defun tramp-file-name-handler (operation &rest args
)
1855 "Invoke Tramp file name handler.
1856 Falls back to normal file name handler if no Tramp file name handler exists."
1860 (tramp-replace-environment-variables
1861 (apply 'tramp-file-name-for-operation operation args
)))
1862 (completion (tramp-completion-mode-p))
1863 (foreign (tramp-find-foreign-file-name-handler filename
)))
1864 (with-parsed-tramp-file-name filename nil
1865 ;; Call the backend function.
1868 (apply foreign operation args
)
1870 ;; Trace that somebody has interrupted the operation.
1872 (let (tramp-message-show-message)
1874 v
1 "Interrupt received in operation %s"
1875 (append (list operation
) args
)))
1876 ;; Propagate the quit signal.
1877 (signal (car err
) (cdr err
)))
1879 ;; When we are in completion mode, some failed
1880 ;; operations shall return at least a default value
1881 ;; in order to give the user a chance to correct the
1882 ;; file name in the minibuffer.
1885 ((and completion
(zerop (length localname
))
1886 (memq operation
'(file-exists-p file-directory-p
)))
1888 ((and completion
(zerop (length localname
))
1890 '(expand-file-name file-name-as-directory
)))
1892 ;; Propagate the error.
1893 (t (signal (car err
) (cdr err
))))))
1895 ;; Nothing to do for us.
1896 (tramp-run-real-handler operation args
)))))
1898 ;; When `tramp-mode' is not enabled, we don't do anything.
1899 (tramp-run-real-handler operation args
)))
1901 ;; In Emacs, there is some concurrency due to timers. If a timer
1902 ;; interrupts Tramp and wishes to use the same connection buffer as
1903 ;; the "main" Emacs, then garbage might occur in the connection
1904 ;; buffer. Therefore, we need to make sure that a timer does not use
1905 ;; the same connection buffer as the "main" Emacs. We implement a
1906 ;; cheap global lock, instead of locking each connection buffer
1907 ;; separately. The global lock is based on two variables,
1908 ;; `tramp-locked' and `tramp-locker'. `tramp-locked' is set to true
1909 ;; (with setq) to indicate a lock. But Tramp also calls itself during
1910 ;; processing of a single file operation, so we need to allow
1911 ;; recursive calls. That's where the `tramp-locker' variable comes in
1912 ;; -- it is let-bound to t during the execution of the current
1913 ;; handler. So if `tramp-locked' is t and `tramp-locker' is also t,
1914 ;; then we should just proceed because we have been called
1915 ;; recursively. But if `tramp-locker' is nil, then we are a timer
1916 ;; interrupting the "main" Emacs, and then we signal an error.
1918 (defvar tramp-locked nil
1919 "If non-nil, then Tramp is currently busy.
1920 Together with `tramp-locker', this implements a locking mechanism
1921 preventing reentrant calls of Tramp.")
1923 (defvar tramp-locker nil
1924 "If non-nil, then a caller has locked Tramp.
1925 Together with `tramp-locked', this implements a locking mechanism
1926 preventing reentrant calls of Tramp.")
1929 (progn (defun tramp-completion-file-name-handler (operation &rest args
)
1930 "Invoke Tramp file name completion handler.
1931 Falls back to normal file name handler if no Tramp file name handler exists."
1932 ;; We bind `directory-sep-char' here for XEmacs on Windows, which
1933 ;; would otherwise use backslash.
1934 (let ((directory-sep-char ?
/)
1935 (fn (assoc operation tramp-completion-file-name-handler-alist
)))
1937 ;; When `tramp-mode' is not enabled, we don't do anything.
1939 ;; For other syntaxes than `sep', the regexp matches many common
1940 ;; situations where the user doesn't actually want to use Tramp.
1941 ;; So to avoid autoloading Tramp after typing just "/s", we
1942 ;; disable this part of the completion, unless the user implicitly
1943 ;; indicated his interest in using a fancier completion system.
1944 (or (eq tramp-syntax
'sep
)
1945 (featurep 'tramp
) ;; If it's loaded, we may as well use it.
1946 ;; `partial-completion-mode' does not exist in XEmacs.
1947 ;; It is obsoleted with Emacs 24.1.
1948 (and (boundp 'partial-completion-mode
)
1949 (symbol-value 'partial-completion-mode
))
1950 ;; FIXME: These may have been loaded even if the user never
1951 ;; intended to use them.
1953 (featurep 'icicles
)))
1954 (save-match-data (apply (cdr fn
) args
))
1955 (tramp-completion-run-real-handler operation args
)))))
1958 (progn (defun tramp-register-file-name-handlers ()
1959 "Add Tramp file name handlers to `file-name-handler-alist'."
1960 ;; Remove autoloaded handlers from file name handler alist. Useful,
1961 ;; if `tramp-syntax' has been changed.
1962 (let ((a1 (rassq 'tramp-file-name-handler file-name-handler-alist
)))
1963 (setq file-name-handler-alist
(delq a1 file-name-handler-alist
)))
1965 'tramp-completion-file-name-handler file-name-handler-alist
)))
1966 (setq file-name-handler-alist
(delq a1 file-name-handler-alist
)))
1967 ;; Add the handlers.
1968 (add-to-list 'file-name-handler-alist
1969 (cons tramp-file-name-regexp
'tramp-file-name-handler
))
1970 (put 'tramp-file-name-handler
'safe-magic t
)
1971 (add-to-list 'file-name-handler-alist
1972 (cons tramp-completion-file-name-regexp
1973 'tramp-completion-file-name-handler
))
1974 (put 'tramp-completion-file-name-handler
'safe-magic t
)
1975 ;; If jka-compr or epa-file are already loaded, move them to the
1976 ;; front of `file-name-handler-alist'.
1977 (dolist (fnh '(epa-file-handler jka-compr-handler
))
1978 (let ((entry (rassoc fnh file-name-handler-alist
)))
1980 (setq file-name-handler-alist
1981 (cons entry
(delete entry file-name-handler-alist
))))))))
1983 ;; `tramp-file-name-handler' must be registered before evaluation of
1984 ;; site-start and init files, because there might exist remote files
1985 ;; already, f.e. files kept via recentf-mode.
1987 (tramp-register-file-name-handlers)
1989 (defun tramp-exists-file-name-handler (operation &rest args
)
1990 "Check, whether OPERATION runs a file name handler."
1991 ;; The file name handler is determined on base of either an
1992 ;; argument, `buffer-file-name', or `default-directory'.
1994 (let* ((buffer-file-name "/")
1995 (default-directory "/")
1996 (fnha file-name-handler-alist
)
1997 (check-file-name-operation operation
)
1998 (file-name-handler-alist
2001 (lambda (operation &rest args
)
2002 "Returns OPERATION if it is the one to be checked."
2003 (if (equal check-file-name-operation operation
)
2005 (let ((file-name-handler-alist fnha
))
2006 (apply operation args
))))))))
2007 (equal (apply operation args
) operation
))))
2010 (defun tramp-unload-file-name-handlers ()
2011 (setq file-name-handler-alist
2012 (delete (rassoc 'tramp-file-name-handler
2013 file-name-handler-alist
)
2014 (delete (rassoc 'tramp-completion-file-name-handler
2015 file-name-handler-alist
)
2016 file-name-handler-alist
))))
2018 (add-hook 'tramp-unload-hook
'tramp-unload-file-name-handlers
)
2020 ;;; File name handler functions for completion mode:
2022 (defvar tramp-completion-mode nil
2023 "If non-nil, external packages signal that they are in file name completion.
2025 This is necessary, because Tramp uses a heuristic depending on last
2026 input event. This fails when external packages use other characters
2027 but <TAB>, <SPACE> or ?\\? for file name completion. This variable
2028 should never be set globally, the intention is to let-bind it.")
2030 ;; Necessary because `tramp-file-name-regexp-unified' and
2031 ;; `tramp-completion-file-name-regexp-unified' aren't different. If
2032 ;; nil, `tramp-completion-run-real-handler' is called (i.e. forwarding
2033 ;; to `tramp-file-name-handler'). Otherwise, it takes
2034 ;; `tramp-run-real-handler'. Using `last-input-event' is a little bit
2035 ;; risky, because completing a file might require loading other files,
2036 ;; like "~/.netrc", and for them it shouldn't be decided based on that
2037 ;; variable. On the other hand, those files shouldn't have partial
2038 ;; Tramp file name syntax. Maybe another variable should be introduced
2039 ;; overwriting this check in such cases. Or we change Tramp file name
2040 ;; syntax in order to avoid ambiguities, like in XEmacs ...
2041 ;;;###tramp-autoload
2042 (defun tramp-completion-mode-p ()
2043 "Check, whether method / user name / host name completion is active."
2045 ;; Signal from outside. `non-essential' has been introduced in Emacs 24.
2046 (and (boundp 'non-essential
) (symbol-value 'non-essential
))
2047 tramp-completion-mode
2049 (equal last-input-event
'tab
)
2050 (and (natnump last-input-event
)
2052 ;; ?\t has event-modifier 'control.
2053 (equal last-input-event ?
\t)
2054 (and (not (event-modifiers last-input-event
))
2055 (or (equal last-input-event ?
\?)
2056 (equal last-input-event ?\
)))))
2058 (and (featurep 'xemacs
)
2059 ;; `last-input-event' might be nil.
2060 (not (null last-input-event
))
2061 ;; `last-input-event' may have no character approximation.
2062 (tramp-compat-funcall 'event-to-character last-input-event
)
2064 ;; ?\t has event-modifier 'control.
2066 (tramp-compat-funcall 'event-to-character last-input-event
) ?
\t)
2067 (and (not (event-modifiers last-input-event
))
2069 (tramp-compat-funcall 'event-to-character last-input-event
)
2072 (tramp-compat-funcall 'event-to-character last-input-event
)
2075 (defun tramp-connectable-p (filename)
2076 "Check, whether it is possible to connect the remote host w/o side-effects.
2077 This is true, if either the remote host is already connected, or if we are
2078 not in completion mode."
2079 (and (tramp-tramp-file-p filename
)
2080 (with-parsed-tramp-file-name filename nil
2081 (or (get-buffer (tramp-buffer-name v
))
2082 (not (tramp-completion-mode-p))))))
2084 ;; Method, host name and user name completion.
2085 ;; `tramp-completion-dissect-file-name' returns a list of
2086 ;; tramp-file-name structures. For all of them we return possible completions.
2088 (defun tramp-completion-handle-file-name-all-completions (filename directory
)
2089 "Like `file-name-all-completions' for partial Tramp files."
2091 (let* ((fullname (tramp-drop-volume-letter
2092 (expand-file-name filename directory
)))
2093 ;; Possible completion structures.
2094 (v (tramp-completion-dissect-file-name fullname
))
2098 (let* ((car (car v
))
2099 (method (tramp-file-name-method car
))
2100 (user (tramp-file-name-user car
))
2101 (host (tramp-file-name-host car
))
2102 (localname (tramp-file-name-localname car
))
2103 (m (tramp-find-method method user host
))
2104 (tramp-current-user user
) ; see `tramp-parse-passwd'
2107 (unless localname
;; Nothing to complete.
2111 ;; Method dependent user / host combinations.
2115 (setq all-user-hosts
2116 (append all-user-hosts
2117 (funcall (nth 0 x
) (nth 1 x
)))))
2118 (tramp-get-completion-function m
))
2124 (tramp-get-completion-user-host
2125 method user host
(nth 0 x
) (nth 1 x
)))
2126 (delq nil all-user-hosts
)))))
2128 ;; Possible methods.
2130 (append result
(tramp-get-completion-methods m
)))))
2134 ;; Unify list, remove nil elements.
2136 (let ((car (car result
)))
2140 (substring car
(length (tramp-drop-volume-letter directory
)))))
2141 (setq result
(cdr result
))))
2143 ;; Complete local parts.
2147 (apply (if (tramp-connectable-p fullname
)
2148 'tramp-completion-run-real-handler
2149 'tramp-run-real-handler
)
2150 'file-name-all-completions
(list (list filename directory
)))))))
2152 ;; Method, host name and user name completion for a file.
2154 (defun tramp-completion-handle-file-name-completion
2155 (filename directory
&optional predicate
)
2156 "Like `file-name-completion' for Tramp files."
2159 (mapcar 'list
(file-name-all-completions filename directory
))
2160 (when (and predicate
2161 (tramp-connectable-p (expand-file-name filename directory
)))
2162 (lambda (x) (funcall predicate
(expand-file-name (car x
) directory
))))))
2164 ;; I misuse a little bit the tramp-file-name structure in order to handle
2165 ;; completion possibilities for partial methods / user names / host names.
2166 ;; Return value is a list of tramp-file-name structures according to possible
2167 ;; completions. If "localname" is non-nil it means there
2168 ;; shouldn't be a completion anymore.
2170 ;; Expected results:
2172 ;; "/x" "/[x" "/x@" "/[x@" "/x@y" "/[x@y"
2173 ;; [nil nil "x" nil] [nil "x" nil nil] [nil "x" "y" nil]
2174 ;; [nil "x" nil nil]
2175 ;; ["x" nil nil nil]
2177 ;; "/x:" "/x:y" "/x:y:"
2178 ;; [nil nil "x" ""] [nil nil "x" "y"] ["x" nil "y" ""]
2180 ;; ["x" nil "" nil] ["x" nil "y" nil]
2181 ;; ["x" "" nil nil] ["x" "y" nil nil]
2183 ;; "/x:y@" "/x:y@z" "/x:y@z:"
2184 ;; [nil nil "x" "y@"] [nil nil "x" "y@z"] ["x" "y" "z" ""]
2185 ;; "/[x/y@" "/[x/y@z"
2186 ;; ["x" nil "y" nil] ["x" "y" "z" nil]
2187 (defun tramp-completion-dissect-file-name (name)
2188 "Returns a list of `tramp-file-name' structures.
2189 They are collected by `tramp-completion-dissect-file-name1'."
2193 (tramp-completion-ipv6-regexp
2196 (if (zerop (length tramp-postfix-ipv6-format
))
2197 tramp-postfix-host-format
2198 tramp-postfix-ipv6-format
)))
2199 ;; "/method" "/[method"
2200 (tramp-completion-file-name-structure1
2201 (list (concat tramp-prefix-regexp
"\\(" tramp-method-regexp x-nil
"\\)$")
2204 (tramp-completion-file-name-structure2
2205 (list (concat tramp-prefix-regexp
"\\(" tramp-user-regexp x-nil
"\\)$")
2208 (tramp-completion-file-name-structure3
2209 (list (concat tramp-prefix-regexp
"\\(" tramp-host-regexp x-nil
"\\)$")
2211 ;; "/[ipv6" "/[ipv6"
2212 (tramp-completion-file-name-structure4
2213 (list (concat tramp-prefix-regexp
2214 tramp-prefix-ipv6-regexp
2215 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2217 ;; "/user@host" "/[user@host"
2218 (tramp-completion-file-name-structure5
2219 (list (concat tramp-prefix-regexp
2220 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2221 "\\(" tramp-host-regexp x-nil
"\\)$")
2223 ;; "/user@[ipv6" "/[user@ipv6"
2224 (tramp-completion-file-name-structure6
2225 (list (concat tramp-prefix-regexp
2226 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2227 tramp-prefix-ipv6-regexp
2228 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2230 ;; "/method:user" "/[method/user" "/method://user"
2231 (tramp-completion-file-name-structure7
2232 (list (concat tramp-prefix-regexp
2233 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2234 "\\(" tramp-user-regexp x-nil
"\\)$")
2236 ;; "/method:host" "/[method/host" "/method://host"
2237 (tramp-completion-file-name-structure8
2238 (list (concat tramp-prefix-regexp
2239 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2240 "\\(" tramp-host-regexp x-nil
"\\)$")
2242 ;; "/method:[ipv6" "/[method/ipv6" "/method://[ipv6"
2243 (tramp-completion-file-name-structure9
2244 (list (concat tramp-prefix-regexp
2245 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2246 tramp-prefix-ipv6-regexp
2247 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2249 ;; "/method:user@host" "/[method/user@host" "/method://user@host"
2250 (tramp-completion-file-name-structure10
2251 (list (concat tramp-prefix-regexp
2252 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2253 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2254 "\\(" tramp-host-regexp x-nil
"\\)$")
2256 ;; "/method:user@[ipv6" "/[method/user@ipv6" "/method://user@[ipv6"
2257 (tramp-completion-file-name-structure11
2258 (list (concat tramp-prefix-regexp
2259 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2260 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2261 tramp-prefix-ipv6-regexp
2262 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2264 ;; "/method: "/method:/"
2265 (tramp-completion-file-name-structure12
2267 (if (equal tramp-syntax
'url
)
2268 (concat tramp-prefix-regexp
2269 "\\(" tramp-method-regexp
"\\)"
2270 "\\(" (substring tramp-postfix-method-regexp
0 1)
2271 "\\|" (substring tramp-postfix-method-regexp
1 2) "\\)"
2273 ;; Should not match if not URL syntax.
2274 (concat tramp-prefix-regexp
"/$"))
2276 ;; "/method: "/method:/"
2277 (tramp-completion-file-name-structure13
2279 (if (equal tramp-syntax
'url
)
2280 (concat tramp-prefix-regexp
2281 "\\(" tramp-method-regexp
"\\)"
2282 "\\(" (substring tramp-postfix-method-regexp
0 1)
2283 "\\|" (substring tramp-postfix-method-regexp
1 2) "\\)"
2285 ;; Should not match if not URL syntax.
2286 (concat tramp-prefix-regexp
"/$"))
2289 (mapc (lambda (regexp)
2290 (add-to-list 'result
2291 (tramp-completion-dissect-file-name1 regexp name
)))
2293 tramp-completion-file-name-structure1
2294 tramp-completion-file-name-structure2
2295 tramp-completion-file-name-structure3
2296 tramp-completion-file-name-structure4
2297 tramp-completion-file-name-structure5
2298 tramp-completion-file-name-structure6
2299 tramp-completion-file-name-structure7
2300 tramp-completion-file-name-structure8
2301 tramp-completion-file-name-structure9
2302 tramp-completion-file-name-structure10
2303 tramp-completion-file-name-structure11
2304 tramp-completion-file-name-structure12
2305 tramp-completion-file-name-structure13
2306 tramp-file-name-structure
))
2310 (defun tramp-completion-dissect-file-name1 (structure name
)
2311 "Returns a `tramp-file-name' structure matching STRUCTURE.
2312 The structure consists of remote method, remote user,
2313 remote host and localname (filename on remote host)."
2316 (when (string-match (nth 0 structure
) name
)
2317 (let ((method (and (nth 1 structure
)
2318 (match-string (nth 1 structure
) name
)))
2319 (user (and (nth 2 structure
)
2320 (match-string (nth 2 structure
) name
)))
2321 (host (and (nth 3 structure
)
2322 (match-string (nth 3 structure
) name
)))
2323 (localname (and (nth 4 structure
)
2324 (match-string (nth 4 structure
) name
))))
2325 (vector method user host localname
)))))
2327 ;; This function returns all possible method completions, adding the
2328 ;; trailing method delimiter.
2329 (defun tramp-get-completion-methods (partial-method)
2330 "Returns all method completions for PARTIAL-METHOD."
2334 (string-match (concat "^" (regexp-quote partial-method
)) method
)
2335 (tramp-completion-make-tramp-file-name method nil nil nil
)))
2336 (mapcar 'car tramp-methods
)))
2338 ;; Compares partial user and host names with possible completions.
2339 (defun tramp-get-completion-user-host (method partial-user partial-host user host
)
2340 "Returns the most expanded string for user and host name completion.
2341 PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
2344 ((and partial-user partial-host
)
2346 (string-match (concat "^" (regexp-quote partial-host
)) host
)
2347 (string-equal partial-user
(or user partial-user
)))
2348 (setq user partial-user
)
2355 (and user
(string-match (concat "^" (regexp-quote partial-user
)) user
))
2361 (and host
(string-match (concat "^" (regexp-quote partial-host
)) host
))
2367 (unless (zerop (+ (length user
) (length host
)))
2368 (tramp-completion-make-tramp-file-name method user host nil
)))
2370 (defun tramp-parse-rhosts (filename)
2371 "Return a list of (user host) tuples allowed to access.
2372 Either user or host may be nil."
2373 ;; On Windows, there are problems in completion when
2374 ;; `default-directory' is remote.
2375 (let ((default-directory (tramp-compat-temporary-file-directory))
2377 (when (file-readable-p filename
)
2379 (insert-file-contents filename
)
2380 (goto-char (point-min))
2382 (push (tramp-parse-rhosts-group) res
))))
2385 (defun tramp-parse-rhosts-group ()
2386 "Return a (user host) tuple allowed to access.
2387 Either user or host may be nil."
2391 "^\\(" tramp-host-regexp
"\\)"
2392 "\\([ \t]+" "\\(" tramp-user-regexp
"\\)" "\\)?")))
2393 (narrow-to-region (point) (point-at-eol))
2394 (when (re-search-forward regexp nil t
)
2395 (setq result
(append (list (match-string 3) (match-string 1)))))
2400 (defun tramp-parse-shosts (filename)
2401 "Return a list of (user host) tuples allowed to access.
2402 User is always nil."
2403 ;; On Windows, there are problems in completion when
2404 ;; `default-directory' is remote.
2405 (let ((default-directory (tramp-compat-temporary-file-directory))
2407 (when (file-readable-p filename
)
2409 (insert-file-contents filename
)
2410 (goto-char (point-min))
2412 (push (tramp-parse-shosts-group) res
))))
2415 (defun tramp-parse-shosts-group ()
2416 "Return a (user host) tuple allowed to access.
2417 User is always nil."
2419 (regexp (concat "^\\(" tramp-host-regexp
"\\)")))
2420 (narrow-to-region (point) (point-at-eol))
2421 (when (re-search-forward regexp nil t
)
2422 (setq result
(list nil
(match-string 1))))
2425 (> (skip-chars-forward ",") 0)
2429 (defun tramp-parse-sconfig (filename)
2430 "Return a list of (user host) tuples allowed to access.
2431 User is always nil."
2432 ;; On Windows, there are problems in completion when
2433 ;; `default-directory' is remote.
2434 (let ((default-directory (tramp-compat-temporary-file-directory))
2436 (when (file-readable-p filename
)
2438 (insert-file-contents filename
)
2439 (goto-char (point-min))
2441 (push (tramp-parse-sconfig-group) res
))))
2444 (defun tramp-parse-sconfig-group ()
2445 "Return a (user host) tuple allowed to access.
2446 User is always nil."
2448 (regexp (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp
"\\)")))
2449 (narrow-to-region (point) (point-at-eol))
2450 (when (re-search-forward regexp nil t
)
2451 (setq result
(list nil
(match-string 1))))
2454 (> (skip-chars-forward ",") 0)
2458 (defun tramp-parse-shostkeys (dirname)
2459 "Return a list of (user host) tuples allowed to access.
2460 User is always nil."
2461 ;; On Windows, there are problems in completion when
2462 ;; `default-directory' is remote.
2463 (let* ((default-directory (tramp-compat-temporary-file-directory))
2464 (regexp (concat "^key_[0-9]+_\\(" tramp-host-regexp
"\\)\\.pub$"))
2465 (files (when (file-directory-p dirname
) (directory-files dirname
)))
2468 (when (string-match regexp
(car files
))
2469 (push (list nil
(match-string 1 (car files
))) result
))
2470 (setq files
(cdr files
)))
2473 (defun tramp-parse-sknownhosts (dirname)
2474 "Return a list of (user host) tuples allowed to access.
2475 User is always nil."
2476 ;; On Windows, there are problems in completion when
2477 ;; `default-directory' is remote.
2478 (let* ((default-directory (tramp-compat-temporary-file-directory))
2479 (regexp (concat "^\\(" tramp-host-regexp
2480 "\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$"))
2481 (files (when (file-directory-p dirname
) (directory-files dirname
)))
2484 (when (string-match regexp
(car files
))
2485 (push (list nil
(match-string 1 (car files
))) result
))
2486 (setq files
(cdr files
)))
2489 (defun tramp-parse-hosts (filename)
2490 "Return a list of (user host) tuples allowed to access.
2491 User is always nil."
2492 ;; On Windows, there are problems in completion when
2493 ;; `default-directory' is remote.
2494 (let ((default-directory (tramp-compat-temporary-file-directory))
2496 (when (file-readable-p filename
)
2498 (insert-file-contents filename
)
2499 (goto-char (point-min))
2501 (push (tramp-parse-hosts-group) res
))))
2504 (defun tramp-parse-hosts-group ()
2505 "Return a (user host) tuple allowed to access.
2506 User is always nil."
2509 (concat "^\\(" tramp-ipv6-regexp
"\\|" tramp-host-regexp
"\\)")))
2510 (narrow-to-region (point) (point-at-eol))
2511 (when (re-search-forward regexp nil t
)
2512 (setq result
(list nil
(match-string 1))))
2515 (> (skip-chars-forward " \t") 0)
2519 ;; For su-alike methods it would be desirable to return "root@localhost"
2520 ;; as default. Unfortunately, we have no information whether any user name
2521 ;; has been typed already. So we use `tramp-current-user' as indication,
2522 ;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
2523 (defun tramp-parse-passwd (filename)
2524 "Return a list of (user host) tuples allowed to access.
2525 Host is always \"localhost\"."
2526 ;; On Windows, there are problems in completion when
2527 ;; `default-directory' is remote.
2528 (let ((default-directory (tramp-compat-temporary-file-directory))
2530 (if (zerop (length tramp-current-user
))
2532 (when (file-readable-p filename
)
2534 (insert-file-contents filename
)
2535 (goto-char (point-min))
2537 (push (tramp-parse-passwd-group) res
))))
2540 (defun tramp-parse-passwd-group ()
2541 "Return a (user host) tuple allowed to access.
2542 Host is always \"localhost\"."
2544 (regexp (concat "^\\(" tramp-user-regexp
"\\):")))
2545 (narrow-to-region (point) (point-at-eol))
2546 (when (re-search-forward regexp nil t
)
2547 (setq result
(list (match-string 1) "localhost")))
2552 (defun tramp-parse-netrc (filename)
2553 "Return a list of (user host) tuples allowed to access.
2555 ;; On Windows, there are problems in completion when
2556 ;; `default-directory' is remote.
2557 (let ((default-directory (tramp-compat-temporary-file-directory))
2559 (when (file-readable-p filename
)
2561 (insert-file-contents filename
)
2562 (goto-char (point-min))
2564 (push (tramp-parse-netrc-group) res
))))
2567 (defun tramp-parse-netrc-group ()
2568 "Return a (user host) tuple allowed to access.
2573 "^[ \t]*machine[ \t]+" "\\(" tramp-host-regexp
"\\)"
2574 "\\([ \t]+login[ \t]+" "\\(" tramp-user-regexp
"\\)" "\\)?")))
2575 (narrow-to-region (point) (point-at-eol))
2576 (when (re-search-forward regexp nil t
)
2577 (setq result
(list (match-string 3) (match-string 1))))
2582 (defun tramp-parse-putty (registry)
2583 "Return a list of (user host) tuples allowed to access.
2584 User is always nil."
2585 ;; On Windows, there are problems in completion when
2586 ;; `default-directory' is remote.
2587 (let ((default-directory (tramp-compat-temporary-file-directory))
2590 (when (zerop (tramp-compat-call-process "reg" nil t nil
"query" registry
))
2591 (goto-char (point-min))
2593 (push (tramp-parse-putty-group registry
) res
))))
2596 (defun tramp-parse-putty-group (registry)
2597 "Return a (user host) tuple allowed to access.
2598 User is always nil."
2600 (regexp (concat (regexp-quote registry
) "\\\\\\(.+\\)")))
2601 (narrow-to-region (point) (point-at-eol))
2602 (when (re-search-forward regexp nil t
)
2603 (setq result
(list nil
(match-string 1))))
2608 ;;; Common file name handler functions for different backends:
2610 (defvar tramp-handle-file-local-copy-hook nil
2611 "Normal hook to be run at the end of `tramp-*-handle-file-local-copy'.")
2613 (defvar tramp-handle-write-region-hook nil
2614 "Normal hook to be run at the end of `tramp-*-handle-write-region'.")
2616 (defun tramp-handle-directory-file-name (directory)
2617 "Like `directory-file-name' for Tramp files."
2618 ;; If localname component of filename is "/", leave it unchanged.
2619 ;; Otherwise, remove any trailing slash from localname component.
2620 ;; Method, host, etc, are unchanged. Does it make sense to try
2621 ;; to avoid parsing the filename?
2622 (with-parsed-tramp-file-name directory nil
2623 (if (and (not (zerop (length localname
)))
2624 (eq (aref localname
(1- (length localname
))) ?
/)
2625 (not (string= localname
"/")))
2626 (substring directory
0 -
1)
2629 (defun tramp-handle-directory-files
2630 (directory &optional full match nosort files-only
)
2631 "Like `directory-files' for Tramp files."
2632 ;; FILES-ONLY is valid for XEmacs only.
2633 (when (file-directory-p directory
)
2634 (setq directory
(file-name-as-directory (expand-file-name directory
)))
2635 (let ((temp (nreverse (file-name-all-completions "" directory
)))
2639 (setq item
(directory-file-name (pop temp
)))
2640 (when (and (or (null match
) (string-match match item
))
2641 (or (null files-only
)
2643 (and (equal files-only t
) (file-regular-p item
))
2644 ;; Directories only.
2645 (file-directory-p item
)))
2646 (push (if full
(concat directory item
) item
)
2648 (if nosort result
(sort result
'string
<)))))
2650 (defun tramp-handle-directory-files-and-attributes
2651 (directory &optional full match nosort id-format
)
2652 "Like `directory-files-and-attributes' for Tramp files."
2655 (cons x
(tramp-compat-file-attributes
2656 (if full x
(expand-file-name x directory
)) id-format
)))
2657 (directory-files directory full match nosort
)))
2659 (defun tramp-handle-dired-uncache (dir &optional dir-p
)
2660 "Like `dired-uncache' for Tramp files."
2661 ;; DIR-P is valid for XEmacs only.
2662 (with-parsed-tramp-file-name
2663 (if (or dir-p
(file-directory-p dir
)) dir
(file-name-directory dir
)) nil
2664 (tramp-flush-directory-property v localname
)))
2666 (defun tramp-handle-file-exists-p (filename)
2667 "Like `file-exists-p' for Tramp files."
2668 (not (null (file-attributes filename
))))
2670 (defun tramp-handle-file-modes (filename)
2671 "Like `file-modes' for Tramp files."
2672 (let ((truename (or (file-truename filename
) filename
)))
2673 (when (file-exists-p truename
)
2674 (tramp-mode-string-to-int (nth 8 (file-attributes truename
))))))
2676 ;; Localname manipulation functions that grok Tramp localnames...
2677 (defun tramp-handle-file-name-as-directory (file)
2678 "Like `file-name-as-directory' but aware of Tramp files."
2679 ;; `file-name-as-directory' would be sufficient except localname is
2680 ;; the empty string.
2681 (let ((v (tramp-dissect-file-name file t
)))
2682 ;; Run the command on the localname portion only.
2683 (tramp-make-tramp-file-name
2684 (tramp-file-name-method v
)
2685 (tramp-file-name-user v
)
2686 (tramp-file-name-host v
)
2687 (tramp-run-real-handler
2688 'file-name-as-directory
(list (or (tramp-file-name-localname v
) ""))))))
2690 (defun tramp-handle-file-name-completion
2691 (filename directory
&optional predicate
)
2692 "Like `file-name-completion' for Tramp files."
2693 (unless (tramp-tramp-file-p directory
)
2695 "tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
2699 (mapcar 'list
(file-name-all-completions filename directory
))
2701 (lambda (x) (funcall predicate
(expand-file-name (car x
) directory
))))))
2703 (defun tramp-handle-file-name-directory (file)
2704 "Like `file-name-directory' but aware of Tramp files."
2705 ;; Everything except the last filename thing is the directory. We
2706 ;; cannot apply `with-parsed-tramp-file-name', because this expands
2707 ;; the remote file name parts. This is a problem when we are in
2708 ;; file name completion.
2709 (let ((v (tramp-dissect-file-name file t
)))
2710 ;; Run the command on the localname portion only.
2711 (tramp-make-tramp-file-name
2712 (tramp-file-name-method v
)
2713 (tramp-file-name-user v
)
2714 (tramp-file-name-host v
)
2715 (tramp-run-real-handler
2716 'file-name-directory
(list (or (tramp-file-name-localname v
) ""))))))
2718 (defun tramp-handle-file-name-nondirectory (file)
2719 "Like `file-name-nondirectory' but aware of Tramp files."
2720 (with-parsed-tramp-file-name file nil
2721 (tramp-run-real-handler 'file-name-nondirectory
(list localname
))))
2723 (defun tramp-handle-file-newer-than-file-p (file1 file2
)
2724 "Like `file-newer-than-file-p' for Tramp files."
2726 ((not (file-exists-p file1
)) nil
)
2727 ((not (file-exists-p file2
)) t
)
2728 (t (tramp-time-less-p (nth 5 (file-attributes file2
))
2729 (nth 5 (file-attributes file1
))))))
2731 (defun tramp-handle-file-regular-p (filename)
2732 "Like `file-regular-p' for Tramp files."
2733 (and (file-exists-p filename
)
2734 (eq ?-
(aref (nth 8 (file-attributes filename
)) 0))))
2736 (defun tramp-handle-file-remote-p (filename &optional identification connected
)
2737 "Like `file-remote-p' for Tramp files."
2738 (let ((tramp-verbose 3))
2739 (when (tramp-tramp-file-p filename
)
2740 (let* ((v (tramp-dissect-file-name filename
))
2741 (p (tramp-get-connection-process v
))
2742 (c (and p
(processp p
) (memq (process-status p
) '(run open
)))))
2743 ;; We expand the file name only, if there is already a connection.
2744 (with-parsed-tramp-file-name
2745 (if c
(expand-file-name filename
) filename
) nil
2746 (and (or (not connected
) c
)
2748 ((eq identification
'method
) method
)
2749 ((eq identification
'user
) user
)
2750 ((eq identification
'host
) host
)
2751 ((eq identification
'localname
) localname
)
2752 (t (tramp-make-tramp-file-name method user host
"")))))))))
2754 (defun tramp-handle-file-symlink-p (filename)
2755 "Like `file-symlink-p' for Tramp files."
2756 (with-parsed-tramp-file-name filename nil
2757 (let ((x (car (file-attributes filename
))))
2759 ;; When Tramp is running on VMS, then `file-name-absolute-p'
2760 ;; might do weird things.
2761 (if (file-name-absolute-p x
)
2762 (tramp-make-tramp-file-name method user host x
)
2765 (defun tramp-handle-find-backup-file-name (filename)
2766 "Like `find-backup-file-name' for Tramp files."
2767 (with-parsed-tramp-file-name filename nil
2768 ;; We set both variables. It doesn't matter whether it is
2770 (let ((backup-directory-alist
2772 (when (boundp 'backup-directory-alist
)
2773 (if (symbol-value 'tramp-backup-directory-alist
)
2778 (if (and (stringp (cdr x
))
2779 (file-name-absolute-p (cdr x
))
2780 (not (tramp-file-name-p (cdr x
))))
2781 (tramp-make-tramp-file-name method user host
(cdr x
))
2783 (symbol-value 'tramp-backup-directory-alist
))
2784 (symbol-value 'backup-directory-alist
))))
2786 (bkup-backup-directory-info
2788 (when (boundp 'bkup-backup-directory-info
)
2789 (if (symbol-value 'tramp-bkup-backup-directory-info
)
2795 (if (and (stringp (car (cdr x
)))
2796 (file-name-absolute-p (car (cdr x
)))
2797 (not (tramp-file-name-p (car (cdr x
)))))
2798 (tramp-make-tramp-file-name
2799 method user host
(car (cdr x
)))
2802 (symbol-value 'tramp-bkup-backup-directory-info
))
2803 (symbol-value 'bkup-backup-directory-info
)))))
2805 (tramp-run-real-handler 'find-backup-file-name
(list filename
)))))
2807 (defun tramp-handle-insert-file-contents
2808 (filename &optional visit beg end replace
)
2809 "Like `insert-file-contents' for Tramp files."
2810 (barf-if-buffer-read-only)
2811 (setq filename
(expand-file-name filename
))
2812 (let (result local-copy remote-copy
)
2813 (with-parsed-tramp-file-name filename nil
2815 (if (not (file-exists-p filename
))
2816 ;; We don't raise a Tramp error, because it might be
2817 ;; suppressed, like in `find-file-noselect-1'.
2819 (list "File not found on remote host" filename
))
2821 (if (and (tramp-local-host-p v
)
2822 (let (file-name-handler-alist)
2823 (file-readable-p localname
)))
2824 ;; Short track: if we are on the local host, we can
2827 (tramp-run-real-handler
2828 'insert-file-contents
2829 (list localname visit beg end replace
)))
2831 ;; When we shall insert only a part of the file, we copy
2834 (setq remote-copy
(tramp-make-tramp-temp-file v
))
2835 ;; This is defined in tramp-sh.el. Let's assume this
2836 ;; is loaded already.
2837 (tramp-compat-funcall 'tramp-send-command
2841 (format "tail -c +%d %s | head -c +%d >%s"
2842 (1+ beg
) (tramp-shell-quote-argument localname
)
2843 (- end beg
) remote-copy
))
2845 (format "tail -c +%d %s >%s"
2846 (1+ beg
) (tramp-shell-quote-argument localname
)
2849 (format "head -c +%d %s >%s"
2850 (1+ end
) (tramp-shell-quote-argument localname
)
2853 ;; `insert-file-contents-literally' takes care to avoid
2854 ;; calling jka-compr. By let-binding
2855 ;; `inhibit-file-name-operation', we propagate that care
2856 ;; to the `file-local-copy' operation.
2858 (let ((inhibit-file-name-operation
2859 (when (eq inhibit-file-name-operation
2860 'insert-file-contents
)
2863 ((stringp remote-copy
)
2865 (tramp-make-tramp-file-name
2866 method user host remote-copy
)))
2867 ((stringp tramp-temp-buffer-file-name
)
2868 (copy-file filename tramp-temp-buffer-file-name
'ok
)
2869 tramp-temp-buffer-file-name
)
2870 (t (file-local-copy filename
)))))
2872 ;; When the file is not readable for the owner, it
2873 ;; cannot be inserted, even if it is readable for the
2874 ;; group or for everybody.
2875 (set-file-modes local-copy
(tramp-compat-octal-to-decimal "0600"))
2877 (when (and (null remote-copy
)
2878 (tramp-get-method-parameter
2879 method
'tramp-copy-keep-tmpfile
))
2880 ;; We keep the local file for performance reasons,
2881 ;; useful for "rsync".
2882 (setq tramp-temp-buffer-file-name local-copy
))
2884 (with-progress-reporter
2885 v
3 (format "Inserting local temp file `%s'" local-copy
)
2886 ;; We must ensure that `file-coding-system-alist'
2887 ;; matches `local-copy'.
2888 (let ((file-coding-system-alist
2889 (tramp-find-file-name-coding-system-alist
2890 filename local-copy
)))
2892 (insert-file-contents
2893 local-copy nil nil nil replace
))))))
2898 (setq buffer-file-name filename
)
2899 (setq buffer-read-only
(not (file-writable-p filename
)))
2900 (set-visited-file-modtime)
2901 (set-buffer-modified-p nil
))
2902 (when (and (stringp local-copy
)
2903 (or remote-copy
(null tramp-temp-buffer-file-name
)))
2904 (delete-file local-copy
))
2905 (when (stringp remote-copy
)
2907 (tramp-make-tramp-file-name method user host remote-copy
))))))
2910 (list (expand-file-name filename
)
2913 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix
)
2914 "Like `load' for Tramp files."
2915 (with-parsed-tramp-file-name (expand-file-name file
) nil
2917 (cond ((file-exists-p (concat file
".elc"))
2918 (setq file
(concat file
".elc")))
2919 ((file-exists-p (concat file
".el"))
2920 (setq file
(concat file
".el")))))
2922 ;; The first condition is always true for absolute file names.
2923 ;; Included for safety's sake.
2924 (unless (or (file-name-directory file
)
2925 (string-match "\\.elc?\\'" file
))
2928 "File `%s' does not include a `.el' or `.elc' suffix" file
)))
2930 (when (not (file-exists-p file
))
2931 (tramp-error v
'file-error
"Cannot load nonexistent file `%s'" file
)))
2932 (if (not (file-exists-p file
))
2934 (let ((tramp-message-show-message (not nomessage
)))
2935 (with-progress-reporter v
0 (format "Loading %s" file
)
2936 (let ((local-copy (file-local-copy file
)))
2937 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
2939 (load local-copy noerror t t
)
2940 (delete-file local-copy
)))))
2943 (defun tramp-handle-substitute-in-file-name (filename)
2944 "Like `substitute-in-file-name' for Tramp files.
2945 \"//\" and \"/~\" substitute only in the local filename part.
2946 If the URL Tramp syntax is chosen, \"//\" as method delimiter and \"/~\" at
2947 beginning of local filename are not substituted."
2948 ;; First, we must replace environment variables.
2949 (setq filename
(tramp-replace-environment-variables filename
))
2950 (with-parsed-tramp-file-name filename nil
2951 (if (equal tramp-syntax
'url
)
2952 ;; We need to check localname only. The other parts cannot contain
2954 (if (and (> (length localname
) 1)
2955 (or (string-match "//" localname
)
2956 (string-match "/~" localname
1)))
2957 (tramp-run-real-handler 'substitute-in-file-name
(list filename
))
2958 (tramp-make-tramp-file-name
2959 (when method
(substitute-in-file-name method
))
2960 (when user
(substitute-in-file-name user
))
2961 (when host
(substitute-in-file-name host
))
2963 (tramp-run-real-handler
2964 'substitute-in-file-name
(list localname
)))))
2965 ;; Ignore in LOCALNAME everything before "//" or "/~".
2966 (when (and (stringp localname
) (string-match ".+?/\\(/\\|~\\)" localname
))
2968 (concat (file-remote-p filename
)
2969 (replace-match "\\1" nil nil localname
)))
2970 ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
2971 (when (string-match "~$" filename
)
2972 (setq filename
(concat filename
"/"))))
2973 (tramp-run-real-handler 'substitute-in-file-name
(list filename
)))))
2975 (defun tramp-handle-unhandled-file-name-directory (filename)
2976 "Like `unhandled-file-name-directory' for Tramp files."
2977 ;; With Emacs 23, we could simply return `nil'. But we must keep it
2978 ;; for backward compatibility.
2979 (expand-file-name "~/"))
2981 ;;; Functions for establishing connection:
2983 ;; The following functions are actions to be taken when seeing certain
2984 ;; prompts from the remote host. See the variable
2985 ;; `tramp-actions-before-shell' for usage of these functions.
2987 (defun tramp-action-login (proc vec
)
2988 "Send the login name."
2989 (when (not (stringp tramp-current-user
))
2990 (save-window-excursion
2991 (let ((enable-recursive-minibuffers t
))
2992 (pop-to-buffer (tramp-get-connection-buffer vec
))
2993 (setq tramp-current-user
(read-string (match-string 0))))))
2994 (tramp-message vec
3 "Sending login name `%s'" tramp-current-user
)
2995 (with-current-buffer (tramp-get-connection-buffer vec
)
2996 (tramp-message vec
6 "\n%s" (buffer-string)))
2997 (tramp-send-string vec tramp-current-user
))
2999 (defun tramp-action-password (proc vec
)
3000 "Query the user for a password."
3001 (with-current-buffer (process-buffer proc
)
3002 (tramp-check-for-regexp proc tramp-password-prompt-regexp
)
3003 (tramp-message vec
3 "Sending %s" (match-string 1))
3004 (tramp-enter-password proc
)
3005 ;; Hide password prompt.
3006 (narrow-to-region (point-max) (point-max))))
3008 (defun tramp-action-succeed (proc vec
)
3009 "Signal success in finding shell prompt."
3010 (throw 'tramp-action
'ok
))
3012 (defun tramp-action-permission-denied (proc vec
)
3013 "Signal permission denied."
3015 (throw 'tramp-action
'permission-denied
))
3017 (defun tramp-action-yesno (proc vec
)
3018 "Ask the user for confirmation using `yes-or-no-p'.
3019 Send \"yes\" to remote process on confirmation, abort otherwise.
3020 See also `tramp-action-yn'."
3021 (save-window-excursion
3022 (let ((enable-recursive-minibuffers t
))
3023 (save-match-data (pop-to-buffer (tramp-get-connection-buffer vec
)))
3024 (unless (yes-or-no-p (match-string 0))
3026 (throw 'tramp-action
'permission-denied
))
3027 (with-current-buffer (tramp-get-connection-buffer vec
)
3028 (tramp-message vec
6 "\n%s" (buffer-string)))
3029 (tramp-send-string vec
"yes"))))
3031 (defun tramp-action-yn (proc vec
)
3032 "Ask the user for confirmation using `y-or-n-p'.
3033 Send \"y\" to remote process on confirmation, abort otherwise.
3034 See also `tramp-action-yesno'."
3035 (save-window-excursion
3036 (let ((enable-recursive-minibuffers t
))
3037 (save-match-data (pop-to-buffer (tramp-get-connection-buffer vec
)))
3038 (unless (y-or-n-p (match-string 0))
3040 (throw 'tramp-action
'permission-denied
))
3041 (with-current-buffer (tramp-get-connection-buffer vec
)
3042 (tramp-message vec
6 "\n%s" (buffer-string)))
3043 (tramp-send-string vec
"y"))))
3045 (defun tramp-action-terminal (proc vec
)
3046 "Tell the remote host which terminal type to use.
3047 The terminal type can be configured with `tramp-terminal-type'."
3048 (tramp-message vec
5 "Setting `%s' as terminal type." tramp-terminal-type
)
3049 (with-current-buffer (tramp-get-connection-buffer vec
)
3050 (tramp-message vec
6 "\n%s" (buffer-string)))
3051 (tramp-send-string vec tramp-terminal-type
))
3053 (defun tramp-action-process-alive (proc vec
)
3054 "Check, whether a process has finished."
3055 (unless (memq (process-status proc
) '(run open
))
3056 (throw 'tramp-action
'process-died
)))
3058 (defun tramp-action-out-of-band (proc vec
)
3059 "Check, whether an out-of-band copy has finished."
3060 (cond ((and (memq (process-status proc
) '(stop exit
))
3061 (zerop (process-exit-status proc
)))
3062 (tramp-message vec
3 "Process has finished.")
3063 (throw 'tramp-action
'ok
))
3064 ((or (and (memq (process-status proc
) '(stop exit
))
3065 (not (zerop (process-exit-status proc
))))
3066 (memq (process-status proc
) '(signal)))
3067 ;; `scp' could have copied correctly, but set modes could have failed.
3068 ;; This can be ignored.
3069 (with-current-buffer (process-buffer proc
)
3070 (goto-char (point-min))
3071 (if (re-search-forward tramp-operation-not-permitted-regexp nil t
)
3073 (tramp-message vec
5 "'set mode' error ignored.")
3074 (tramp-message vec
3 "Process has finished.")
3075 (throw 'tramp-action
'ok
))
3076 (tramp-message vec
3 "Process has died.")
3077 (throw 'tramp-action
'process-died
))))
3080 ;;; Functions for processing the actions:
3082 (defun tramp-process-one-action (proc vec actions
)
3083 "Wait for output from the shell and perform one action."
3084 (let (found todo item pattern action
)
3086 ;; Reread output once all actions have been performed.
3087 ;; Obviously, the output was not complete.
3088 (tramp-accept-process-output proc
1)
3091 (setq item
(pop todo
))
3092 (setq pattern
(format "\\(%s\\)\\'" (symbol-value (nth 0 item
))))
3093 (setq action
(nth 1 item
))
3095 vec
5 "Looking for regexp \"%s\" from remote shell" pattern
)
3096 (when (tramp-check-for-regexp proc pattern
)
3097 (tramp-message vec
5 "Call `%s'" (symbol-name action
))
3098 (setq found
(funcall action proc vec
)))))
3101 (defun tramp-process-actions (proc vec pos actions
&optional timeout
)
3102 "Perform ACTIONS until success or TIMEOUT.
3103 PROC and VEC indicate the remote connection to be used. POS, if
3104 set, is the starting point of the region to be deleted in the
3106 ;; Preserve message for `progress-reporter'.
3107 (tramp-compat-with-temp-message ""
3108 ;; Enable auth-source and password-cache.
3109 (tramp-set-connection-property vec
"first-password-request" t
)
3113 (tramp-message proc
3 "Waiting for prompts from remote shell")
3115 (catch 'tramp-action
3117 (with-timeout (timeout)
3118 (tramp-process-one-action proc vec actions
))
3119 (tramp-process-one-action proc vec actions
)))))
3120 (with-current-buffer (tramp-get-connection-buffer vec
)
3122 (tramp-message vec
6 "\n%s" (buffer-string)))
3123 (unless (eq exit
'ok
)
3124 (tramp-clear-passwd vec
)
3125 (tramp-error-with-buffer
3128 ((eq exit
'permission-denied
) "Permission denied")
3129 ((eq exit
'process-died
) "Process died")
3130 (t "Login failed"))))
3132 (with-current-buffer (tramp-get-connection-buffer vec
)
3133 (let (buffer-read-only) (delete-region pos
(point)))))))))
3135 :;; Utility functions:
3137 (defun tramp-accept-process-output (&optional proc timeout timeout-msecs
)
3138 "Like `accept-process-output' for Tramp processes.
3139 This is needed in order to hide `last-coding-system-used', which is set
3140 for process communication also."
3141 (with-current-buffer (process-buffer proc
)
3142 (tramp-message proc
10 "%s %s" proc
(process-status proc
))
3143 (let (buffer-read-only last-coding-system-used
)
3144 ;; Under Windows XP, accept-process-output doesn't return
3145 ;; sometimes. So we add an additional timeout.
3146 (with-timeout ((or timeout
1))
3147 (accept-process-output proc timeout timeout-msecs
)))
3148 (tramp-message proc
10 "\n%s" (buffer-string))))
3150 (defun tramp-check-for-regexp (proc regexp
)
3151 "Check, whether REGEXP is contained in process buffer of PROC.
3152 Erase echoed commands if exists."
3153 (with-current-buffer (process-buffer proc
)
3154 (goto-char (point-min))
3156 ;; Check whether we need to remove echo output.
3157 (when (and (tramp-get-connection-property proc
"check-remote-echo" nil
)
3158 (re-search-forward tramp-echoed-echo-mark-regexp nil t
))
3159 (let ((begin (match-beginning 0)))
3160 (when (re-search-forward tramp-echoed-echo-mark-regexp nil t
)
3161 ;; Discard echo from remote output.
3162 (tramp-set-connection-property proc
"check-remote-echo" nil
)
3163 (tramp-message proc
5 "echo-mark found")
3165 (delete-region begin
(point))
3166 (goto-char (point-min)))))
3168 (when (or (not (tramp-get-connection-property proc
"check-remote-echo" nil
))
3169 ;; Sometimes, the echo string is suppressed on the remote side.
3171 (tramp-compat-funcall
3172 'substring-no-properties tramp-echo-mark-marker
3173 0 (min tramp-echo-mark-marker-length
(1- (point-max))))
3174 (tramp-compat-funcall
3175 'buffer-substring-no-properties
3176 1 (min (1+ tramp-echo-mark-marker-length
) (point-max))))))
3177 ;; No echo to be handled, now we can look for the regexp.
3178 (goto-char (point-min))
3179 (re-search-forward regexp nil t
))))
3181 (defun tramp-wait-for-regexp (proc timeout regexp
)
3182 "Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
3183 Expects the output of PROC to be sent to the current buffer. Returns
3184 the string that matched, or nil. Waits indefinitely if TIMEOUT is
3186 (with-current-buffer (process-buffer proc
)
3187 (let ((found (tramp-check-for-regexp proc regexp
))
3188 (start-time (current-time)))
3190 ;; Work around a bug in XEmacs 21, where the timeout
3191 ;; expires faster than it should. This degenerates
3192 ;; to polling for buggy XEmacsen, but oh, well.
3193 (while (and (not found
)
3194 (< (tramp-time-diff (current-time) start-time
)
3196 (with-timeout (timeout)
3198 (tramp-accept-process-output proc
1)
3199 (unless (memq (process-status proc
) '(run open
))
3200 (tramp-error-with-buffer
3201 nil proc
'file-error
"Process has died"))
3202 (setq found
(tramp-check-for-regexp proc regexp
))))))
3205 (tramp-accept-process-output proc
1)
3206 (unless (memq (process-status proc
) '(run open
))
3207 (tramp-error-with-buffer
3208 nil proc
'file-error
"Process has died"))
3209 (setq found
(tramp-check-for-regexp proc regexp
)))))
3210 (tramp-message proc
6 "\n%s" (buffer-string))
3214 proc
'file-error
"[[Regexp `%s' not found in %d secs]]"
3216 (tramp-error proc
'file-error
"[[Regexp `%s' not found]]" regexp
)))
3219 ;; We don't call `tramp-send-string' in order to hide the password
3220 ;; from the debug buffer, and because end-of-line handling of the
3222 (defun tramp-enter-password (proc)
3223 "Prompt for a password and send it to the remote end."
3224 (process-send-string
3225 proc
(concat (tramp-read-passwd proc
)
3226 (or (tramp-get-method-parameter
3227 tramp-current-method
3228 'tramp-password-end-of-line
)
3229 tramp-default-password-end-of-line
))))
3231 ;; It seems that Tru64 Unix does not like it if long strings are sent
3232 ;; to it in one go. (This happens when sending the Perl
3233 ;; `file-attributes' implementation, for instance.) Therefore, we
3234 ;; have this function which sends the string in chunks.
3235 (defun tramp-send-string (vec string
)
3236 "Send the STRING via connection VEC.
3238 The STRING is expected to use Unix line-endings, but the lines sent to
3239 the remote host use line-endings as defined in the variable
3240 `tramp-rsh-end-of-line'. The communication buffer is erased before sending."
3241 (let* ((p (tramp-get-connection-process vec
))
3242 (chunksize (tramp-get-connection-property p
"chunksize" nil
)))
3245 vec
'file-error
"Can't send string to remote host -- not logged in"))
3246 (tramp-set-connection-property p
"last-cmd-time" (current-time))
3247 (tramp-message vec
10 "%s" string
)
3248 (with-current-buffer (tramp-get-connection-buffer vec
)
3249 ;; Clean up the buffer. We cannot call `erase-buffer' because
3250 ;; narrowing might be in effect.
3251 (let (buffer-read-only) (delete-region (point-min) (point-max)))
3252 ;; Replace "\n" by `tramp-rsh-end-of-line'.
3254 (mapconcat 'identity
3255 (tramp-compat-split-string string
"\n")
3256 tramp-rsh-end-of-line
))
3257 (unless (or (string= string
"")
3258 (string-equal (substring string -
1) tramp-rsh-end-of-line
))
3259 (setq string
(concat string tramp-rsh-end-of-line
)))
3261 (if (and chunksize
(not (zerop chunksize
)))
3263 (end (length string
)))
3266 vec
10 "Sending chunk from %s to %s"
3267 pos
(min (+ pos chunksize
) end
))
3268 (process-send-string
3269 p
(substring string pos
(min (+ pos chunksize
) end
)))
3270 (setq pos
(+ pos chunksize
))))
3271 (process-send-string p string
)))))
3273 (defun tramp-get-inode (vec)
3274 "Returns the virtual inode number.
3275 If it doesn't exist, generate a new one."
3276 (let ((string (tramp-make-tramp-file-name
3277 (tramp-file-name-method vec
)
3278 (tramp-file-name-user vec
)
3279 (tramp-file-name-host vec
)
3281 (unless (assoc string tramp-inodes
)
3282 (add-to-list 'tramp-inodes
3283 (list string
(length tramp-inodes
))))
3284 (nth 1 (assoc string tramp-inodes
))))
3286 (defun tramp-get-device (vec)
3287 "Returns the virtual device number.
3288 If it doesn't exist, generate a new one."
3289 (let ((string (tramp-make-tramp-file-name
3290 (tramp-file-name-method vec
)
3291 (tramp-file-name-user vec
)
3292 (tramp-file-name-host vec
)
3294 (unless (assoc string tramp-devices
)
3295 (add-to-list 'tramp-devices
3296 (list string
(length tramp-devices
))))
3297 (cons -
1 (nth 1 (assoc string tramp-devices
)))))
3299 (defun tramp-equal-remote (file1 file2
)
3300 "Check, whether the remote parts of FILE1 and FILE2 are identical.
3301 The check depends on method, user and host name of the files. If
3302 one of the components is missing, the default values are used.
3303 The local file name parts of FILE1 and FILE2 are not taken into
3308 (tramp-equal-remote \"/ssh::/etc\" \"/<your host name>:/home\")
3310 would yield `t'. On the other hand, the following check results in nil:
3312 (tramp-equal-remote \"/sudo::/etc\" \"/su::/etc\")"
3313 (and (stringp (file-remote-p file1
))
3314 (stringp (file-remote-p file2
))
3315 (string-equal (file-remote-p file1
) (file-remote-p file2
))))
3317 (defun tramp-get-method-parameter (method param
)
3318 "Return the method parameter PARAM.
3319 If the `tramp-methods' entry does not exist, return nil."
3320 (let ((entry (assoc param
(assoc method tramp-methods
))))
3321 (when entry
(cadr entry
))))
3323 (defun tramp-mode-string-to-int (mode-string)
3324 "Converts a ten-letter `drwxrwxrwx'-style mode string into mode bits."
3325 (let* (case-fold-search
3326 (mode-chars (string-to-vector mode-string
))
3327 (owner-read (aref mode-chars
1))
3328 (owner-write (aref mode-chars
2))
3329 (owner-execute-or-setid (aref mode-chars
3))
3330 (group-read (aref mode-chars
4))
3331 (group-write (aref mode-chars
5))
3332 (group-execute-or-setid (aref mode-chars
6))
3333 (other-read (aref mode-chars
7))
3334 (other-write (aref mode-chars
8))
3335 (other-execute-or-sticky (aref mode-chars
9)))
3339 ((char-equal owner-read ?r
) (tramp-compat-octal-to-decimal "00400"))
3340 ((char-equal owner-read ?-
) 0)
3341 (t (error "Second char `%c' must be one of `r-'" owner-read
)))
3343 ((char-equal owner-write ?w
) (tramp-compat-octal-to-decimal "00200"))
3344 ((char-equal owner-write ?-
) 0)
3345 (t (error "Third char `%c' must be one of `w-'" owner-write
)))
3347 ((char-equal owner-execute-or-setid ?x
)
3348 (tramp-compat-octal-to-decimal "00100"))
3349 ((char-equal owner-execute-or-setid ?S
)
3350 (tramp-compat-octal-to-decimal "04000"))
3351 ((char-equal owner-execute-or-setid ?s
)
3352 (tramp-compat-octal-to-decimal "04100"))
3353 ((char-equal owner-execute-or-setid ?-
) 0)
3354 (t (error "Fourth char `%c' must be one of `xsS-'"
3355 owner-execute-or-setid
)))
3357 ((char-equal group-read ?r
) (tramp-compat-octal-to-decimal "00040"))
3358 ((char-equal group-read ?-
) 0)
3359 (t (error "Fifth char `%c' must be one of `r-'" group-read
)))
3361 ((char-equal group-write ?w
) (tramp-compat-octal-to-decimal "00020"))
3362 ((char-equal group-write ?-
) 0)
3363 (t (error "Sixth char `%c' must be one of `w-'" group-write
)))
3365 ((char-equal group-execute-or-setid ?x
)
3366 (tramp-compat-octal-to-decimal "00010"))
3367 ((char-equal group-execute-or-setid ?S
)
3368 (tramp-compat-octal-to-decimal "02000"))
3369 ((char-equal group-execute-or-setid ?s
)
3370 (tramp-compat-octal-to-decimal "02010"))
3371 ((char-equal group-execute-or-setid ?-
) 0)
3372 (t (error "Seventh char `%c' must be one of `xsS-'"
3373 group-execute-or-setid
)))
3375 ((char-equal other-read ?r
)
3376 (tramp-compat-octal-to-decimal "00004"))
3377 ((char-equal other-read ?-
) 0)
3378 (t (error "Eighth char `%c' must be one of `r-'" other-read
)))
3380 ((char-equal other-write ?w
) (tramp-compat-octal-to-decimal "00002"))
3381 ((char-equal other-write ?-
) 0)
3382 (t (error "Nineth char `%c' must be one of `w-'" other-write
)))
3384 ((char-equal other-execute-or-sticky ?x
)
3385 (tramp-compat-octal-to-decimal "00001"))
3386 ((char-equal other-execute-or-sticky ?T
)
3387 (tramp-compat-octal-to-decimal "01000"))
3388 ((char-equal other-execute-or-sticky ?t
)
3389 (tramp-compat-octal-to-decimal "01001"))
3390 ((char-equal other-execute-or-sticky ?-
) 0)
3391 (t (error "Tenth char `%c' must be one of `xtT-'"
3392 other-execute-or-sticky
)))))))
3394 (defun tramp-local-host-p (vec)
3395 "Return t if this points to the local host, nil otherwise."
3396 ;; We cannot use `tramp-file-name-real-host'. A port is an
3397 ;; indication for an ssh tunnel or alike.
3398 (let ((host (tramp-file-name-host vec
)))
3401 (string-match tramp-local-host-regexp host
)
3402 ;; The method shall be applied to one of the shell file name
3403 ;; handler. `tramp-local-host-p' is also called for "smb" and
3404 ;; alike, where it must fail.
3405 (tramp-get-method-parameter
3406 (tramp-file-name-method vec
) 'tramp-login-program
)
3407 ;; The local temp directory must be writable for the other user.
3409 (tramp-make-tramp-file-name
3410 (tramp-file-name-method vec
)
3411 (tramp-file-name-user vec
)
3413 (tramp-compat-temporary-file-directory)))
3414 ;; On some systems, chown runs only for root.
3415 (or (zerop (user-uid))
3416 ;; This is defined in tramp-sh.el. Let's assume this is
3418 (zerop (tramp-compat-funcall 'tramp-get-remote-uid vec
'integer
))))))
3420 (defun tramp-make-tramp-temp-file (vec)
3421 "Create a temporary file on the remote host identified by VEC.
3422 Return the local name of the temporary file."
3424 (tramp-make-tramp-file-name
3425 (tramp-file-name-method vec
)
3426 (tramp-file-name-user vec
)
3427 (tramp-file-name-host vec
)
3428 (tramp-drop-volume-letter
3430 tramp-temp-name-prefix
3431 ;; This is defined in tramp-sh.el. Let's assume this is
3433 (tramp-compat-funcall 'tramp-get-remote-tmpdir vec
)))))
3436 ;; `make-temp-file' would be the natural choice for
3437 ;; implementation. But it calls `write-region' internally,
3438 ;; which also needs a temporary file - we would end in an
3440 (setq result
(make-temp-name prefix
))
3441 (if (file-exists-p result
)
3443 ;; This creates the file by side effect.
3444 (set-file-times result
)
3445 (set-file-modes result
(tramp-compat-octal-to-decimal "0700"))))
3447 ;; Return the local part.
3448 (with-parsed-tramp-file-name result nil localname
)))
3450 (defun tramp-delete-temp-file-function ()
3451 "Remove temporary files related to current buffer."
3452 (when (stringp tramp-temp-buffer-file-name
)
3453 (ignore-errors (delete-file tramp-temp-buffer-file-name
))))
3455 (add-hook 'kill-buffer-hook
'tramp-delete-temp-file-function
)
3456 (add-hook 'tramp-cache-unload-hook
3458 (remove-hook 'kill-buffer-hook
3459 'tramp-delete-temp-file-function
)))
3461 ;;; Auto saving to a special directory:
3463 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name
)
3464 (defadvice make-auto-save-file-name
3465 (around tramp-advice-make-auto-save-file-name
() activate
)
3466 "Invoke `tramp-*-handle-make-auto-save-file-name' for Tramp files."
3467 (if (tramp-tramp-file-p (buffer-file-name))
3468 ;; We cannot call `tramp-handle-make-auto-save-file-name'
3469 ;; directly, because this would bypass the locking mechanism.
3470 (setq ad-return-value
3471 (tramp-file-name-handler 'make-auto-save-file-name
))
3477 'make-auto-save-file-name
3478 'around
'tramp-advice-make-auto-save-file-name
)
3479 (ad-activate 'make-auto-save-file-name
))))
3481 ;; In XEmacs < 21.5, autosaved remote files have permission 0666 minus
3482 ;; umask. This is a security threat.
3484 (defun tramp-set-auto-save-file-modes ()
3485 "Set permissions of autosaved remote files to the original permissions."
3486 (let ((bfn (buffer-file-name)))
3487 (when (and (tramp-tramp-file-p bfn
)
3489 (stringp buffer-auto-save-file-name
)
3490 (not (equal bfn buffer-auto-save-file-name
)))
3491 (unless (file-exists-p buffer-auto-save-file-name
)
3492 (write-region "" nil buffer-auto-save-file-name
))
3493 ;; Permissions should be set always, because there might be an old
3494 ;; auto-saved file belonging to another original file. This could
3495 ;; be a security threat.
3497 buffer-auto-save-file-name
3498 (or (file-modes bfn
) (tramp-compat-octal-to-decimal "0600"))))))
3500 (unless (and (featurep 'xemacs
)
3501 (= emacs-major-version
21)
3502 (> emacs-minor-version
4))
3503 (add-hook 'auto-save-hook
'tramp-set-auto-save-file-modes
)
3504 (add-hook 'tramp-unload-hook
3506 (remove-hook 'auto-save-hook
'tramp-set-auto-save-file-modes
))))
3508 (defun tramp-subst-strs-in-string (alist string
)
3509 "Replace all occurrences of the string FROM with TO in STRING.
3510 ALIST is of the form ((FROM . TO) ...)."
3513 (let* ((pr (car alist
))
3516 (while (string-match (regexp-quote from
) string
)
3517 (setq string
(replace-match to t t string
)))
3518 (setq alist
(cdr alist
))))
3521 ;;; Compatibility functions section:
3523 (defun tramp-read-passwd (proc &optional prompt
)
3524 "Read a password from user (compat function).
3525 Consults the auth-source package.
3526 Invokes `password-read' if available, `read-passwd' else."
3527 (let* ((key (tramp-make-tramp-file-name
3528 tramp-current-method tramp-current-user
3529 tramp-current-host
""))
3532 (with-current-buffer (process-buffer proc
)
3533 (tramp-check-for-regexp proc tramp-password-prompt-regexp
)
3534 (format "%s for %s " (capitalize (match-string 1)) key
))))
3535 auth-info auth-passwd
)
3536 (with-parsed-tramp-file-name key nil
3539 ;; See if auth-sources contains something useful, if it's
3540 ;; bound. `auth-source-user-or-password' is an obsoleted
3541 ;; function, it has been replaced by `auth-source-search'.
3542 (and (boundp 'auth-sources
)
3543 (tramp-get-connection-property v
"first-password-request" nil
)
3544 ;; Try with Tramp's current method.
3545 (if (fboundp 'auth-source-search
)
3547 (tramp-compat-funcall
3550 :user
(or tramp-current-user t
)
3551 :host tramp-current-host
3552 :port tramp-current-method
)
3553 auth-passwd
(plist-get (nth 0 auth-info
) :secret
)
3554 auth-passwd
(if (functionp auth-passwd
)
3555 (funcall auth-passwd
)
3557 (tramp-compat-funcall
3558 'auth-source-user-or-password
3559 "password" tramp-current-host tramp-current-method
)))
3560 ;; Try the password cache.
3561 (when (functionp 'password-read
)
3562 (unless (tramp-get-connection-property
3563 v
"first-password-request" nil
)
3564 (tramp-compat-funcall 'password-cache-remove key
))
3566 (tramp-compat-funcall 'password-read pw-prompt key
)))
3567 (tramp-compat-funcall 'password-cache-add key password
)
3569 ;; Else, get the password interactively.
3570 (read-passwd pw-prompt
))
3571 (tramp-set-connection-property v
"first-password-request" nil
)))))
3573 (defun tramp-clear-passwd (vec)
3574 "Clear password cache for connection related to VEC."
3575 (tramp-compat-funcall
3576 'password-cache-remove
3577 (tramp-make-tramp-file-name
3578 (tramp-file-name-method vec
)
3579 (tramp-file-name-user vec
)
3580 (tramp-file-name-host vec
)
3583 ;; Snarfed code from time-date.el and parse-time.el
3585 (defconst tramp-half-a-year
'(241 17024)
3586 "Evaluated by \"(days-to-time 183)\".")
3588 (defconst tramp-parse-time-months
3589 '(("jan" .
1) ("feb" .
2) ("mar" .
3)
3590 ("apr" .
4) ("may" .
5) ("jun" .
6)
3591 ("jul" .
7) ("aug" .
8) ("sep" .
9)
3592 ("oct" .
10) ("nov" .
11) ("dec" .
12))
3593 "Alist mapping month names to integers.")
3595 (defun tramp-time-less-p (t1 t2
)
3596 "Say whether time value T1 is less than time value T2."
3597 (unless t1
(setq t1
'(0 0)))
3598 (unless t2
(setq t2
'(0 0)))
3599 (or (< (car t1
) (car t2
))
3600 (and (= (car t1
) (car t2
))
3601 (< (nth 1 t1
) (nth 1 t2
)))))
3603 (defun tramp-time-subtract (t1 t2
)
3604 "Subtract two time values.
3605 Return the difference in the format of a time value."
3606 (unless t1
(setq t1
'(0 0)))
3607 (unless t2
(setq t2
'(0 0)))
3608 (let ((borrow (< (cadr t1
) (cadr t2
))))
3609 (list (- (car t1
) (car t2
) (if borrow
1 0))
3610 (- (+ (if borrow
65536 0) (cadr t1
)) (cadr t2
)))))
3612 (defun tramp-time-diff (t1 t2
)
3613 "Return the difference between the two times, in seconds.
3614 T1 and T2 are time values (as returned by `current-time' for example)."
3615 (cond ((and (fboundp 'subtract-time
)
3616 (fboundp 'float-time
))
3617 (tramp-compat-funcall
3618 'float-time
(tramp-compat-funcall 'subtract-time t1 t2
)))
3619 ((and (fboundp 'subtract-time
)
3620 (fboundp 'time-to-seconds
))
3621 (tramp-compat-funcall
3622 'time-to-seconds
(tramp-compat-funcall 'subtract-time t1 t2
)))
3623 ((fboundp 'itimer-time-difference
)
3624 (tramp-compat-funcall
3625 'itimer-time-difference
3626 (if (< (length t1
) 3) (append t1
'(0)) t1
)
3627 (if (< (length t2
) 3) (append t2
'(0)) t2
)))
3629 (let ((time (tramp-time-subtract t1 t2
)))
3630 (+ (* (car time
) 65536.0)
3632 (/ (or (nth 2 time
) 0) 1000000.0))))))
3634 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
3635 ;; does not deal well with newline characters. Newline is replaced by
3636 ;; backslash newline. But if, say, the string `a backslash newline b'
3637 ;; is passed to a shell, the shell will expand this into "ab",
3638 ;; completely omitting the newline. This is not what was intended.
3639 ;; It does not appear to be possible to make the function
3640 ;; `shell-quote-argument' work with newlines without making it
3641 ;; dependent on the shell used. But within this package, we know that
3642 ;; we will always use a Bourne-like shell, so we use an approach which
3645 ;; The approach is simple: we call `shell-quote-argument', then
3646 ;; massage the newline part of the result.
3648 ;; This function should produce a string which is grokked by a Unix
3649 ;; shell, even if the Emacs is running on Windows. Since this is the
3650 ;; kludges section, we bind `system-type' in such a way that
3651 ;; `shell-quote-arguments' behaves as if on Unix.
3653 ;; Thanks to Mario DeWeerd for the hint that it is sufficient for this
3654 ;; function to work with Bourne-like shells.
3656 ;; CCC: This function should be rewritten so that
3657 ;; `shell-quote-argument' is not used. This way, we are safe from
3658 ;; changes in `shell-quote-argument'.
3659 ;;;###tramp-autoload
3660 (defun tramp-shell-quote-argument (s)
3661 "Similar to `shell-quote-argument', but groks newlines.
3662 Only works for Bourne-like shells."
3663 (let ((system-type 'not-windows
))
3665 (let ((result (shell-quote-argument s
))
3666 (nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line
))))
3667 (when (and (>= (length result
) 2)
3668 (string= (substring result
0 2) "\\~"))
3669 (setq result
(substring result
1)))
3670 (while (string-match nl result
)
3671 (setq result
(replace-match (format "'%s'" tramp-rsh-end-of-line
)
3675 ;; Checklist for `tramp-unload-hook'
3676 ;; - Unload all `tramp-*' packages
3677 ;; - Reset `file-name-handler-alist'
3678 ;; - Cleanup hooks where Tramp functions are in
3679 ;; - Cleanup advised functions
3680 ;; - Cleanup autoloads
3682 (defun tramp-unload-tramp ()
3683 "Discard Tramp from loading remote files."
3685 ;; ange-ftp settings must be enabled.
3686 (tramp-compat-funcall 'tramp-ftp-enable-ange-ftp
)
3687 ;; Maybe it's not loaded yet.
3688 (ignore-errors (unload-feature 'tramp
'force
)))
3694 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
3695 ;; `shell-quote-argument'.
3696 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
3697 ;; by the files in that directory. Add this here.
3698 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
3699 ;; * Make ffap.el grok Tramp filenames. (Eli Tziperman)
3700 ;; * abbreviate-file-name
3701 ;; * Better error checking. At least whenever we see something
3702 ;; strange when doing zerop, we should kill the process and start
3703 ;; again. (Greg Stark)
3704 ;; * Username and hostname completion.
3705 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'.
3706 ;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.
3707 ;; Code is nearly identical.
3708 ;; * Make `tramp-default-user' obsolete.
3709 ;; * Implement a general server-local-variable mechanism, as there are
3710 ;; probably other variables that need different values for different
3711 ;; servers too. The user could then configure a variable (such as
3712 ;; tramp-server-local-variable-alist) to define any such variables
3713 ;; that they need to, which would then be let bound as appropriate
3714 ;; in tramp functions. (Jason Rumney)
3715 ;; * IMHO, it's a drawback that currently Tramp doesn't support
3716 ;; Unicode in Dired file names by default. Is it possible to
3717 ;; improve Tramp to set LC_ALL to "C" only for commands where Tramp
3718 ;; expects English? Or just to set LC_MESSAGES to "C" if Tramp
3719 ;; expects only English messages? (Juri Linkov)
3720 ;; * Make shadowfile.el grok Tramp filenames. (Bug#4526, Bug#4846)
3721 ;; * I was wondering it it would be possible to use tramp even if I'm
3722 ;; actually using sshfs. But when I launch a command I would like
3723 ;; to get it executed on the remote machine where the files really
3724 ;; are. (Andrea Crotti)
3725 ;; * Run emerge on two remote files. Bug is described here:
3726 ;; <http://www.mail-archive.com/tramp-devel@nongnu.org/msg01041.html>.
3729 ;; Functions for file-name-handler-alist:
3730 ;; diff-latest-backup-file -- in diff.el
3732 ;;; tramp.el ends here