1 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol
3 ;; Copyright (C) 1998-2013 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 ;; Pacify byte-compiler.
65 (defvar bkup-backup-directory-info
)
66 (defvar directory-sep-char
)
67 (defvar eshell-path-env
)
68 (defvar file-notify-descriptors
)
69 (defvar outline-regexp
)
71 ;;; User Customizable Internal Variables:
74 "Edit remote files with a combination of ssh, scp, etc."
79 ;; Maybe we need once a real Tramp mode, with key bindings etc.
81 (defcustom tramp-mode t
82 "Whether Tramp is enabled.
83 If it is set to nil, all remote file names are used literally."
87 (defcustom tramp-verbose
3
88 "Verbosity level for Tramp messages.
89 Any level x includes messages for all levels 1 .. x-1. The levels are
91 0 silent (no tramp messages at all)
94 3 connection to remote hosts (default level)
97 6 sent and received strings
99 8 connection properties
107 (when (boundp 'backup-directory-alist
)
108 (defcustom tramp-backup-directory-alist nil
109 "Alist of filename patterns and backup directory names.
110 Each element looks like (REGEXP . DIRECTORY), with the same meaning like
111 in `backup-directory-alist'. If a Tramp file is backed up, and DIRECTORY
112 is a local file name, the backup directory is prepended with Tramp file
113 name prefix \(method, user, host\) of file.
115 \(setq tramp-backup-directory-alist backup-directory-alist\)
117 gives the same backup policy for Tramp files on their hosts like the
118 policy for local files."
120 :type
'(repeat (cons (regexp :tag
"Regexp matching filename")
121 (directory :tag
"Backup directory name"))))))
123 ;; XEmacs case. We cannot check for `bkup-backup-directory-info', because
124 ;; the package "backup-dir" might not be loaded yet.
126 (when (featurep 'xemacs
)
127 (defcustom tramp-bkup-backup-directory-info nil
128 "Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
129 It has the same meaning like `bkup-backup-directory-info' from package
130 `backup-dir'. If a Tramp file is backed up, and BACKUP-DIR is a local
131 file name, the backup directory is prepended with Tramp file name prefix
132 \(method, user, host\) of file.
134 \(setq tramp-bkup-backup-directory-info bkup-backup-directory-info\)
136 gives the same backup policy for Tramp files on their hosts like the
137 policy for local files."
139 (list (regexp :tag
"File regexp")
140 (string :tag
"Backup Dir")
145 (const search-upward
))))
148 (defcustom tramp-auto-save-directory nil
149 "Put auto-save files in this directory, if set.
150 The idea is to use a local directory so that auto-saving is faster."
152 :type
'(choice (const nil
) string
))
154 (defcustom tramp-encoding-shell
155 (if (memq system-type
'(windows-nt))
158 "Use this program for encoding and decoding commands on the local host.
159 This shell is used to execute the encoding and decoding command on the
160 local host, so if you want to use `~' in those commands, you should
161 choose a shell here which groks tilde expansion. `/bin/sh' normally
162 does not understand tilde expansion.
164 For encoding and decoding, commands like the following are executed:
166 /bin/sh -c COMMAND < INPUT > OUTPUT
168 This variable can be used to change the \"/bin/sh\" part. See the
169 variable `tramp-encoding-command-switch' for the \"-c\" part.
171 If the shell must be forced to be interactive, see
172 `tramp-encoding-command-interactive'.
174 Note that this variable is not used for remote commands. There are
175 mechanisms in tramp.el which automatically determine the right shell to
176 use for the remote host."
178 :type
'(file :must-match t
))
180 (defcustom tramp-encoding-command-switch
181 (if (string-match "cmd\\.exe" tramp-encoding-shell
)
184 "Use this switch together with `tramp-encoding-shell' for local commands.
185 See the variable `tramp-encoding-shell' for more information."
189 (defcustom tramp-encoding-command-interactive
190 (unless (string-match "cmd\\.exe" tramp-encoding-shell
) "-i")
191 "Use this switch together with `tramp-encoding-shell' for interactive shells.
192 See the variable `tramp-encoding-shell' for more information."
195 :type
'(choice (const nil
) string
))
198 (defvar tramp-methods nil
199 "Alist of methods for remote files.
200 This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
201 Each NAME stands for a remote access method. Each PARAM is a
202 pair of the form (KEY VALUE). The following KEYs are defined:
203 * `tramp-remote-shell'
204 This specifies the shell to use on the remote host. This
205 MUST be a Bourne-like shell. It is normally not necessary to
206 set this to any value other than \"/bin/sh\": Tramp wants to
207 use a shell which groks tilde expansion, but it can search
208 for it. Also note that \"/bin/sh\" exists on all Unixen,
209 this might not be true for the value that you decide to use.
210 You Have Been Warned.
211 * `tramp-remote-shell-args'
212 For implementation of `shell-command', this specifies the
213 arguments to let `tramp-remote-shell' run a single command.
214 * `tramp-login-program'
215 This specifies the name of the program to use for logging in to the
216 remote host. This may be the name of rsh or a workalike program,
217 or the name of telnet or a workalike, or the name of su or a workalike.
219 This specifies the list of arguments to pass to the above
220 mentioned program. Please note that this is a list of list of arguments,
221 that is, normally you don't want to put \"-a -b\" or \"-f foo\"
222 here. Instead, you want a list (\"-a\" \"-b\"), or (\"-f\" \"foo\").
223 There are some patterns: \"%h\" in this list is replaced by the host
224 name, \"%u\" is replaced by the user name, \"%p\" is replaced by the
225 port number, and \"%%\" can be used to obtain a literal percent character.
226 If a list containing \"%h\", \"%u\" or \"%p\" is unchanged during
227 expansion (i.e. no host or no user specified), this list is not used as
228 argument. By this, arguments like (\"-l\" \"%u\") are optional.
229 \"%t\" is replaced by the temporary file name produced with
230 `tramp-make-tramp-temp-file'. \"%k\" indicates the keep-date
231 parameter of a program, if exists. \"%c\" adds additional
232 `tramp-ssh-controlmaster-options' options for the first hop.
234 When an asynchronous process is started, we know already that
235 the connection works. Therefore, we can pass additional
236 parameters to suppress diagnostic messages, in order not to
237 tamper the process output.
238 * `tramp-copy-program'
239 This specifies the name of the program to use for remotely copying
240 the file; this might be the absolute filename of rcp or the name of
243 This specifies the list of parameters to pass to the above mentioned
244 program, the hints for `tramp-login-args' also apply here.
245 * `tramp-copy-keep-date'
246 This specifies whether the copying program when the preserves the
247 timestamp of the original file.
248 * `tramp-copy-keep-tmpfile'
249 This specifies whether a temporary local file shall be kept
250 for optimization reasons (useful for \"rsync\" methods).
251 * `tramp-copy-recursive'
252 Whether the operation copies directories recursively.
253 * `tramp-default-port'
254 The default port of a method is needed in case of gateway connections.
255 Additionally, it is used as indication which method is prepared for
258 As the attribute name says, additional arguments are specified here
259 when a method is applied via a gateway.
261 A directory on the remote host for temporary files. If not
262 specified, \"/tmp\" is taken as default.
263 * `tramp-connection-timeout'
264 This is the maximum time to be spent for establishing a connection.
265 In general, the global default value shall be used, but for
266 some methods, like \"su\" or \"sudo\", a shorter timeout
269 What does all this mean? Well, you should specify `tramp-login-program'
270 for all methods; this program is used to log in to the remote site. Then,
271 there are two ways to actually transfer the files between the local and the
272 remote side. One way is using an additional rcp-like program. If you want
273 to do this, set `tramp-copy-program' in the method.
275 Another possibility for file transfer is inline transfer, i.e. the
276 file is passed through the same buffer used by `tramp-login-program'. In
277 this case, the file contents need to be protected since the
278 `tramp-login-program' might use escape codes or the connection might not
279 be eight-bit clean. Therefore, file contents are encoded for transit.
280 See the variables `tramp-local-coding-commands' and
281 `tramp-remote-coding-commands' for details.
283 So, to summarize: if the method is an out-of-band method, then you
284 must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
285 inline method, then these two parameters should be nil. Methods which
286 are fit for gateways must have `tramp-default-port' at least.
290 When using `su' or `sudo' the phrase `open connection to a remote
291 host' sounds strange, but it is used nevertheless, for consistency.
292 No connection is opened to a remote host, but `su' or `sudo' is
293 started on the local host. You should specify a remote host
294 `localhost' or the name of the local host. Another host name is
295 useful only in combination with `tramp-default-proxies-alist'.")
298 (defconst tramp-ssh-controlmaster-options
302 (call-process "ssh" nil t nil
"-o" "ControlMaster")
303 (goto-char (point-min))
304 (when (search-forward-regexp "Missing ControlMaster argument" nil t
)
305 (setq result
"-o ControlPath=%t.%%r@%%h:%%p -o ControlMaster=auto")))
308 (call-process "ssh" nil t nil
"-o" "ControlPersist")
309 (goto-char (point-min))
310 (when (search-forward-regexp "Missing ControlPersist argument" nil t
)
311 (setq result
(concat result
" -o ControlPersist=no"))))))
313 "Call ssh to detect whether it supports the Control* arguments.
314 Return a string to be used in `tramp-methods'.")
317 (defcustom tramp-use-ssh-controlmaster-options
318 (not (zerop (length tramp-ssh-controlmaster-options
)))
319 "Whether to use `tramp-ssh-controlmaster-options'."
324 (defcustom tramp-default-method
325 ;; An external copy method seems to be preferred, because it performs
326 ;; much better for large files, and it hasn't too serious delays
327 ;; for small files. But it must be ensured that there aren't
328 ;; permanent password queries. Either a password agent like
329 ;; "ssh-agent" or "Pageant" shall run, or the optional
330 ;; password-cache.el or auth-sources.el packages shall be active for
331 ;; password caching. If we detect that the user is running OpenSSH
332 ;; 4.0 or newer, we could reuse the connection, which calls also for
333 ;; an external method.
335 ;; PuTTY is installed. We don't take it, if it is installed on a
336 ;; non-windows system, or pscp from the pssh (parallel ssh) package
338 ((and (eq system-type
'windows-nt
)
339 (executable-find "pscp"))
340 (if (or (fboundp 'password-read
)
341 (fboundp 'auth-source-user-or-password
)
342 (fboundp 'auth-source-search
)
343 ;; Pageant is running.
344 (tramp-compat-process-running-p "Pageant"))
347 ;; There is an ssh installation.
348 ((executable-find "scp")
349 (if (or (fboundp 'password-read
)
350 (fboundp 'auth-source-user-or-password
)
351 (fboundp 'auth-source-search
)
352 ;; ssh-agent is running.
353 (getenv "SSH_AUTH_SOCK")
354 (getenv "SSH_AGENT_PID")
355 ;; We could reuse the connection.
356 (> (length tramp-ssh-controlmaster-options
) 0))
361 "Default method to use for transferring files.
362 See `tramp-methods' for possibilities.
363 Also see `tramp-default-method-alist'."
368 (defcustom tramp-default-method-alist nil
369 "Default method to use for specific host/user pairs.
370 This is an alist of items (HOST USER METHOD). The first matching item
371 specifies the method to use for a file name which does not specify a
372 method. HOST and USER are regular expressions or nil, which is
373 interpreted as a regular expression which always matches. If no entry
374 matches, the variable `tramp-default-method' takes effect.
376 If the file name does not specify the user, lookup is done using the
377 empty string for the user name.
379 See `tramp-methods' for a list of possibilities for METHOD."
381 :type
'(repeat (list (choice :tag
"Host regexp" regexp sexp
)
382 (choice :tag
"User regexp" regexp sexp
)
383 (choice :tag
"Method name" string
(const nil
)))))
385 (defcustom tramp-default-user nil
386 "Default user to use for transferring files.
387 It is nil by default; otherwise settings in configuration files like
388 \"~/.ssh/config\" would be overwritten. Also see `tramp-default-user-alist'.
390 This variable is regarded as obsolete, and will be removed soon."
392 :type
'(choice (const nil
) string
))
395 (defcustom tramp-default-user-alist nil
396 "Default user to use for specific method/host pairs.
397 This is an alist of items (METHOD HOST USER). The first matching item
398 specifies the user to use for a file name which does not specify a
399 user. METHOD and USER are regular expressions or nil, which is
400 interpreted as a regular expression which always matches. If no entry
401 matches, the variable `tramp-default-user' takes effect.
403 If the file name does not specify the method, lookup is done using the
404 empty string for the method name."
406 :type
'(repeat (list (choice :tag
"Method regexp" regexp sexp
)
407 (choice :tag
" Host regexp" regexp sexp
)
408 (choice :tag
" User name" string
(const nil
)))))
410 (defcustom tramp-default-host
(system-name)
411 "Default host to use for transferring files.
412 Useful for su and sudo methods mostly."
417 (defcustom tramp-default-host-alist nil
418 "Default host to use for specific method/user pairs.
419 This is an alist of items (METHOD USER HOST). The first matching item
420 specifies the host to use for a file name which does not specify a
421 host. METHOD and HOST are regular expressions or nil, which is
422 interpreted as a regular expression which always matches. If no entry
423 matches, the variable `tramp-default-host' takes effect.
425 If the file name does not specify the method, lookup is done using the
426 empty string for the method name."
429 :type
'(repeat (list (choice :tag
"Method regexp" regexp sexp
)
430 (choice :tag
" User regexp" regexp sexp
)
431 (choice :tag
" Host name" string
(const nil
)))))
433 (defcustom tramp-default-proxies-alist nil
434 "Route to be followed for specific host/user pairs.
435 This is an alist of items (HOST USER PROXY). The first matching
436 item specifies the proxy to be passed for a file name located on
437 a remote target matching USER@HOST. HOST and USER are regular
438 expressions. PROXY must be a Tramp filename without a localname
439 part. Method and user name on PROXY are optional, which is
440 interpreted with the default values. PROXY can contain the
441 patterns %h and %u, which are replaced by the strings matching
442 HOST or USER, respectively.
444 HOST, USER or PROXY could also be Lisp forms, which will be
445 evaluated. The result must be a string or nil, which is
446 interpreted as a regular expression which always matches."
448 :type
'(repeat (list (choice :tag
"Host regexp" regexp sexp
)
449 (choice :tag
"User regexp" regexp sexp
)
450 (choice :tag
" Proxy name" string
(const nil
)))))
452 (defcustom tramp-save-ad-hoc-proxies nil
453 "Whether to save ad-hoc proxies persistently."
458 (defcustom tramp-restricted-shell-hosts-alist
459 (when (memq system-type
'(windows-nt))
460 (list (concat "\\`" (regexp-quote (system-name)) "\\'")))
461 "List of hosts, which run a restricted shell.
462 This is a list of regular expressions, which denote hosts running
463 a registered shell like \"rbash\". Those hosts can be used as
464 proxies only, see `tramp-default-proxies-alist'. If the local
465 host runs a registered shell, it shall be added to this list, too."
468 :type
'(repeat (regexp :tag
"Host regexp")))
471 (defconst tramp-local-host-regexp
475 (list "localhost" "localhost6" (system-name) "127\.0\.0\.1" "::1") t
)
477 "Host names which are regarded as local host.")
479 (defvar tramp-completion-function-alist nil
480 "Alist of methods for remote files.
481 This is a list of entries of the form \(NAME PAIR1 PAIR2 ...\).
482 Each NAME stands for a remote access method. Each PAIR is of the form
483 \(FUNCTION FILE\). FUNCTION is responsible to extract user names and host
484 names from FILE for completion. The following predefined FUNCTIONs exists:
486 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
487 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
488 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
489 * `tramp-parse-shostkeys' for \"~/.ssh2/hostkeys/*\" like files,
490 * `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
491 * `tramp-parse-hosts' for \"/etc/hosts\" like files,
492 * `tramp-parse-passwd' for \"/etc/passwd\" like files.
493 * `tramp-parse-netrc' for \"~/.netrc\" like files.
494 * `tramp-parse-putty' for PuTTY registered sessions.
496 FUNCTION can also be a customer defined function. For more details see
499 (defconst tramp-echo-mark-marker
"_echo"
500 "String marker to surround echoed commands.")
502 (defconst tramp-echo-mark-marker-length
(length tramp-echo-mark-marker
)
503 "String length of `tramp-echo-mark-marker'.")
505 (defconst tramp-echo-mark
506 (concat tramp-echo-mark-marker
507 (make-string tramp-echo-mark-marker-length ?
\b))
508 "String mark to be transmitted around shell commands.
509 Used to separate their echo from the output they produce. This
510 will only be used if we cannot disable remote echo via stty.
511 This string must have no effect on the remote shell except for
512 producing some echo which can later be detected by
513 `tramp-echoed-echo-mark-regexp'. Using `tramp-echo-mark-marker',
514 followed by an equal number of backspaces to erase them will
517 (defconst tramp-echoed-echo-mark-regexp
518 (format "%s\\(\b\\( \b\\)?\\)\\{%d\\}"
519 tramp-echo-mark-marker tramp-echo-mark-marker-length
)
520 "Regexp which matches `tramp-echo-mark' as it gets echoed by
523 (defcustom tramp-local-end-of-line
524 (if (memq system-type
'(windows-nt)) "\r\n" "\n")
525 "String used for end of line in local processes."
530 (defcustom tramp-rsh-end-of-line
"\n"
531 "String used for end of line in rsh connections.
532 I don't think this ever needs to be changed, so please tell me about it
533 if you need to change this."
537 (defcustom tramp-login-prompt-regexp
538 ".*ogin\\( .*\\)?: *"
539 "Regexp matching login-like prompts.
540 The regexp should match at end of buffer.
542 Sometimes the prompt is reported to look like \"login as:\"."
546 (defcustom tramp-shell-prompt-pattern
547 ;; Allow a prompt to start right after a ^M since it indeed would be
548 ;; displayed at the beginning of the line (and Zsh uses it). This
549 ;; regexp works only for GNU Emacs.
550 ;; Allow also [] style prompts. They can appear only during
551 ;; connection initialization; Tramp redefines the prompt afterwards.
552 (concat (if (featurep 'xemacs
) "" "\\(?:^\\|\r\\)")
553 "[^]#$%>\n]*#?[]#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*")
554 "Regexp to match prompts from remote shell.
555 Normally, Tramp expects you to configure `shell-prompt-pattern'
556 correctly, but sometimes it happens that you are connecting to a
557 remote host which sends a different kind of shell prompt. Therefore,
558 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
559 and also things matched by this variable. The default value of this
560 variable is similar to the default value of `shell-prompt-pattern',
561 which should work well in many cases.
563 This regexp must match both `tramp-initial-end-of-output' and
564 `tramp-end-of-output'."
568 (defcustom tramp-password-prompt-regexp
569 "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
570 "Regexp matching password-like prompts.
571 The regexp should match at end of buffer.
573 The `sudo' program appears to insert a `^@' character into the prompt."
577 (defcustom tramp-wrong-passwd-regexp
579 ;; These strings should be on the last line
580 (regexp-opt '("Permission denied"
585 "Timeout, server not responding."
587 "Name or service not known"
588 "Host key verification failed."
589 "No supported authentication methods left to try!") t
)
593 ;; Here comes a list of regexes, separated by \\|
594 "Received signal [0-9]+"
596 "Regexp matching a `login failed' message.
597 The regexp should match at end of buffer."
601 (defcustom tramp-yesno-prompt-regexp
603 (regexp-opt '("Are you sure you want to continue connecting (yes/no)?") t
)
605 "Regular expression matching all yes/no queries which need to be confirmed.
606 The confirmation should be done with yes or no.
607 The regexp should match at end of buffer.
608 See also `tramp-yn-prompt-regexp'."
612 (defcustom tramp-yn-prompt-regexp
614 (regexp-opt '("Store key in cache? (y/n)"
615 "Update cached key? (y/n, Return cancels connection)") t
)
617 "Regular expression matching all y/n queries which need to be confirmed.
618 The confirmation should be done with y or n.
619 The regexp should match at end of buffer.
620 See also `tramp-yesno-prompt-regexp'."
624 (defcustom tramp-terminal-prompt-regexp
628 "Terminal type\\? \\[.*\\]"
630 "Regular expression matching all terminal setting prompts.
631 The regexp should match at end of buffer.
632 The answer will be provided by `tramp-action-terminal', which see."
636 (defcustom tramp-operation-not-permitted-regexp
637 (concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
638 (regexp-opt '("Operation not permitted") t
))
639 "Regular expression matching keep-date problems in (s)cp operations.
640 Copying has been performed successfully already, so this message can
645 (defcustom tramp-copy-failed-regexp
647 (regexp-opt '("Permission denied"
650 "No such file or directory") t
)
652 "Regular expression matching copy problems in (s)cp operations."
656 (defcustom tramp-process-alive-regexp
658 "Regular expression indicating a process has finished.
659 In fact this expression is empty by intention, it will be used only to
660 check regularly the status of the associated process.
661 The answer will be provided by `tramp-action-process-alive',
662 `tramp-action-out-of-band', which see."
666 (defconst tramp-temp-name-prefix
"tramp."
667 "Prefix to use for temporary files.
668 If this is a relative file name (such as \"tramp.\"), it is considered
669 relative to the directory name returned by the function
670 `tramp-compat-temporary-file-directory' (which see). It may also be an
671 absolute file name; don't forget to include a prefix for the filename
674 (defconst tramp-temp-buffer-name
" *tramp temp*"
675 "Buffer name for a temporary buffer.
676 It shall be used in combination with `generate-new-buffer-name'.")
678 (defvar tramp-temp-buffer-file-name nil
679 "File name of a persistent local temporary file.
680 Useful for \"rsync\" like methods.")
681 (make-variable-buffer-local 'tramp-temp-buffer-file-name
)
682 (put 'tramp-temp-buffer-file-name
'permanent-local t
)
684 ;; XEmacs is distributed with few Lisp packages. Further packages are
685 ;; installed using EFS. If we use a unified filename format, then
686 ;; Tramp is required in addition to EFS. (But why can't Tramp just
687 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
688 ;; just like before.) Another reason for using a separate filename
689 ;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
690 ;; Tramp only knows how to deal with `file-name-handler-alist', not
693 ;; Currently, we have the choice between 'ftp and 'sep.
695 (defcustom tramp-syntax
696 (if (featurep 'xemacs
) 'sep
'ftp
)
697 "Tramp filename syntax to be used.
699 It can have the following values:
701 'ftp -- Ange-FTP respective EFS like syntax (GNU Emacs default)
702 'sep -- Syntax as defined for XEmacs."
705 :type
`(choice (const :tag
,(if (featurep 'xemacs
) "EFS" "Ange-FTP") ftp
)
706 (const :tag
"XEmacs" sep
)))
708 (defconst tramp-prefix-format
709 (cond ((equal tramp-syntax
'ftp
) "/")
710 ((equal tramp-syntax
'sep
) "/[")
711 (t (error "Wrong `tramp-syntax' defined")))
712 "String matching the very beginning of Tramp file names.
713 Used in `tramp-make-tramp-file-name'.")
715 (defconst tramp-prefix-regexp
716 (concat "^" (regexp-quote tramp-prefix-format
))
717 "Regexp matching the very beginning of Tramp file names.
718 Should always start with \"^\". Derived from `tramp-prefix-format'.")
720 (defconst tramp-method-regexp
722 "Regexp matching methods identifiers.")
724 (defconst tramp-postfix-method-format
725 (cond ((equal tramp-syntax
'ftp
) ":")
726 ((equal tramp-syntax
'sep
) "/")
727 (t (error "Wrong `tramp-syntax' defined")))
728 "String matching delimiter between method and user or host names.
729 Used in `tramp-make-tramp-file-name'.")
731 (defconst tramp-postfix-method-regexp
732 (regexp-quote tramp-postfix-method-format
)
733 "Regexp matching delimiter between method and user or host names.
734 Derived from `tramp-postfix-method-format'.")
736 (defconst tramp-user-regexp
"[^/|: \t]+"
737 "Regexp matching user names.")
740 (defconst tramp-prefix-domain-format
"%"
741 "String matching delimiter between user and domain names.")
744 (defconst tramp-prefix-domain-regexp
745 (regexp-quote tramp-prefix-domain-format
)
746 "Regexp matching delimiter between user and domain names.
747 Derived from `tramp-prefix-domain-format'.")
749 (defconst tramp-domain-regexp
"[-a-zA-Z0-9_.]+"
750 "Regexp matching domain names.")
752 (defconst tramp-user-with-domain-regexp
753 (concat "\\(" tramp-user-regexp
"\\)"
754 tramp-prefix-domain-regexp
755 "\\(" tramp-domain-regexp
"\\)")
756 "Regexp matching user names with domain names.")
758 (defconst tramp-postfix-user-format
"@"
759 "String matching delimiter between user and host names.
760 Used in `tramp-make-tramp-file-name'.")
762 (defconst tramp-postfix-user-regexp
763 (regexp-quote tramp-postfix-user-format
)
764 "Regexp matching delimiter between user and host names.
765 Derived from `tramp-postfix-user-format'.")
767 (defconst tramp-host-regexp
"[a-zA-Z0-9_.-]+"
768 "Regexp matching host names.")
770 (defconst tramp-prefix-ipv6-format
771 (cond ((equal tramp-syntax
'ftp
) "[")
772 ((equal tramp-syntax
'sep
) "")
773 (t (error "Wrong `tramp-syntax' defined")))
774 "String matching left hand side of IPv6 addresses.
775 Used in `tramp-make-tramp-file-name'.")
777 (defconst tramp-prefix-ipv6-regexp
778 (regexp-quote tramp-prefix-ipv6-format
)
779 "Regexp matching left hand side of IPv6 addresses.
780 Derived from `tramp-prefix-ipv6-format'.")
782 ;; The following regexp is a bit sloppy. But it shall serve our
783 ;; purposes. It covers also IPv4 mapped IPv6 addresses, like in
784 ;; "::ffff:192.168.0.1".
785 (defconst tramp-ipv6-regexp
786 "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9.]+"
787 "Regexp matching IPv6 addresses.")
789 (defconst tramp-postfix-ipv6-format
790 (cond ((equal tramp-syntax
'ftp
) "]")
791 ((equal tramp-syntax
'sep
) "")
792 (t (error "Wrong `tramp-syntax' defined")))
793 "String matching right hand side of IPv6 addresses.
794 Used in `tramp-make-tramp-file-name'.")
796 (defconst tramp-postfix-ipv6-regexp
797 (regexp-quote tramp-postfix-ipv6-format
)
798 "Regexp matching right hand side of IPv6 addresses.
799 Derived from `tramp-postfix-ipv6-format'.")
801 (defconst tramp-prefix-port-format
802 (cond ((equal tramp-syntax
'ftp
) "#")
803 ((equal tramp-syntax
'sep
) "#")
804 (t (error "Wrong `tramp-syntax' defined")))
805 "String matching delimiter between host names and port numbers.")
807 (defconst tramp-prefix-port-regexp
808 (regexp-quote tramp-prefix-port-format
)
809 "Regexp matching delimiter between host names and port numbers.
810 Derived from `tramp-prefix-port-format'.")
812 (defconst tramp-port-regexp
"[0-9]+"
813 "Regexp matching port numbers.")
815 (defconst tramp-host-with-port-regexp
816 (concat "\\(" tramp-host-regexp
"\\)"
817 tramp-prefix-port-regexp
818 "\\(" tramp-port-regexp
"\\)")
819 "Regexp matching host names with port numbers.")
821 (defconst tramp-postfix-hop-format
"|"
822 "String matching delimiter after ad-hoc hop definitions.")
824 (defconst tramp-postfix-hop-regexp
825 (regexp-quote tramp-postfix-hop-format
)
826 "Regexp matching delimiter after ad-hoc hop definitions.
827 Derived from `tramp-postfix-hop-format'.")
829 (defconst tramp-postfix-host-format
830 (cond ((equal tramp-syntax
'ftp
) ":")
831 ((equal tramp-syntax
'sep
) "]")
832 (t (error "Wrong `tramp-syntax' defined")))
833 "String matching delimiter between host names and localnames.
834 Used in `tramp-make-tramp-file-name'.")
836 (defconst tramp-postfix-host-regexp
837 (regexp-quote tramp-postfix-host-format
)
838 "Regexp matching delimiter between host names and localnames.
839 Derived from `tramp-postfix-host-format'.")
841 (defconst tramp-localname-regexp
".*$"
842 "Regexp matching localnames.")
844 ;;; File name format:
846 (defconst tramp-remote-file-name-spec-regexp
848 "\\(?:" "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
"\\)?"
849 "\\(?:" "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
"\\)?"
850 "\\(" "\\(?:" tramp-host-regexp
"\\|"
851 tramp-prefix-ipv6-regexp tramp-ipv6-regexp
852 tramp-postfix-ipv6-regexp
"\\)"
853 "\\(?:" tramp-prefix-port-regexp tramp-port-regexp
"\\)?" "\\)?")
854 "Regular expression matching a Tramp file name between prefix and postfix.")
856 (defconst tramp-file-name-structure
860 "\\(" "\\(?:" tramp-remote-file-name-spec-regexp
861 tramp-postfix-hop-regexp
"\\)+" "\\)?"
862 tramp-remote-file-name-spec-regexp tramp-postfix-host-regexp
863 "\\(" tramp-localname-regexp
"\\)")
865 "List of six elements (REGEXP METHOD USER HOST FILE HOP), detailing \
866 the Tramp file name structure.
868 The first element REGEXP is a regular expression matching a Tramp file
869 name. The regex should contain parentheses around the method name,
870 the user name, the host name, and the file name parts.
872 The second element METHOD is a number, saying which pair of
873 parentheses matches the method name. The third element USER is
874 similar, but for the user name. The fourth element HOST is similar,
875 but for the host name. The fifth element FILE is for the file name.
876 The last element HOP is the ad-hoc hop definition, which could be a
877 cascade of several hops.
879 These numbers are passed directly to `match-string', which see. That
880 means the opening parentheses are counted to identify the pair.
882 See also `tramp-file-name-regexp'.")
885 (defconst tramp-file-name-regexp-unified
886 (if (memq system-type
'(cygwin windows-nt
))
887 "\\`/\\([^[/|:]\\{2,\\}\\|[^/|]\\{2,\\}]\\):"
888 "\\`/\\([^[/|:]+\\|[^/|]+]\\):")
889 "Value for `tramp-file-name-regexp' for unified remoting.
890 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
891 Tramp. See `tramp-file-name-structure' for more explanations.
893 On W32 systems, the volume letter must be ignored.")
896 (defconst tramp-file-name-regexp-separate
"\\`/\\[.*\\]"
897 "Value for `tramp-file-name-regexp' for separate remoting.
898 XEmacs uses a separate filename syntax for Tramp and EFS.
899 See `tramp-file-name-structure' for more explanations.")
902 (defconst tramp-file-name-regexp
903 (cond ((equal tramp-syntax
'ftp
) tramp-file-name-regexp-unified
)
904 ((equal tramp-syntax
'sep
) tramp-file-name-regexp-separate
)
905 (t (error "Wrong `tramp-syntax' defined")))
906 "Regular expression matching file names handled by Tramp.
907 This regexp should match Tramp file names but no other file names.
908 When tramp.el is loaded, this regular expression is prepended to
909 `file-name-handler-alist', and that is searched sequentially. Thus,
910 if the Tramp entry appears rather early in the `file-name-handler-alist'
911 and is a bit too general, then some files might be considered Tramp
912 files which are not really Tramp files.
914 Please note that the entry in `file-name-handler-alist' is made when
915 this file \(tramp.el\) is loaded. This means that this variable must be set
916 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
917 updated after changing this variable.
919 Also see `tramp-file-name-structure'.")
922 (defconst tramp-completion-file-name-regexp-unified
923 (if (memq system-type
'(cygwin windows-nt
))
924 "\\`/[^/]\\{2,\\}\\'" "\\`/[^/]*\\'")
925 "Value for `tramp-completion-file-name-regexp' for unified remoting.
926 GNU Emacs uses a unified filename syntax for Tramp and Ange-FTP.
927 See `tramp-file-name-structure' for more explanations.
929 On W32 systems, the volume letter must be ignored.")
932 (defconst tramp-completion-file-name-regexp-separate
933 "\\`/\\([[][^]]*\\)?\\'"
934 "Value for `tramp-completion-file-name-regexp' for separate remoting.
935 XEmacs uses a separate filename syntax for Tramp and EFS.
936 See `tramp-file-name-structure' for more explanations.")
939 (defconst tramp-completion-file-name-regexp
940 (cond ((equal tramp-syntax
'ftp
) tramp-completion-file-name-regexp-unified
)
941 ((equal tramp-syntax
'sep
) tramp-completion-file-name-regexp-separate
)
942 (t (error "Wrong `tramp-syntax' defined")))
943 "Regular expression matching file names handled by Tramp completion.
944 This regexp should match partial Tramp file names only.
946 Please note that the entry in `file-name-handler-alist' is made when
947 this file \(tramp.el\) is loaded. This means that this variable must be set
948 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
949 updated after changing this variable.
951 Also see `tramp-file-name-structure'.")
953 ;; Chunked sending kludge. We set this to 500 for black-listed constellations
954 ;; known to have a bug in `process-send-string'; some ssh connections appear
955 ;; to drop bytes when data is sent too quickly. There is also a connection
956 ;; buffer local variable, which is computed depending on remote host properties
957 ;; when `tramp-chunksize' is zero or nil.
958 (defcustom tramp-chunksize
959 (when (and (not (featurep 'xemacs
))
960 (memq system-type
'(hpux)))
962 ;; Parentheses in docstring starting at beginning of line are escaped.
963 ;; Fontification is messed up when
964 ;; `open-paren-in-column-0-is-defun-start' set to t.
965 "If non-nil, chunksize for sending input to local process.
966 It is necessary only on systems which have a buggy `process-send-string'
967 implementation. The necessity, whether this variable must be set, can be
968 checked via the following code:
971 (let* ((user \"xxx\") (host \"yyy\")
973 (sent init) (received init))
974 (while (= sent received)
975 (setq sent (+ sent step))
977 (let ((proc (start-process (buffer-name) (current-buffer)
978 \"ssh\" \"-l\" user host \"wc\" \"-c\")))
979 (when (memq (process-status proc) '(run open))
980 (process-send-string proc (make-string sent ?\\ ))
981 (process-send-eof proc)
982 (process-send-eof proc))
983 (while (not (progn (goto-char (point-min))
984 (re-search-forward \"\\\\w+\" (point-max) t)))
985 (accept-process-output proc 1))
986 (when (memq (process-status proc) '(run open))
987 (setq received (string-to-number (match-string 0)))
988 (delete-process proc)
989 (message \"Bytes sent: %s\\tBytes received: %s\" sent received)
991 (if (> sent (+ init step))
992 (message \"You should set `tramp-chunksize' to a maximum of %s\"
994 (message \"Test does not work\")
995 (display-buffer (current-buffer))
998 In the Emacs normally running Tramp, evaluate the above code
999 \(replace \"xxx\" and \"yyy\" by the remote user and host name,
1000 respectively\). You can do this, for example, by pasting it into
1001 the `*scratch*' buffer and then hitting C-j with the cursor after the
1002 last closing parenthesis. Note that it works only if you have configured
1003 \"ssh\" to run without password query, see ssh-agent\(1\).
1005 You will see the number of bytes sent successfully to the remote host.
1006 If that number exceeds 1000, you can stop the execution by hitting
1007 C-g, because your Emacs is likely clean.
1009 When it is necessary to set `tramp-chunksize', you might consider to
1010 use an out-of-the-band method \(like \"scp\"\) instead of an internal one
1011 \(like \"ssh\"\), because setting `tramp-chunksize' to non-nil decreases
1014 If your Emacs is buggy, the code stops and gives you an indication
1015 about the value `tramp-chunksize' should be set. Maybe you could just
1016 experiment a bit, e.g. changing the values of `init' and `step'
1017 in the third line of the code.
1019 Please raise a bug report via \"M-x tramp-bug\" if your system needs
1020 this variable to be set as well."
1022 :type
'(choice (const nil
) integer
))
1024 ;; Logging in to a remote host normally requires obtaining a pty. But
1025 ;; Emacs on MacOS X has process-connection-type set to nil by default,
1026 ;; so on those systems Tramp doesn't obtain a pty. Here, we allow
1027 ;; for an override of the system default.
1028 (defcustom tramp-process-connection-type t
1029 "Overrides `process-connection-type' for connections from Tramp.
1030 Tramp binds `process-connection-type' to the value given here before
1031 opening a connection to a remote host."
1033 :type
'(choice (const nil
) (const t
) (const pty
)))
1035 (defcustom tramp-connection-timeout
60
1036 "Defines the max time to wait for establishing a connection (in seconds).
1037 This can be overwritten for different connection types in `tramp-methods'."
1042 (defcustom tramp-connection-min-time-diff
5
1043 "Defines seconds between two consecutive connection attempts.
1044 This is necessary as self defense mechanism, in order to avoid
1045 yo-yo connection attempts when the remote host is unavailable.
1047 A value of 0 or `nil' suppresses this check. This might be
1048 necessary, when several out-of-order copy operations are
1049 performed, or when several asynchronous processes will be started
1050 in a short time frame. In those cases it is recommended to
1051 let-bind this variable."
1054 :type
'(choice (const nil
) integer
))
1056 (defcustom tramp-completion-reread-directory-timeout
10
1057 "Defines seconds since last remote command before rereading a directory.
1058 A remote directory might have changed its contents. In order to
1059 make it visible during file name completion in the minibuffer,
1060 Tramp flushes its cache and rereads the directory contents when
1061 more than `tramp-completion-reread-directory-timeout' seconds
1062 have been gone since last remote command execution. A value of `t'
1063 would require an immediate reread during filename completion, `nil'
1064 means to use always cached values for the directory contents."
1066 :type
'(choice (const nil
) (const t
) integer
))
1068 ;;; Internal Variables:
1070 (defvar tramp-current-method nil
1071 "Connection method for this *tramp* buffer.")
1073 (defvar tramp-current-user nil
1074 "Remote login name for this *tramp* buffer.")
1076 (defvar tramp-current-host nil
1077 "Remote host for this *tramp* buffer.")
1079 (defvar tramp-current-connection nil
1080 "Last connection timestamp.")
1083 (defconst tramp-completion-file-name-handler-alist
1084 '((file-name-all-completions . tramp-completion-handle-file-name-all-completions
)
1085 (file-name-completion . tramp-completion-handle-file-name-completion
))
1086 "Alist of completion handler functions.
1087 Used for file names matching `tramp-file-name-regexp'. Operations
1088 not mentioned here will be handled by Tramp's file name handler
1089 functions, or the normal Emacs functions.")
1091 ;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
1092 ;;;###tramp-autoload
1093 (defvar tramp-foreign-file-name-handler-alist nil
1094 "Alist of elements (FUNCTION . HANDLER) for foreign methods handled specially.
1095 If (FUNCTION FILENAME) returns non-nil, then all I/O on that file is done by
1098 ;;; Internal functions which must come first:
1100 (defsubst tramp-user-error
(vec-or-proc format
&rest args
)
1101 "Signal a pilot error."
1103 'tramp-error vec-or-proc
1104 (if (fboundp 'user-error
) 'user-error
'error
) format args
))
1106 ;; Conversion functions between external representation and
1107 ;; internal data structure. Convenience functions for internal
1110 (defun tramp-get-method-parameter (method param
)
1111 "Return the method parameter PARAM.
1112 If the `tramp-methods' entry does not exist, return nil."
1113 (let ((entry (assoc param
(assoc method tramp-methods
))))
1114 (when entry
(cadr entry
))))
1116 (defun tramp-file-name-p (vec)
1117 "Check, whether VEC is a Tramp object."
1118 (and (vectorp vec
) (= 5 (length vec
))))
1120 (defun tramp-file-name-method (vec)
1121 "Return method component of VEC."
1122 (and (tramp-file-name-p vec
) (aref vec
0)))
1124 (defun tramp-file-name-user (vec)
1125 "Return user component of VEC."
1126 (and (tramp-file-name-p vec
) (aref vec
1)))
1128 (defun tramp-file-name-host (vec)
1129 "Return host component of VEC."
1130 (and (tramp-file-name-p vec
) (aref vec
2)))
1132 (defun tramp-file-name-localname (vec)
1133 "Return localname component of VEC."
1134 (and (tramp-file-name-p vec
) (aref vec
3)))
1136 (defun tramp-file-name-hop (vec)
1137 "Return hop component of VEC."
1138 (and (tramp-file-name-p vec
) (aref vec
4)))
1140 ;; The user part of a Tramp file name vector can be of kind
1141 ;; "user%domain". Sometimes, we must extract these parts.
1142 (defun tramp-file-name-real-user (vec)
1143 "Return the user name of VEC without domain."
1145 (let ((user (tramp-file-name-user vec
)))
1146 (if (and (stringp user
)
1147 (string-match tramp-user-with-domain-regexp user
))
1148 (match-string 1 user
)
1151 (defun tramp-file-name-domain (vec)
1152 "Return the domain name of VEC."
1154 (let ((user (tramp-file-name-user vec
)))
1156 (string-match tramp-user-with-domain-regexp user
)
1157 (match-string 2 user
)))))
1159 ;; The host part of a Tramp file name vector can be of kind
1160 ;; "host#port". Sometimes, we must extract these parts.
1161 (defun tramp-file-name-real-host (vec)
1162 "Return the host name of VEC without port."
1164 (let ((host (tramp-file-name-host vec
)))
1165 (if (and (stringp host
)
1166 (string-match tramp-host-with-port-regexp host
))
1167 (match-string 1 host
)
1170 (defun tramp-file-name-port (vec)
1171 "Return the port number of VEC."
1173 (let ((method (tramp-file-name-method vec
))
1174 (host (tramp-file-name-host vec
)))
1175 (or (and (stringp host
)
1176 (string-match tramp-host-with-port-regexp host
)
1177 (string-to-number (match-string 2 host
)))
1178 (tramp-get-method-parameter method
'tramp-default-port
)))))
1180 ;;;###tramp-autoload
1181 (defun tramp-tramp-file-p (name)
1182 "Return t if NAME is a string with Tramp file name syntax."
1185 (string-match tramp-file-name-regexp name
))))
1187 ;; Obsoleted with Tramp 2.2.7.
1188 (defconst tramp-obsolete-methods
1189 '("ssh1" "ssh2" "scp1" "scp2" "scpc" "rsyncc" "plink1")
1190 "Obsolete methods.")
1192 (defvar tramp-warned-obsolete-methods nil
1193 "Which methods the user has been warned to be obsolete.")
1195 (defun tramp-find-method (method user host
)
1196 "Return the right method string to use.
1197 This is METHOD, if non-nil. Otherwise, do a lookup in
1198 `tramp-default-method-alist'. It maps also obsolete methods to
1202 (let ((choices tramp-default-method-alist
)
1205 (setq item
(pop choices
))
1206 (when (and (string-match (or (nth 0 item
) "") (or host
""))
1207 (string-match (or (nth 1 item
) "") (or user
"")))
1208 (setq lmethod
(nth 2 item
))
1209 (setq choices nil
)))
1211 tramp-default-method
)))
1212 ;; This is needed for a transition period only.
1213 (when (member result tramp-obsolete-methods
)
1214 (unless (member result tramp-warned-obsolete-methods
)
1216 (warn "Method %s is obsolete, using %s"
1217 result
(substring result
0 -
1))
1218 (unless (y-or-n-p (format "Method \"%s\" is obsolete, use \"%s\"? "
1219 result
(substring result
0 -
1)))
1220 (tramp-user-error nil
"Method \"%s\" not supported" result
)))
1221 (add-to-list 'tramp-warned-obsolete-methods result
))
1222 ;; This works with the current set of `tramp-obsolete-methods'.
1223 ;; Must be improved, if their are more sophisticated replacements.
1224 (setq result
(substring result
0 -
1)))
1225 ;; We must mark, whether a default value has been used. Not
1226 ;; applicable for XEmacs.
1227 (if (or method
(null result
) (null (functionp 'propertize
)))
1229 (tramp-compat-funcall 'propertize result
'tramp-default t
))))
1231 (defun tramp-find-user (method user host
)
1232 "Return the right user string to use.
1233 This is USER, if non-nil. Otherwise, do a lookup in
1234 `tramp-default-user-alist'."
1237 (let ((choices tramp-default-user-alist
)
1240 (setq item
(pop choices
))
1241 (when (and (string-match (or (nth 0 item
) "") (or method
""))
1242 (string-match (or (nth 1 item
) "") (or host
"")))
1243 (setq luser
(nth 2 item
))
1244 (setq choices nil
)))
1246 tramp-default-user
)))
1247 ;; We must mark, whether a default value has been used. Not
1248 ;; applicable for XEmacs.
1249 (if (or user
(null result
) (null (functionp 'propertize
)))
1251 (tramp-compat-funcall 'propertize result
'tramp-default t
))))
1253 (defun tramp-find-host (method user host
)
1254 "Return the right host string to use.
1255 This is HOST, if non-nil. Otherwise, it is `tramp-default-host'."
1256 (or (and (> (length host
) 0) host
)
1257 (let ((choices tramp-default-host-alist
)
1260 (setq item
(pop choices
))
1261 (when (and (string-match (or (nth 0 item
) "") (or method
""))
1262 (string-match (or (nth 1 item
) "") (or user
"")))
1263 (setq lhost
(nth 2 item
))
1264 (setq choices nil
)))
1266 tramp-default-host
))
1268 (defun tramp-check-proper-method-and-host (vec)
1269 "Check method and host name of VEC."
1270 (let ((method (tramp-file-name-method vec
))
1271 (user (tramp-file-name-user vec
))
1272 (host (tramp-file-name-host vec
))
1273 (methods (mapcar 'car tramp-methods
)))
1274 (when (and method
(not (member method methods
)))
1275 (tramp-cleanup-connection vec
)
1276 (tramp-user-error vec
"Unknown method \"%s\"" method
))
1277 (when (and (equal tramp-syntax
'ftp
) host
1278 (or (null method
) (get-text-property 0 'tramp-default method
))
1279 (or (null user
) (get-text-property 0 'tramp-default user
))
1280 (member host methods
))
1281 (tramp-cleanup-connection vec
)
1282 (tramp-user-error vec
"Host name must not match method \"%s\"" host
))))
1284 (defun tramp-dissect-file-name (name &optional nodefault
)
1285 "Return a `tramp-file-name' structure.
1286 The structure consists of remote method, remote user, remote host
1287 and localname (file name on remote host). If NODEFAULT is
1288 non-nil, the file name parts are not expanded to their default
1291 (let ((match (string-match (nth 0 tramp-file-name-structure
) name
)))
1292 (unless match
(tramp-user-error nil
"Not a Tramp file name: \"%s\"" name
))
1293 (let ((method (match-string (nth 1 tramp-file-name-structure
) name
))
1294 (user (match-string (nth 2 tramp-file-name-structure
) name
))
1295 (host (match-string (nth 3 tramp-file-name-structure
) name
))
1296 (localname (match-string (nth 4 tramp-file-name-structure
) name
))
1297 (hop (match-string (nth 5 tramp-file-name-structure
) name
)))
1299 (when (string-match tramp-prefix-ipv6-regexp host
)
1300 (setq host
(replace-match "" nil t host
)))
1301 (when (string-match tramp-postfix-ipv6-regexp host
)
1302 (setq host
(replace-match "" nil t host
))))
1304 (vector method user host localname hop
)
1306 (tramp-find-method method user host
)
1307 (tramp-find-user method user host
)
1308 (tramp-find-host method user host
)
1311 (defun tramp-buffer-name (vec)
1312 "A name for the connection buffer VEC."
1313 ;; We must use `tramp-file-name-real-host', because for gateway
1314 ;; methods the default port will be expanded later on, which would
1316 (let ((method (tramp-file-name-method vec
))
1317 (user (tramp-file-name-user vec
))
1318 (host (tramp-file-name-real-host vec
)))
1319 (if (not (zerop (length user
)))
1320 (format "*tramp/%s %s@%s*" method user host
)
1321 (format "*tramp/%s %s*" method host
))))
1323 (defun tramp-make-tramp-file-name (method user host localname
&optional hop
)
1324 "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME.
1325 When not nil, an optional HOP is prepended."
1326 (concat tramp-prefix-format hop
1327 (when (not (zerop (length method
)))
1328 (concat method tramp-postfix-method-format
))
1329 (when (not (zerop (length user
)))
1330 (concat user tramp-postfix-user-format
))
1332 (if (string-match tramp-ipv6-regexp host
)
1333 (concat tramp-prefix-ipv6-format host tramp-postfix-ipv6-format
)
1335 tramp-postfix-host-format
1336 (when localname localname
)))
1338 (defun tramp-completion-make-tramp-file-name (method user host localname
)
1339 "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME.
1340 It must not be a complete Tramp file name, but as long as there are
1341 necessary only. This function will be used in file name completion."
1342 (concat tramp-prefix-format
1343 (when (not (zerop (length method
)))
1344 (concat method tramp-postfix-method-format
))
1345 (when (not (zerop (length user
)))
1346 (concat user tramp-postfix-user-format
))
1347 (when (not (zerop (length host
)))
1349 (if (string-match tramp-ipv6-regexp host
)
1351 tramp-prefix-ipv6-format host tramp-postfix-ipv6-format
)
1353 tramp-postfix-host-format
))
1354 (when localname localname
)))
1356 (defun tramp-get-buffer (vec)
1357 "Get the connection buffer to be used for VEC."
1358 (or (get-buffer (tramp-buffer-name vec
))
1359 (with-current-buffer (get-buffer-create (tramp-buffer-name vec
))
1360 (setq buffer-undo-list t
)
1361 (setq default-directory
1362 (tramp-make-tramp-file-name
1363 (tramp-file-name-method vec
)
1364 (tramp-file-name-user vec
)
1365 (tramp-file-name-host vec
)
1369 (defun tramp-get-connection-buffer (vec)
1370 "Get the connection buffer to be used for VEC.
1371 In case a second asynchronous communication has been started, it is different
1372 from `tramp-get-buffer'."
1373 (or (tramp-get-connection-property vec
"process-buffer" nil
)
1374 (tramp-get-buffer vec
)))
1376 (defun tramp-get-connection-name (vec)
1377 "Get the connection name to be used for VEC.
1378 In case a second asynchronous communication has been started, it is different
1379 from the default one."
1380 (or (tramp-get-connection-property vec
"process-name" nil
)
1381 (tramp-buffer-name vec
)))
1383 (defun tramp-get-connection-process (vec)
1384 "Get the connection process to be used for VEC.
1385 In case a second asynchronous communication has been started, it is different
1386 from the default one."
1387 (get-process (tramp-get-connection-name vec
)))
1389 (defun tramp-debug-buffer-name (vec)
1390 "A name for the debug buffer for VEC."
1391 ;; We must use `tramp-file-name-real-host', because for gateway
1392 ;; methods the default port will be expanded later on, which would
1394 (let ((method (tramp-file-name-method vec
))
1395 (user (tramp-file-name-user vec
))
1396 (host (tramp-file-name-real-host vec
)))
1397 (if (not (zerop (length user
)))
1398 (format "*debug tramp/%s %s@%s*" method user host
)
1399 (format "*debug tramp/%s %s*" method host
))))
1401 (defconst tramp-debug-outline-regexp
1402 "[0-9]+:[0-9]+:[0-9]+\\.[0-9]+ [a-z0-9-]+ (\\([0-9]+\\)) #"
1403 "Used for highlighting Tramp debug buffers in `outline-mode'.")
1405 (defun tramp-debug-outline-level ()
1406 "Return the depth to which a statement is nested in the outline.
1407 Point must be at the beginning of a header line.
1409 The outline level is equal to the verbosity of the Tramp message."
1410 (1+ (string-to-number (match-string 1))))
1412 (defun tramp-get-debug-buffer (vec)
1413 "Get the debug buffer for VEC."
1414 (with-current-buffer
1415 (get-buffer-create (tramp-debug-buffer-name vec
))
1417 (setq buffer-undo-list t
)
1418 ;; So it does not get loaded while `outline-regexp' is let-bound.
1420 ;; Activate `outline-mode'. This runs `text-mode-hook' and
1421 ;; `outline-mode-hook'. We must prevent that local processes
1422 ;; die. Yes: I've seen `flyspell-mode', which starts "ispell".
1423 ;; Furthermore, `outline-regexp' must have the correct value
1424 ;; already, because it is used by `font-lock-compile-keywords'.
1425 (let ((default-directory (tramp-compat-temporary-file-directory))
1426 (outline-regexp tramp-debug-outline-regexp
))
1428 (set (make-local-variable 'outline-regexp
) tramp-debug-outline-regexp
)
1429 (set (make-local-variable 'outline-level
) 'tramp-debug-outline-level
))
1432 (defsubst tramp-debug-message
(vec fmt-string
&rest arguments
)
1433 "Append message to debug buffer.
1434 Message is formatted with FMT-STRING as control string and the remaining
1435 ARGUMENTS to actually emit the message (if applicable)."
1436 (with-current-buffer (tramp-get-debug-buffer vec
)
1437 (goto-char (point-max))
1442 ";; %sEmacs: %s Tramp: %s -*- mode: outline; -*-"
1443 (if (featurep 'sxemacs
) "SX" (if (featurep 'xemacs
) "X" "GNU "))
1444 emacs-version tramp-version
)))
1448 (let ((now (current-time)))
1449 (insert (format-time-string "%T." now
))
1450 (insert (format "%06d " (nth 2 now
))))
1451 ;; Calling Tramp function. We suppress compat and trace functions
1452 ;; from being displayed.
1453 (let ((btn 1) btf fn
)
1455 (setq btf
(nth 1 (backtrace-frame btn
)))
1459 (setq fn
(symbol-name btf
))
1462 (string-match "^tramp" fn
)
1469 "tramp-compat-condition-case-unless-debug"
1470 "tramp-compat-funcall"
1471 "tramp-compat-with-temp-message"
1472 "tramp-condition-case-unless-debug"
1473 "tramp-debug-message"
1475 "tramp-error-with-buffer"
1482 (setq btn
(1+ btn
))))
1483 ;; The following code inserts filename and line number. Should
1484 ;; be inactive by default, because it is time consuming.
1485 ; (let ((ffn (find-function-noselect (intern fn))))
1489 ; (file-name-nondirectory (buffer-file-name (car ffn)))
1490 ; (with-current-buffer (car ffn)
1491 ; (1+ (count-lines (point-min) (cdr ffn)))))))
1492 (insert (format "%s " fn
)))
1494 (insert (apply 'format fmt-string arguments
))))
1496 (defvar tramp-message-show-message t
1497 "Show Tramp message in the minibuffer.
1498 This variable is used to disable messages from `tramp-error'.
1499 The messages are visible anyway, because an error is raised.")
1501 (defsubst tramp-message
(vec-or-proc level fmt-string
&rest arguments
)
1502 "Emit a message depending on verbosity level.
1503 VEC-OR-PROC identifies the Tramp buffer to use. It can be either a
1504 vector or a process. LEVEL says to be quiet if `tramp-verbose' is
1505 less than LEVEL. The message is emitted only if `tramp-verbose' is
1506 greater than or equal to LEVEL.
1508 The message is also logged into the debug buffer when `tramp-verbose'
1509 is greater than or equal 4.
1511 Calls functions `message' and `tramp-debug-message' with FMT-STRING as
1512 control string and the remaining ARGUMENTS to actually emit the message (if
1515 (when (<= level tramp-verbose
)
1516 ;; Match data must be preserved!
1518 ;; Display only when there is a minimum level.
1519 (when (and tramp-message-show-message
(<= level
3))
1525 ((= level
2) "Warning: ")
1529 ;; Log only when there is a minimum level.
1530 (when (>= tramp-verbose
4)
1531 ;; Translate proc to vec.
1532 (when (processp vec-or-proc
)
1533 (let ((tramp-verbose 0))
1535 (tramp-get-connection-property vec-or-proc
"vector" nil
))))
1537 (when (vectorp vec-or-proc
)
1538 (apply 'tramp-debug-message
1540 (concat (format "(%d) # " level
) fmt-string
)
1543 (defsubst tramp-backtrace
(&optional vec-or-proc
)
1544 "Dump a backtrace into the debug buffer.
1545 If VEC-OR-PROC is nil, the buffer *debug tramp* is used. This
1546 function is meant for debugging purposes."
1548 (tramp-message vec-or-proc
10 "\n%s" (with-output-to-string (backtrace)))
1549 (if (>= tramp-verbose
10)
1550 (with-output-to-temp-buffer "*debug tramp*" (backtrace)))))
1552 (defsubst tramp-error
(vec-or-proc signal fmt-string
&rest arguments
)
1554 VEC-OR-PROC identifies the connection to use, SIGNAL is the
1555 signal identifier to be raised, remaining arguments passed to
1556 `tramp-message'. Finally, signal SIGNAL is raised."
1557 (let (tramp-message-show-message)
1558 (tramp-backtrace vec-or-proc
)
1561 (error-message-string
1563 (get signal
'error-message
)
1564 (apply 'format fmt-string arguments
))))
1565 (signal signal
(list (apply 'format fmt-string arguments
)))))
1567 (defsubst tramp-error-with-buffer
1568 (buf vec-or-proc signal fmt-string
&rest arguments
)
1569 "Emit an error, and show BUF.
1570 If BUF is nil, show the connection buf. Wait for 30\", or until
1571 an input event arrives. The other arguments are passed to `tramp-error'."
1572 (save-window-excursion
1573 (let* ((buf (or (and (bufferp buf
) buf
)
1574 (and (processp vec-or-proc
) (process-buffer vec-or-proc
))
1575 (and (vectorp vec-or-proc
)
1576 (tramp-get-connection-buffer vec-or-proc
))))
1577 (vec (or (and (vectorp vec-or-proc
) vec-or-proc
)
1578 (and buf
(with-current-buffer buf
1579 (tramp-dissect-file-name default-directory
))))))
1581 (apply 'tramp-error vec-or-proc signal fmt-string arguments
)
1584 tramp-message-show-message
1585 (not (zerop tramp-verbose
))
1586 (not (tramp-completion-mode-p)))
1587 (let ((enable-recursive-minibuffers t
))
1588 ;; `tramp-error' does not show messages. So we must do it
1590 (message fmt-string arguments
)
1595 ;; Reset timestamp. It would be wrong after waiting for a while.
1596 (when (equal (butlast (append vec nil
) 2)
1597 (car tramp-current-connection
))
1598 (setcdr tramp-current-connection
(current-time)))))))
1600 (defmacro with-parsed-tramp-file-name
(filename var
&rest body
)
1601 "Parse a Tramp filename and make components available in the body.
1603 First arg FILENAME is evaluated and dissected into its components.
1604 Second arg VAR is a symbol. It is used as a variable name to hold
1605 the filename structure. It is also used as a prefix for the variables
1606 holding the components. For example, if VAR is the symbol `foo', then
1607 `foo' will be bound to the whole structure, `foo-method' will be bound to
1608 the method component, and so on for `foo-user', `foo-host', `foo-localname',
1611 Remaining args are Lisp expressions to be evaluated (inside an implicit
1614 If VAR is nil, then we bind `v' to the structure and `method', `user',
1615 `host', `localname', `hop' to the components."
1617 (mapcar (lambda (elem)
1618 `(,(if var
(intern (format "%s-%s" var elem
)) elem
)
1619 (,(intern (format "tramp-file-name-%s" elem
))
1621 '(method user host localname hop
))))
1622 `(let* ((,(or var
'v
) (tramp-dissect-file-name ,filename
))
1624 ;; We don't know which of those vars will be used, so we bind them all,
1625 ;; and then add here a dummy use of all those variables, so we don't get
1626 ;; flooded by warnings about those vars `body' didn't use.
1627 (ignore ,@(mapcar #'car bindings
))
1630 (put 'with-parsed-tramp-file-name
'lisp-indent-function
2)
1631 (put 'with-parsed-tramp-file-name
'edebug-form-spec
'(form symbolp body
))
1632 (tramp-compat-font-lock-add-keywords
1633 'emacs-lisp-mode
'("\\<with-parsed-tramp-file-name\\>"))
1635 (defun tramp-progress-reporter-update (reporter &optional value
)
1636 (let* ((parameters (cdr reporter
))
1637 (message (aref parameters
3)))
1638 (when (string-match message
(or (current-message) ""))
1639 (tramp-compat-funcall 'progress-reporter-update reporter value
))))
1641 (defmacro with-tramp-progress-reporter
(vec level message
&rest body
)
1642 "Executes BODY, spinning a progress reporter with MESSAGE.
1643 If LEVEL does not fit for visible messages, there are only traces
1644 without a visible progress reporter."
1645 (declare (indent 3) (debug t
))
1647 (tramp-message ,vec
,level
"%s..." ,message
)
1648 (let ((cookie "failed")
1650 ;; We start a pulsing progress reporter after 3 seconds. Feature
1651 ;; introduced in Emacs 24.1.
1652 (when (and tramp-message-show-message
1653 ;; Display only when there is a minimum level.
1654 (<= ,level
(min tramp-verbose
3)))
1656 (let ((pr (tramp-compat-funcall
1657 #'make-progress-reporter
,message
)))
1660 #'tramp-progress-reporter-update pr
)))))))
1662 ;; Execute the body.
1663 (prog1 (progn ,@body
) (setq cookie
"done"))
1664 ;; Stop progress reporter.
1665 (if tm
(tramp-compat-funcall 'cancel-timer tm
))
1666 (tramp-message ,vec
,level
"%s...%s" ,message cookie
)))))
1668 (tramp-compat-font-lock-add-keywords
1669 'emacs-lisp-mode
'("\\<with-tramp-progress-reporter\\>"))
1671 (defmacro with-tramp-file-property
(vec file property
&rest body
)
1672 "Check in Tramp cache for PROPERTY, otherwise execute BODY and set cache.
1673 FILE must be a local file name on a connection identified via VEC."
1674 `(if (file-name-absolute-p ,file
)
1675 (let ((value (tramp-get-file-property ,vec
,file
,property
'undef
)))
1676 (when (eq value
'undef
)
1677 ;; We cannot pass @body as parameter to
1678 ;; `tramp-set-file-property' because it mangles our
1680 (setq value
(progn ,@body
))
1681 (tramp-set-file-property ,vec
,file
,property value
))
1685 (put 'with-tramp-file-property
'lisp-indent-function
3)
1686 (put 'with-tramp-file-property
'edebug-form-spec t
)
1687 (tramp-compat-font-lock-add-keywords
1688 'emacs-lisp-mode
'("\\<with-tramp-file-property\\>"))
1690 (defmacro with-tramp-connection-property
(key property
&rest body
)
1691 "Check in Tramp for property PROPERTY, otherwise executes BODY and set."
1692 `(let ((value (tramp-get-connection-property ,key
,property
'undef
)))
1693 (when (eq value
'undef
)
1694 ;; We cannot pass ,@body as parameter to
1695 ;; `tramp-set-connection-property' because it mangles our debug
1697 (setq value
(progn ,@body
))
1698 (tramp-set-connection-property ,key
,property value
))
1701 (put 'with-tramp-connection-property
'lisp-indent-function
2)
1702 (put 'with-tramp-connection-property
'edebug-form-spec t
)
1703 (tramp-compat-font-lock-add-keywords
1704 'emacs-lisp-mode
'("\\<with-tramp-connection-property\\>"))
1706 (defun tramp-drop-volume-letter (name)
1707 "Cut off unnecessary drive letter from file NAME.
1708 The functions `tramp-*-handle-expand-file-name' call `expand-file-name'
1709 locally on a remote file name. When the local system is a W32 system
1710 but the remote system is Unix, this introduces a superfluous drive
1711 letter into the file name. This function removes it."
1713 (if (string-match "\\`[a-zA-Z]:/" name
)
1714 (replace-match "/" nil t name
)
1717 ;;; Config Manipulation Functions:
1719 ;;;###tramp-autoload
1720 (defun tramp-set-completion-function (method function-list
)
1721 "Sets the list of completion functions for METHOD.
1722 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
1723 The FUNCTION is intended to parse FILE according its syntax.
1724 It might be a predefined FUNCTION, or a user defined FUNCTION.
1725 For the list of predefined FUNCTIONs see `tramp-completion-function-alist'.
1729 (tramp-set-completion-function
1731 '((tramp-parse-sconfig \"/etc/ssh_config\")
1732 (tramp-parse-sconfig \"~/.ssh/config\")))"
1734 (let ((r function-list
)
1736 (setq tramp-completion-function-alist
1737 (delete (assoc method tramp-completion-function-alist
)
1738 tramp-completion-function-alist
))
1741 ;; Remove double entries.
1742 (when (member (car v
) (cdr v
))
1743 (setcdr v
(delete (car v
) (cdr v
))))
1744 ;; Check for function and file or registry key.
1745 (unless (and (functionp (nth 0 (car v
)))
1746 (if (string-match "^HKEY_CURRENT_USER" (nth 1 (car v
)))
1747 ;; Windows registry.
1748 (and (memq system-type
'(cygwin windows-nt
))
1751 "reg" nil nil nil
"query" (nth 1 (car v
)))))
1752 ;; Configuration file.
1753 (file-exists-p (nth 1 (car v
)))))
1754 (setq r
(delete (car v
) r
)))
1758 (add-to-list 'tramp-completion-function-alist
1761 (defun tramp-get-completion-function (method)
1762 "Returns a list of completion functions for METHOD.
1763 For definition of that list see `tramp-set-completion-function'."
1765 ;; Hosts visited once shall be remembered.
1766 `(tramp-parse-connection-properties ,method
)
1767 ;; The method related defaults.
1768 (cdr (assoc method tramp-completion-function-alist
))))
1771 ;;; Fontification of `read-file-name':
1773 ;; rfn-eshadow.el is part of Emacs 22. It is autoloaded.
1774 (defvar tramp-rfn-eshadow-overlay
)
1775 (make-variable-buffer-local 'tramp-rfn-eshadow-overlay
)
1777 (defun tramp-rfn-eshadow-setup-minibuffer ()
1778 "Set up a minibuffer for `file-name-shadow-mode'.
1779 Adds another overlay hiding filename parts according to Tramp's
1780 special handling of `substitute-in-file-name'."
1781 (when (symbol-value 'minibuffer-completing-file-name
)
1782 (setq tramp-rfn-eshadow-overlay
1783 (tramp-compat-funcall
1785 (tramp-compat-funcall 'minibuffer-prompt-end
)
1786 (tramp-compat-funcall 'minibuffer-prompt-end
)))
1787 ;; Copy rfn-eshadow-overlay properties.
1788 (let ((props (tramp-compat-funcall
1789 'overlay-properties
(symbol-value 'rfn-eshadow-overlay
))))
1791 ;; The `field' property prevents correct minibuffer
1792 ;; completion; we exclude it.
1793 (if (not (eq (car props
) 'field
))
1794 (tramp-compat-funcall
1795 'overlay-put tramp-rfn-eshadow-overlay
(pop props
) (pop props
))
1796 (pop props
) (pop props
))))))
1798 (when (boundp 'rfn-eshadow-setup-minibuffer-hook
)
1799 (add-hook 'rfn-eshadow-setup-minibuffer-hook
1800 'tramp-rfn-eshadow-setup-minibuffer
)
1801 (add-hook 'tramp-unload-hook
1803 (remove-hook 'rfn-eshadow-setup-minibuffer-hook
1804 'tramp-rfn-eshadow-setup-minibuffer
))))
1806 (defconst tramp-rfn-eshadow-update-overlay-regexp
1807 (format "[^%s/~]*\\(/\\|~\\)" tramp-postfix-host-format
))
1809 (defun tramp-rfn-eshadow-update-overlay ()
1810 "Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input.
1811 This is intended to be used as a minibuffer `post-command-hook' for
1812 `file-name-shadow-mode'; the minibuffer should have already
1813 been set up by `rfn-eshadow-setup-minibuffer'."
1814 ;; In remote files name, there is a shadowing just for the local part.
1816 (let ((end (or (tramp-compat-funcall
1817 'overlay-end
(symbol-value 'rfn-eshadow-overlay
))
1818 (tramp-compat-funcall 'minibuffer-prompt-end
)))
1819 ;; We do not want to send any remote command.
1823 (tramp-compat-funcall
1824 'buffer-substring-no-properties end
(point-max)))
1828 (1+ (or (string-match
1829 tramp-rfn-eshadow-update-overlay-regexp
1830 (buffer-string) end
)
1833 (let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay
)
1834 (rfn-eshadow-update-overlay-hook nil
)
1835 file-name-handler-alist
)
1836 (tramp-compat-funcall
1837 'move-overlay rfn-eshadow-overlay
(point-max) (point-max))
1838 (tramp-compat-funcall 'rfn-eshadow-update-overlay
))))))))
1840 (when (boundp 'rfn-eshadow-update-overlay-hook
)
1841 (add-hook 'rfn-eshadow-update-overlay-hook
1842 'tramp-rfn-eshadow-update-overlay
)
1843 (add-hook 'tramp-unload-hook
1845 (remove-hook 'rfn-eshadow-update-overlay-hook
1846 'tramp-rfn-eshadow-update-overlay
))))
1848 ;; Inodes don't exist for some file systems. Therefore we must
1849 ;; generate virtual ones. Used in `find-buffer-visiting'. The method
1850 ;; applied might be not so efficient (Ange-FTP uses hashes). But
1851 ;; performance isn't the major issue given that file transfer will
1853 (defvar tramp-inodes
0
1854 "Keeps virtual inodes numbers.")
1856 ;; Devices must distinguish physical file systems. The device numbers
1857 ;; provided by "lstat" aren't unique, because we operate on different hosts.
1858 ;; So we use virtual device numbers, generated by Tramp. Both Ange-FTP and
1859 ;; EFS use device number "-1". In order to be different, we use device number
1860 ;; (-1 . x), whereby "x" is unique for a given (method user host).
1861 (defvar tramp-devices
0
1862 "Keeps virtual device numbers.")
1864 (defun tramp-default-file-modes (filename)
1865 "Return file modes of FILENAME as integer.
1866 If the file modes of FILENAME cannot be determined, return the
1867 value of `default-file-modes', without execute permissions."
1868 (or (file-modes filename
)
1869 (logand (default-file-modes) (tramp-compat-octal-to-decimal "0666"))))
1871 (defun tramp-replace-environment-variables (filename)
1872 "Replace environment variables in FILENAME.
1873 Return the string with the replaced variables."
1875 (tramp-compat-funcall 'substitute-env-vars filename
'only-defined
))
1876 ;; We need an own implementation.
1878 (let ((idx (string-match "$\\(\\w+\\)" filename
)))
1879 ;; `$' is coded as `$$'.
1881 (or (zerop idx
) (not (eq ?$
(aref filename
(1- idx
)))))
1882 (getenv (match-string 1 filename
)))
1885 (substitute-in-file-name (match-string 0 filename
))
1889 ;; In XEmacs, electricity is implemented via a key map for ?/ and ?~,
1890 ;; which calls corresponding functions (see minibuf.el).
1891 (when (fboundp 'minibuffer-electric-separator
)
1896 (around ,(intern (format "tramp-advice-%s" x
)) activate
)
1897 "Invoke `substitute-in-file-name' for Tramp files."
1898 (if (and (symbol-value 'minibuffer-electric-file-name-behavior
)
1899 (tramp-tramp-file-p (buffer-substring)))
1900 ;; We don't need to handle `last-input-event', because
1901 ;; due to the key map we know it must be ?/ or ?~.
1902 (let ((s (concat (buffer-substring (point-min) (point))
1903 (string last-command-char
))))
1904 (delete-region (point-min) (point))
1905 (insert (substitute-in-file-name s
))
1906 (setq ad-return-value last-command-char
))
1912 (ad-remove-advice ',x
'around
',(intern (format "tramp-advice-%s" x
)))
1913 (ad-activate ',x
)))))
1915 '(minibuffer-electric-separator
1916 minibuffer-electric-tilde
)))
1918 (defun tramp-find-file-name-coding-system-alist (filename tmpname
)
1919 "Like `find-operation-coding-system' for Tramp filenames.
1920 Tramp's `insert-file-contents' and `write-region' work over
1921 temporary file names. If `file-coding-system-alist' contains an
1922 expression, which matches more than the file name suffix, the
1923 coding system might not be determined. This function repairs it."
1925 (dolist (elt file-coding-system-alist result
)
1926 (when (and (consp elt
) (string-match (car elt
) filename
))
1927 ;; We found a matching entry in `file-coding-system-alist'.
1928 ;; So we add a similar entry, but with the temporary file name
1931 'result
(cons (regexp-quote tmpname
) (cdr elt
)) 'append
)))))
1934 (progn (defun tramp-run-real-handler (operation args
)
1935 "Invoke normal file name handler for OPERATION.
1936 First arg specifies the OPERATION, second arg is a list of arguments to
1937 pass to the OPERATION."
1938 (let* ((inhibit-file-name-handlers
1939 `(tramp-file-name-handler
1940 tramp-vc-file-name-handler
1941 tramp-completion-file-name-handler
1942 cygwin-mount-name-hook-function
1943 cygwin-mount-map-drive-hook-function
1945 ,(and (eq inhibit-file-name-operation operation
)
1946 inhibit-file-name-handlers
)))
1947 (inhibit-file-name-operation operation
))
1948 (apply operation args
))))
1951 (progn (defun tramp-completion-run-real-handler (operation args
)
1952 "Invoke `tramp-file-name-handler' for OPERATION.
1953 First arg specifies the OPERATION, second arg is a list of arguments to
1954 pass to the OPERATION."
1955 (let* ((inhibit-file-name-handlers
1956 `(tramp-completion-file-name-handler
1957 cygwin-mount-name-hook-function
1958 cygwin-mount-map-drive-hook-function
1960 ,(and (eq inhibit-file-name-operation operation
)
1961 inhibit-file-name-handlers
)))
1962 (inhibit-file-name-operation operation
))
1963 (apply operation args
))))
1965 ;; We handle here all file primitives. Most of them have the file
1966 ;; name as first parameter; nevertheless we check for them explicitly
1967 ;; in order to be signaled if a new primitive appears. This
1968 ;; scenario is needed because there isn't a way to decide by
1969 ;; syntactical means whether a foreign method must be called. It would
1970 ;; ease the life if `file-name-handler-alist' would support a decision
1971 ;; function as well but regexp only.
1972 (defun tramp-file-name-for-operation (operation &rest args
)
1973 "Return file name related to OPERATION file primitive.
1974 ARGS are the arguments OPERATION has been called with."
1976 ;; FILE resp DIRECTORY.
1978 (list 'access-file
'byte-compiler-base-file-name
'delete-directory
1979 'delete-file
'diff-latest-backup-file
'directory-file-name
1980 'directory-files
'directory-files-and-attributes
1981 'dired-compress-file
'dired-uncache
1982 'file-accessible-directory-p
'file-attributes
1983 'file-directory-p
'file-executable-p
'file-exists-p
1984 'file-local-copy
'file-modes
1985 'file-name-as-directory
'file-name-directory
1986 'file-name-nondirectory
'file-name-sans-versions
1987 'file-ownership-preserved-p
'file-readable-p
1988 'file-regular-p
'file-remote-p
'file-symlink-p
'file-truename
1989 'file-writable-p
'find-backup-file-name
'find-file-noselect
1990 'get-file-buffer
'insert-directory
'insert-file-contents
1991 'load
'make-directory
'make-directory-internal
1992 'set-file-modes
'substitute-in-file-name
1993 'unhandled-file-name-directory
'vc-registered
1997 'file-acl
'file-notify-add-watch
1998 'file-selinux-context
'set-file-acl
'set-file-selinux-context
2000 'abbreviate-file-name
'create-file-buffer
2001 'dired-file-modtime
'dired-make-compressed-filename
2002 'dired-recursive-delete-directory
'dired-set-file-modtime
2003 'dired-shell-unhandle-file-name
'dired-uucode-file
2004 'insert-file-contents-literally
'make-temp-name
'recover-file
2005 'vm-imap-check-mail
'vm-pop-check-mail
'vm-spool-check-mail
))
2006 (if (file-name-absolute-p (nth 0 args
))
2008 (expand-file-name (nth 0 args
))))
2009 ;; FILE DIRECTORY resp FILE1 FILE2.
2011 (list 'add-name-to-file
'copy-file
'expand-file-name
2012 'file-name-all-completions
'file-name-completion
2013 'file-newer-than-file-p
'make-symbolic-link
'rename-file
2017 'file-equal-p
'file-in-directory-p
2019 'dired-make-relative-symlink
2020 'vm-imap-move-mail
'vm-pop-move-mail
'vm-spool-move-mail
))
2023 ((string-match tramp-file-name-regexp
(nth 0 args
)) (nth 0 args
))
2024 ((string-match tramp-file-name-regexp
(nth 1 args
)) (nth 1 args
))
2025 (t (buffer-file-name (current-buffer))))))
2027 ((eq operation
'write-region
)
2031 (list 'set-visited-file-modtime
'verify-visited-file-modtime
2033 'make-auto-save-file-name
2037 (if (bufferp (nth 0 args
)) (nth 0 args
) (current-buffer))))
2040 (list ;; not in Emacs 23+.
2049 'dired-print-file
'dired-shell-call-process
))
2052 ((eq operation
'file-notify-rm-watch
)
2053 (when (processp (nth 0 args
))
2054 (with-current-buffer (process-buffer (nth 0 args
))
2055 default-directory
)))
2056 ;; Unknown file primitive.
2057 (t (error "unknown file I/O primitive: %s" operation
))))
2059 (defun tramp-find-foreign-file-name-handler (filename)
2060 "Return foreign file name handler if exists."
2061 (when (tramp-tramp-file-p filename
)
2062 (let ((v (tramp-dissect-file-name filename t
))
2063 (handler tramp-foreign-file-name-handler-alist
)
2065 ;; When we are not fully sure that filename completion is safe,
2066 ;; we should not return a handler.
2067 (when (or (tramp-file-name-method v
) (tramp-file-name-user v
)
2068 (and (tramp-file-name-host v
)
2069 (not (member (tramp-file-name-host v
)
2070 (mapcar 'car tramp-methods
))))
2071 (not (tramp-completion-mode-p)))
2073 (setq elt
(car handler
)
2074 handler
(cdr handler
))
2075 (when (funcall (car elt
) filename
)
2080 (defvar tramp-debug-on-error nil
2081 "Like `debug-on-error' but used Tramp internal.")
2083 (defmacro tramp-condition-case-unless-debug
2084 (var bodyform
&rest handlers
)
2085 "Like `condition-case-unless-debug' but `tramp-debug-on-error'."
2086 `(let ((debug-on-error tramp-debug-on-error
))
2087 (tramp-compat-condition-case-unless-debug ,var
,bodyform
,@handlers
)))
2091 (defun tramp-file-name-handler (operation &rest args
)
2092 "Invoke Tramp file name handler.
2093 Falls back to normal file name handler if no Tramp file name handler exists."
2097 (tramp-replace-environment-variables
2098 (apply 'tramp-file-name-for-operation operation args
)))
2099 (completion (tramp-completion-mode-p))
2100 (foreign (tramp-find-foreign-file-name-handler filename
)))
2101 (with-parsed-tramp-file-name filename nil
2102 ;; Call the backend function.
2104 (tramp-condition-case-unless-debug err
2105 (let ((sf (symbol-function foreign
))
2107 ;; Some packages set the default directory to a
2108 ;; remote path, before respective Tramp packages
2109 ;; are already loaded. This results in
2110 ;; recursive loading. Therefore, we load the
2111 ;; Tramp packages locally.
2112 (when (and (listp sf
) (eq (car sf
) 'autoload
))
2113 (let ((default-directory
2114 (tramp-compat-temporary-file-directory)))
2115 (load (cadr sf
) 'noerror
'nomessage
)))
2116 ;; If `non-essential' is non-nil, Tramp shall
2117 ;; not open a new connection.
2118 ;; If Tramp detects that it shouldn't continue
2119 ;; to work, it throws the `suppress' event.
2120 ;; This could happen for example, when Tramp
2121 ;; tries to open the same connection twice in a
2122 ;; short time frame.
2123 ;; In both cases, we try the default handler then.
2125 (catch 'non-essential
2127 (apply foreign operation args
))))
2129 ((eq result
'non-essential
)
2131 v
5 "Non-essential received in operation %s"
2132 (append (list operation
) args
))
2133 (tramp-run-real-handler operation args
))
2134 ((eq result
'suppress
)
2135 (let (tramp-message-show-message)
2137 v
1 "Suppress received in operation %s"
2138 (append (list operation
) args
))
2139 (tramp-cleanup-connection v t
)
2140 (tramp-run-real-handler operation args
)))
2143 ;; Trace that somebody has interrupted the operation.
2145 (let (tramp-message-show-message)
2147 v
1 "Interrupt received in operation %s"
2148 (append (list operation
) args
)))
2149 ;; Propagate the quit signal.
2150 (signal (car err
) (cdr err
)))
2152 ;; When we are in completion mode, some failed
2153 ;; operations shall return at least a default value
2154 ;; in order to give the user a chance to correct the
2155 ;; file name in the minibuffer.
2156 ;; In order to get a full backtrace, one could apply
2157 ;; (setq tramp-debug-on-error t)
2160 ((and completion
(zerop (length localname
))
2161 (memq operation
'(file-exists-p file-directory-p
)))
2163 ((and completion
(zerop (length localname
))
2165 '(expand-file-name file-name-as-directory
)))
2167 ;; Propagate the error.
2168 (t (signal (car err
) (cdr err
))))))
2170 ;; Nothing to do for us.
2171 (tramp-run-real-handler operation args
)))))
2173 ;; When `tramp-mode' is not enabled, we don't do anything.
2174 (tramp-run-real-handler operation args
)))
2176 ;; In Emacs, there is some concurrency due to timers. If a timer
2177 ;; interrupts Tramp and wishes to use the same connection buffer as
2178 ;; the "main" Emacs, then garbage might occur in the connection
2179 ;; buffer. Therefore, we need to make sure that a timer does not use
2180 ;; the same connection buffer as the "main" Emacs. We implement a
2181 ;; cheap global lock, instead of locking each connection buffer
2182 ;; separately. The global lock is based on two variables,
2183 ;; `tramp-locked' and `tramp-locker'. `tramp-locked' is set to true
2184 ;; (with setq) to indicate a lock. But Tramp also calls itself during
2185 ;; processing of a single file operation, so we need to allow
2186 ;; recursive calls. That's where the `tramp-locker' variable comes in
2187 ;; -- it is let-bound to t during the execution of the current
2188 ;; handler. So if `tramp-locked' is t and `tramp-locker' is also t,
2189 ;; then we should just proceed because we have been called
2190 ;; recursively. But if `tramp-locker' is nil, then we are a timer
2191 ;; interrupting the "main" Emacs, and then we signal an error.
2193 (defvar tramp-locked nil
2194 "If non-nil, then Tramp is currently busy.
2195 Together with `tramp-locker', this implements a locking mechanism
2196 preventing reentrant calls of Tramp.")
2198 (defvar tramp-locker nil
2199 "If non-nil, then a caller has locked Tramp.
2200 Together with `tramp-locked', this implements a locking mechanism
2201 preventing reentrant calls of Tramp.")
2204 (progn (defun tramp-completion-file-name-handler (operation &rest args
)
2205 "Invoke Tramp file name completion handler.
2206 Falls back to normal file name handler if no Tramp file name handler exists."
2207 ;; We bind `directory-sep-char' here for XEmacs on Windows, which
2208 ;; would otherwise use backslash.
2209 (let ((directory-sep-char ?
/)
2210 (fn (assoc operation tramp-completion-file-name-handler-alist
)))
2212 ;; When `tramp-mode' is not enabled, we don't do anything.
2214 ;; For other syntaxes than `sep', the regexp matches many common
2215 ;; situations where the user doesn't actually want to use Tramp.
2216 ;; So to avoid autoloading Tramp after typing just "/s", we
2217 ;; disable this part of the completion, unless the user implicitly
2218 ;; indicated his interest in using a fancier completion system.
2219 (or (eq tramp-syntax
'sep
)
2220 (featurep 'tramp
) ;; If it's loaded, we may as well use it.
2221 ;; `partial-completion-mode' does not exist in XEmacs.
2222 ;; It is obsoleted with Emacs 24.1.
2223 (and (boundp 'partial-completion-mode
)
2224 (symbol-value 'partial-completion-mode
))
2225 ;; FIXME: These may have been loaded even if the user never
2226 ;; intended to use them.
2228 (featurep 'icicles
)))
2229 (save-match-data (apply (cdr fn
) args
))
2230 (tramp-completion-run-real-handler operation args
)))))
2233 (progn (defun tramp-register-file-name-handlers ()
2234 "Add Tramp file name handlers to `file-name-handler-alist'."
2235 ;; Remove autoloaded handlers from file name handler alist. Useful,
2236 ;; if `tramp-syntax' has been changed.
2237 (let ((a1 (rassq 'tramp-file-name-handler file-name-handler-alist
)))
2238 (setq file-name-handler-alist
(delq a1 file-name-handler-alist
)))
2240 'tramp-completion-file-name-handler file-name-handler-alist
)))
2241 (setq file-name-handler-alist
(delq a1 file-name-handler-alist
)))
2242 ;; Add the handlers.
2243 (add-to-list 'file-name-handler-alist
2244 (cons tramp-file-name-regexp
'tramp-file-name-handler
))
2245 (put 'tramp-file-name-handler
'safe-magic t
)
2246 (add-to-list 'file-name-handler-alist
2247 (cons tramp-completion-file-name-regexp
2248 'tramp-completion-file-name-handler
))
2249 (put 'tramp-completion-file-name-handler
'safe-magic t
)
2250 ;; If jka-compr or epa-file are already loaded, move them to the
2251 ;; front of `file-name-handler-alist'.
2252 (dolist (fnh '(epa-file-handler jka-compr-handler
))
2253 (let ((entry (rassoc fnh file-name-handler-alist
)))
2255 (setq file-name-handler-alist
2256 (cons entry
(delete entry file-name-handler-alist
))))))))
2258 ;; `tramp-file-name-handler' must be registered before evaluation of
2259 ;; site-start and init files, because there might exist remote files
2260 ;; already, f.e. files kept via recentf-mode.
2262 (tramp-register-file-name-handlers)
2264 (defun tramp-exists-file-name-handler (operation &rest args
)
2265 "Check, whether OPERATION runs a file name handler."
2266 ;; The file name handler is determined on base of either an
2267 ;; argument, `buffer-file-name', or `default-directory'.
2269 (let* ((buffer-file-name "/")
2270 (default-directory "/")
2271 (fnha file-name-handler-alist
)
2272 (check-file-name-operation operation
)
2273 (file-name-handler-alist
2276 (lambda (operation &rest args
)
2277 "Returns OPERATION if it is the one to be checked."
2278 (if (equal check-file-name-operation operation
)
2280 (let ((file-name-handler-alist fnha
))
2281 (apply operation args
))))))))
2282 (equal (apply operation args
) operation
))))
2285 (defun tramp-unload-file-name-handlers ()
2286 (setq file-name-handler-alist
2287 (delete (rassoc 'tramp-file-name-handler
2288 file-name-handler-alist
)
2289 (delete (rassoc 'tramp-completion-file-name-handler
2290 file-name-handler-alist
)
2291 file-name-handler-alist
))))
2293 (add-hook 'tramp-unload-hook
'tramp-unload-file-name-handlers
)
2295 ;;; File name handler functions for completion mode:
2297 (defvar tramp-completion-mode nil
2298 "If non-nil, external packages signal that they are in file name completion.
2300 This is necessary, because Tramp uses a heuristic depending on last
2301 input event. This fails when external packages use other characters
2302 but <TAB>, <SPACE> or ?\\? for file name completion. This variable
2303 should never be set globally, the intention is to let-bind it.")
2305 ;; Necessary because `tramp-file-name-regexp-unified' and
2306 ;; `tramp-completion-file-name-regexp-unified' aren't different. If
2307 ;; nil, `tramp-completion-run-real-handler' is called (i.e. forwarding
2308 ;; to `tramp-file-name-handler'). Otherwise, it takes
2309 ;; `tramp-run-real-handler'. Using `last-input-event' is a little bit
2310 ;; risky, because completing a file might require loading other files,
2311 ;; like "~/.netrc", and for them it shouldn't be decided based on that
2312 ;; variable. On the other hand, those files shouldn't have partial
2313 ;; Tramp file name syntax. Maybe another variable should be introduced
2314 ;; overwriting this check in such cases. Or we change Tramp file name
2315 ;; syntax in order to avoid ambiguities, like in XEmacs ...
2316 ;;;###tramp-autoload
2317 (defun tramp-completion-mode-p ()
2318 "Check, whether method / user name / host name completion is active."
2320 ;; Signal from outside. `non-essential' has been introduced in Emacs 24.
2321 (and (boundp 'non-essential
) (symbol-value 'non-essential
))
2322 tramp-completion-mode
2324 (equal last-input-event
'tab
)
2325 (and (natnump last-input-event
)
2327 ;; ?\t has event-modifier 'control.
2328 (equal last-input-event ?
\t)
2329 (and (not (event-modifiers last-input-event
))
2330 (or (equal last-input-event ?
\?)
2331 (equal last-input-event ?\
)))))
2333 (and (featurep 'xemacs
)
2334 ;; `last-input-event' might be nil.
2335 (not (null last-input-event
))
2336 ;; `last-input-event' may have no character approximation.
2337 (tramp-compat-funcall 'event-to-character last-input-event
)
2339 ;; ?\t has event-modifier 'control.
2341 (tramp-compat-funcall 'event-to-character last-input-event
) ?
\t)
2342 (and (not (event-modifiers last-input-event
))
2344 (tramp-compat-funcall 'event-to-character last-input-event
)
2347 (tramp-compat-funcall 'event-to-character last-input-event
)
2350 (defun tramp-connectable-p (filename)
2351 "Check, whether it is possible to connect the remote host w/o side-effects.
2352 This is true, if either the remote host is already connected, or if we are
2353 not in completion mode."
2354 (and (tramp-tramp-file-p filename
)
2355 (with-parsed-tramp-file-name filename nil
2356 (or (not (tramp-completion-mode-p))
2357 (let* ((tramp-verbose 0)
2358 (p (tramp-get-connection-process v
)))
2359 (and p
(processp p
) (memq (process-status p
) '(run open
))))))))
2361 ;; Method, host name and user name completion.
2362 ;; `tramp-completion-dissect-file-name' returns a list of
2363 ;; tramp-file-name structures. For all of them we return possible completions.
2365 (defun tramp-completion-handle-file-name-all-completions (filename directory
)
2366 "Like `file-name-all-completions' for partial Tramp files."
2369 (tramp-drop-volume-letter (expand-file-name filename directory
)))
2372 ;; Suppress hop from completion.
2376 "\\(" "\\(" tramp-remote-file-name-spec-regexp
2377 tramp-postfix-hop-regexp
2380 (setq hop
(match-string 1 fullname
)
2381 fullname
(replace-match "" nil nil fullname
1)))
2383 ;; Possible completion structures.
2384 (dolist (elt (tramp-completion-dissect-file-name fullname
))
2385 (let* ((method (tramp-file-name-method elt
))
2386 (user (tramp-file-name-user elt
))
2387 (host (tramp-file-name-host elt
))
2388 (localname (tramp-file-name-localname elt
))
2389 (m (tramp-find-method method user host
))
2390 (tramp-current-user user
) ; see `tramp-parse-passwd'
2393 (unless localname
;; Nothing to complete.
2397 ;; Method dependent user / host combinations.
2401 (setq all-user-hosts
2402 (append all-user-hosts
2403 (funcall (nth 0 x
) (nth 1 x
)))))
2404 (tramp-get-completion-function m
))
2410 (tramp-get-completion-user-host
2411 method user host
(nth 0 x
) (nth 1 x
)))
2412 (delq nil all-user-hosts
)))))
2414 ;; Possible methods.
2416 (append result
(tramp-get-completion-methods m
)))))))
2418 ;; Unify list, add hop, remove nil elements.
2419 (dolist (elt result
)
2421 (string-match tramp-prefix-regexp elt
)
2422 (setq elt
(replace-match (concat tramp-prefix-format hop
) nil nil elt
))
2425 (substring elt
(length (tramp-drop-volume-letter directory
))))))
2427 ;; Complete local parts.
2431 (apply (if (tramp-connectable-p fullname
)
2432 'tramp-completion-run-real-handler
2433 'tramp-run-real-handler
)
2434 'file-name-all-completions
(list (list filename directory
)))))))
2436 ;; Method, host name and user name completion for a file.
2438 (defun tramp-completion-handle-file-name-completion
2439 (filename directory
&optional predicate
)
2440 "Like `file-name-completion' for Tramp files."
2443 (mapcar 'list
(file-name-all-completions filename directory
))
2444 (when (and predicate
2445 (tramp-connectable-p (expand-file-name filename directory
)))
2446 (lambda (x) (funcall predicate
(expand-file-name (car x
) directory
))))))
2448 ;; I misuse a little bit the tramp-file-name structure in order to handle
2449 ;; completion possibilities for partial methods / user names / host names.
2450 ;; Return value is a list of tramp-file-name structures according to possible
2451 ;; completions. If "localname" is non-nil it means there
2452 ;; shouldn't be a completion anymore.
2454 ;; Expected results:
2456 ;; "/x" "/[x" "/x@" "/[x@" "/x@y" "/[x@y"
2457 ;; [nil nil "x" nil] [nil "x" nil nil] [nil "x" "y" nil]
2458 ;; [nil "x" nil nil]
2459 ;; ["x" nil nil nil]
2461 ;; "/x:" "/x:y" "/x:y:"
2462 ;; [nil nil "x" ""] [nil nil "x" "y"] ["x" nil "y" ""]
2464 ;; ["x" nil "" nil] ["x" nil "y" nil]
2465 ;; ["x" "" nil nil] ["x" "y" nil nil]
2467 ;; "/x:y@" "/x:y@z" "/x:y@z:"
2468 ;; [nil nil "x" "y@"] [nil nil "x" "y@z"] ["x" "y" "z" ""]
2469 ;; "/[x/y@" "/[x/y@z"
2470 ;; ["x" nil "y" nil] ["x" "y" "z" nil]
2471 (defun tramp-completion-dissect-file-name (name)
2472 "Returns a list of `tramp-file-name' structures.
2473 They are collected by `tramp-completion-dissect-file-name1'."
2477 (tramp-completion-ipv6-regexp
2480 (if (zerop (length tramp-postfix-ipv6-format
))
2481 tramp-postfix-host-format
2482 tramp-postfix-ipv6-format
)))
2483 ;; "/method" "/[method"
2484 (tramp-completion-file-name-structure1
2485 (list (concat tramp-prefix-regexp
"\\(" tramp-method-regexp x-nil
"\\)$")
2488 (tramp-completion-file-name-structure2
2489 (list (concat tramp-prefix-regexp
"\\(" tramp-user-regexp x-nil
"\\)$")
2492 (tramp-completion-file-name-structure3
2493 (list (concat tramp-prefix-regexp
"\\(" tramp-host-regexp x-nil
"\\)$")
2495 ;; "/[ipv6" "/[ipv6"
2496 (tramp-completion-file-name-structure4
2497 (list (concat tramp-prefix-regexp
2498 tramp-prefix-ipv6-regexp
2499 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2501 ;; "/user@host" "/[user@host"
2502 (tramp-completion-file-name-structure5
2503 (list (concat tramp-prefix-regexp
2504 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2505 "\\(" tramp-host-regexp x-nil
"\\)$")
2507 ;; "/user@[ipv6" "/[user@ipv6"
2508 (tramp-completion-file-name-structure6
2509 (list (concat tramp-prefix-regexp
2510 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2511 tramp-prefix-ipv6-regexp
2512 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2514 ;; "/method:user" "/[method/user"
2515 (tramp-completion-file-name-structure7
2516 (list (concat tramp-prefix-regexp
2517 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2518 "\\(" tramp-user-regexp x-nil
"\\)$")
2520 ;; "/method:host" "/[method/host"
2521 (tramp-completion-file-name-structure8
2522 (list (concat tramp-prefix-regexp
2523 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2524 "\\(" tramp-host-regexp x-nil
"\\)$")
2526 ;; "/method:[ipv6" "/[method/ipv6"
2527 (tramp-completion-file-name-structure9
2528 (list (concat tramp-prefix-regexp
2529 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2530 tramp-prefix-ipv6-regexp
2531 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2533 ;; "/method:user@host" "/[method/user@host"
2534 (tramp-completion-file-name-structure10
2535 (list (concat tramp-prefix-regexp
2536 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2537 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2538 "\\(" tramp-host-regexp x-nil
"\\)$")
2540 ;; "/method:user@[ipv6" "/[method/user@ipv6"
2541 (tramp-completion-file-name-structure11
2542 (list (concat tramp-prefix-regexp
2543 "\\(" tramp-method-regexp
"\\)" tramp-postfix-method-regexp
2544 "\\(" tramp-user-regexp
"\\)" tramp-postfix-user-regexp
2545 tramp-prefix-ipv6-regexp
2546 "\\(" tramp-completion-ipv6-regexp x-nil
"\\)$")
2549 (mapc (lambda (structure)
2550 (add-to-list 'result
2551 (tramp-completion-dissect-file-name1 structure name
)))
2553 tramp-completion-file-name-structure1
2554 tramp-completion-file-name-structure2
2555 tramp-completion-file-name-structure3
2556 tramp-completion-file-name-structure4
2557 tramp-completion-file-name-structure5
2558 tramp-completion-file-name-structure6
2559 tramp-completion-file-name-structure7
2560 tramp-completion-file-name-structure8
2561 tramp-completion-file-name-structure9
2562 tramp-completion-file-name-structure10
2563 tramp-completion-file-name-structure11
2564 tramp-file-name-structure
))
2568 (defun tramp-completion-dissect-file-name1 (structure name
)
2569 "Returns a `tramp-file-name' structure matching STRUCTURE.
2570 The structure consists of remote method, remote user,
2571 remote host and localname (filename on remote host)."
2574 (when (string-match (nth 0 structure
) name
)
2575 (let ((method (and (nth 1 structure
)
2576 (match-string (nth 1 structure
) name
)))
2577 (user (and (nth 2 structure
)
2578 (match-string (nth 2 structure
) name
)))
2579 (host (and (nth 3 structure
)
2580 (match-string (nth 3 structure
) name
)))
2581 (localname (and (nth 4 structure
)
2582 (match-string (nth 4 structure
) name
))))
2583 (vector method user host localname nil
)))))
2585 ;; This function returns all possible method completions, adding the
2586 ;; trailing method delimiter.
2587 (defun tramp-get-completion-methods (partial-method)
2588 "Returns all method completions for PARTIAL-METHOD."
2592 (string-match (concat "^" (regexp-quote partial-method
)) method
)
2593 (tramp-completion-make-tramp-file-name method nil nil nil
)))
2594 (mapcar 'car tramp-methods
)))
2596 ;; Compares partial user and host names with possible completions.
2597 (defun tramp-get-completion-user-host
2598 (method partial-user partial-host user host
)
2599 "Returns the most expanded string for user and host name completion.
2600 PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
2603 ((and partial-user partial-host
)
2605 (string-match (concat "^" (regexp-quote partial-host
)) host
)
2606 (string-equal partial-user
(or user partial-user
)))
2607 (setq user partial-user
)
2614 (and user
(string-match (concat "^" (regexp-quote partial-user
)) user
))
2620 (and host
(string-match (concat "^" (regexp-quote partial-host
)) host
))
2626 (unless (zerop (+ (length user
) (length host
)))
2627 (tramp-completion-make-tramp-file-name method user host nil
)))
2629 ;; Generic function.
2630 (defun tramp-parse-group (regexp match-level skip-regexp
)
2631 "Return a (user host) tuple allowed to access.
2632 User is always nil."
2634 (when (re-search-forward regexp
(point-at-eol) t
)
2635 (setq result
(list nil
(match-string match-level
))))
2637 (> (skip-chars-forward skip-regexp
) 0)
2641 ;; Generic function.
2642 (defun tramp-parse-file (filename function
)
2643 "Return a list of (user host) tuples allowed to access.
2644 User is always nil."
2645 ;; On Windows, there are problems in completion when
2646 ;; `default-directory' is remote.
2647 (let ((default-directory (tramp-compat-temporary-file-directory)))
2648 (when (file-readable-p filename
)
2650 (insert-file-contents filename
)
2651 (goto-char (point-min))
2652 (loop while
(not (eobp)) collect
(funcall function
))))))
2654 ;;;###tramp-autoload
2655 (defun tramp-parse-rhosts (filename)
2656 "Return a list of (user host) tuples allowed to access.
2657 Either user or host may be nil."
2658 (tramp-parse-file filename
'tramp-parse-rhosts-group
))
2660 (defun tramp-parse-rhosts-group ()
2661 "Return a (user host) tuple allowed to access.
2662 Either user or host may be nil."
2666 "^\\(" tramp-host-regexp
"\\)"
2667 "\\([ \t]+" "\\(" tramp-user-regexp
"\\)" "\\)?")))
2668 (when (re-search-forward regexp
(point-at-eol) t
)
2669 (setq result
(append (list (match-string 3) (match-string 1)))))
2673 ;;;###tramp-autoload
2674 (defun tramp-parse-shosts (filename)
2675 "Return a list of (user host) tuples allowed to access.
2676 User is always nil."
2677 (tramp-parse-file filename
'tramp-parse-shosts-group
))
2679 (defun tramp-parse-shosts-group ()
2680 "Return a (user host) tuple allowed to access.
2681 User is always nil."
2682 (tramp-parse-group (concat "^\\(" tramp-host-regexp
"\\)") 1 ","))
2684 ;;;###tramp-autoload
2685 (defun tramp-parse-sconfig (filename)
2686 "Return a list of (user host) tuples allowed to access.
2687 User is always nil."
2688 (tramp-parse-file filename
'tramp-parse-sconfig-group
))
2690 (defun tramp-parse-sconfig-group ()
2691 "Return a (user host) tuple allowed to access.
2692 User is always nil."
2694 (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp
"\\)") 1 ","))
2696 ;; Generic function.
2697 (defun tramp-parse-shostkeys-sknownhosts (dirname regexp
)
2698 "Return a list of (user host) tuples allowed to access.
2699 User is always nil."
2700 ;; On Windows, there are problems in completion when
2701 ;; `default-directory' is remote.
2702 (let* ((default-directory (tramp-compat-temporary-file-directory))
2703 (files (and (file-directory-p dirname
) (directory-files dirname
))))
2704 (loop for f in files
2705 when
(and (not (string-match "^\\.\\.?$" f
)) (string-match regexp f
))
2706 collect
(list nil
(match-string 1 f
)))))
2708 ;;;###tramp-autoload
2709 (defun tramp-parse-shostkeys (dirname)
2710 "Return a list of (user host) tuples allowed to access.
2711 User is always nil."
2712 (tramp-parse-shostkeys-sknownhosts
2713 dirname
(concat "^key_[0-9]+_\\(" tramp-host-regexp
"\\)\\.pub$")))
2715 ;;;###tramp-autoload
2716 (defun tramp-parse-sknownhosts (dirname)
2717 "Return a list of (user host) tuples allowed to access.
2718 User is always nil."
2719 (tramp-parse-shostkeys-sknownhosts
2721 (concat "^\\(" tramp-host-regexp
"\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$")))
2723 ;;;###tramp-autoload
2724 (defun tramp-parse-hosts (filename)
2725 "Return a list of (user host) tuples allowed to access.
2726 User is always nil."
2727 (tramp-parse-file filename
'tramp-parse-hosts-group
))
2729 (defun tramp-parse-hosts-group ()
2730 "Return a (user host) tuple allowed to access.
2731 User is always nil."
2733 (concat "^\\(" tramp-ipv6-regexp
"\\|" tramp-host-regexp
"\\)") 1 " \t"))
2735 ;; For su-alike methods it would be desirable to return "root@localhost"
2736 ;; as default. Unfortunately, we have no information whether any user name
2737 ;; has been typed already. So we use `tramp-current-user' as indication,
2738 ;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
2739 ;;;###tramp-autoload
2740 (defun tramp-parse-passwd (filename)
2741 "Return a list of (user host) tuples allowed to access.
2742 Host is always \"localhost\"."
2743 (if (zerop (length tramp-current-user
))
2745 (tramp-parse-file filename
'tramp-parse-passwd-group
)))
2747 (defun tramp-parse-passwd-group ()
2748 "Return a (user host) tuple allowed to access.
2749 Host is always \"localhost\"."
2751 (regexp (concat "^\\(" tramp-user-regexp
"\\):")))
2752 (when (re-search-forward regexp
(point-at-eol) t
)
2753 (setq result
(list (match-string 1) "localhost")))
2757 ;;;###tramp-autoload
2758 (defun tramp-parse-netrc (filename)
2759 "Return a list of (user host) tuples allowed to access.
2761 (tramp-parse-file filename
'tramp-parse-netrc-group
))
2763 (defun tramp-parse-netrc-group ()
2764 "Return a (user host) tuple allowed to access.
2769 "^[ \t]*machine[ \t]+" "\\(" tramp-host-regexp
"\\)"
2770 "\\([ \t]+login[ \t]+" "\\(" tramp-user-regexp
"\\)" "\\)?")))
2771 (when (re-search-forward regexp
(point-at-eol) t
)
2772 (setq result
(list (match-string 3) (match-string 1))))
2776 ;;;###tramp-autoload
2777 (defun tramp-parse-putty (registry-or-dirname)
2778 "Return a list of (user host) tuples allowed to access.
2779 User is always nil."
2780 (if (memq system-type
'(windows-nt))
2782 (when (zerop (tramp-call-process
2783 "reg" nil t nil
"query" registry-or-dirname
))
2784 (goto-char (point-min))
2785 (loop while
(not (eobp)) collect
2786 (tramp-parse-putty-group registry-or-dirname
))))
2788 (tramp-parse-shostkeys-sknownhosts
2789 registry-or-dirname
(concat "^\\(" tramp-host-regexp
"\\)$"))))
2791 (defun tramp-parse-putty-group (registry)
2792 "Return a (user host) tuple allowed to access.
2793 User is always nil."
2795 (regexp (concat (regexp-quote registry
) "\\\\\\(.+\\)")))
2796 (when (re-search-forward regexp
(point-at-eol) t
)
2797 (setq result
(list nil
(match-string 1))))
2801 ;;; Common file name handler functions for different backends:
2803 (defvar tramp-handle-file-local-copy-hook nil
2804 "Normal hook to be run at the end of `tramp-*-handle-file-local-copy'.")
2806 (defvar tramp-handle-write-region-hook nil
2807 "Normal hook to be run at the end of `tramp-*-handle-write-region'.")
2809 (defun tramp-handle-directory-file-name (directory)
2810 "Like `directory-file-name' for Tramp files."
2811 ;; If localname component of filename is "/", leave it unchanged.
2812 ;; Otherwise, remove any trailing slash from localname component.
2813 ;; Method, host, etc, are unchanged. Does it make sense to try
2814 ;; to avoid parsing the filename?
2815 (with-parsed-tramp-file-name directory nil
2816 (if (and (not (zerop (length localname
)))
2817 (eq (aref localname
(1- (length localname
))) ?
/)
2818 (not (string= localname
"/")))
2819 (substring directory
0 -
1)
2822 (defun tramp-handle-directory-files
2823 (directory &optional full match nosort files-only
)
2824 "Like `directory-files' for Tramp files."
2825 ;; FILES-ONLY is valid for XEmacs only.
2826 (when (file-directory-p directory
)
2827 (setq directory
(file-name-as-directory (expand-file-name directory
)))
2828 (let ((temp (nreverse (file-name-all-completions "" directory
)))
2832 (setq item
(directory-file-name (pop temp
)))
2833 (when (and (or (null match
) (string-match match item
))
2834 (or (null files-only
)
2836 (and (equal files-only t
) (file-regular-p item
))
2837 ;; Directories only.
2838 (file-directory-p item
)))
2839 (push (if full
(concat directory item
) item
)
2841 (if nosort result
(sort result
'string
<)))))
2843 (defun tramp-handle-directory-files-and-attributes
2844 (directory &optional full match nosort id-format
)
2845 "Like `directory-files-and-attributes' for Tramp files."
2848 (cons x
(tramp-compat-file-attributes
2849 (if full x
(expand-file-name x directory
)) id-format
)))
2850 (directory-files directory full match nosort
)))
2852 (defun tramp-handle-dired-uncache (dir &optional dir-p
)
2853 "Like `dired-uncache' for Tramp files."
2854 ;; DIR-P is valid for XEmacs only.
2855 (with-parsed-tramp-file-name
2856 (if (or dir-p
(file-directory-p dir
)) dir
(file-name-directory dir
)) nil
2857 (tramp-flush-directory-property v localname
)))
2859 (defun tramp-handle-file-accessible-directory-p (filename)
2860 "Like `file-accessible-directory-p' for Tramp files."
2861 (and (file-directory-p filename
)
2862 (file-executable-p filename
)))
2864 (defun tramp-handle-file-exists-p (filename)
2865 "Like `file-exists-p' for Tramp files."
2866 (not (null (file-attributes filename
))))
2868 (defun tramp-handle-file-modes (filename)
2869 "Like `file-modes' for Tramp files."
2870 (let ((truename (or (file-truename filename
) filename
)))
2871 (when (file-exists-p truename
)
2872 (tramp-mode-string-to-int (nth 8 (file-attributes truename
))))))
2874 ;; Localname manipulation functions that grok Tramp localnames...
2875 (defun tramp-handle-file-name-as-directory (file)
2876 "Like `file-name-as-directory' but aware of Tramp files."
2877 ;; `file-name-as-directory' would be sufficient except localname is
2878 ;; the empty string.
2879 (let ((v (tramp-dissect-file-name file t
)))
2880 ;; Run the command on the localname portion only.
2881 (tramp-make-tramp-file-name
2882 (tramp-file-name-method v
)
2883 (tramp-file-name-user v
)
2884 (tramp-file-name-host v
)
2885 (tramp-run-real-handler
2886 'file-name-as-directory
(list (or (tramp-file-name-localname v
) ""))))))
2888 (defun tramp-handle-file-name-completion
2889 (filename directory
&optional predicate
)
2890 "Like `file-name-completion' for Tramp files."
2891 (unless (tramp-tramp-file-p directory
)
2893 "tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
2897 (mapcar 'list
(file-name-all-completions filename directory
))
2899 (lambda (x) (funcall predicate
(expand-file-name (car x
) directory
))))))
2901 (defun tramp-handle-file-name-directory (file)
2902 "Like `file-name-directory' but aware of Tramp files."
2903 ;; Everything except the last filename thing is the directory. We
2904 ;; cannot apply `with-parsed-tramp-file-name', because this expands
2905 ;; the remote file name parts. This is a problem when we are in
2906 ;; file name completion.
2907 (let ((v (tramp-dissect-file-name file t
)))
2908 ;; Run the command on the localname portion only.
2909 (tramp-make-tramp-file-name
2910 (tramp-file-name-method v
)
2911 (tramp-file-name-user v
)
2912 (tramp-file-name-host v
)
2913 (tramp-run-real-handler
2914 'file-name-directory
(list (or (tramp-file-name-localname v
) ""))))))
2916 (defun tramp-handle-file-name-nondirectory (file)
2917 "Like `file-name-nondirectory' but aware of Tramp files."
2918 (with-parsed-tramp-file-name file nil
2919 (tramp-run-real-handler 'file-name-nondirectory
(list localname
))))
2921 (defun tramp-handle-file-newer-than-file-p (file1 file2
)
2922 "Like `file-newer-than-file-p' for Tramp files."
2924 ((not (file-exists-p file1
)) nil
)
2925 ((not (file-exists-p file2
)) t
)
2926 (t (tramp-time-less-p (nth 5 (file-attributes file2
))
2927 (nth 5 (file-attributes file1
))))))
2929 (defun tramp-handle-file-regular-p (filename)
2930 "Like `file-regular-p' for Tramp files."
2931 (and (file-exists-p filename
)
2932 (eq ?-
(aref (nth 8 (file-attributes filename
)) 0))))
2934 (defun tramp-handle-file-remote-p (filename &optional identification connected
)
2935 "Like `file-remote-p' for Tramp files."
2936 ;; We do not want traces in the debug buffer.
2937 (let ((tramp-verbose (min tramp-verbose
3)))
2938 (when (tramp-tramp-file-p filename
)
2939 (let* ((v (tramp-dissect-file-name filename
))
2940 (p (tramp-get-connection-process v
))
2941 (c (and p
(processp p
) (memq (process-status p
) '(run open
)))))
2942 ;; We expand the file name only, if there is already a connection.
2943 (with-parsed-tramp-file-name
2944 (if c
(expand-file-name filename
) filename
) nil
2945 (and (or (not connected
) c
)
2947 ((eq identification
'method
) method
)
2948 ((eq identification
'user
) user
)
2949 ((eq identification
'host
) host
)
2950 ((eq identification
'localname
) localname
)
2951 (t (tramp-make-tramp-file-name method user host
"")))))))))
2953 (defun tramp-handle-file-symlink-p (filename)
2954 "Like `file-symlink-p' for Tramp files."
2955 (with-parsed-tramp-file-name filename nil
2956 (let ((x (car (file-attributes filename
))))
2958 ;; When Tramp is running on VMS, then `file-name-absolute-p'
2959 ;; might do weird things.
2960 (if (file-name-absolute-p x
)
2961 (tramp-make-tramp-file-name method user host x
)
2964 (defun tramp-handle-find-backup-file-name (filename)
2965 "Like `find-backup-file-name' for Tramp files."
2966 (with-parsed-tramp-file-name filename nil
2967 ;; We set both variables. It doesn't matter whether it is
2969 (let ((backup-directory-alist
2971 (when (boundp 'backup-directory-alist
)
2972 (if (symbol-value 'tramp-backup-directory-alist
)
2977 (if (and (stringp (cdr x
))
2978 (file-name-absolute-p (cdr x
))
2979 (not (tramp-file-name-p (cdr x
))))
2980 (tramp-make-tramp-file-name method user host
(cdr x
))
2982 (symbol-value 'tramp-backup-directory-alist
))
2983 (symbol-value 'backup-directory-alist
))))
2985 (bkup-backup-directory-info
2987 (when (boundp 'bkup-backup-directory-info
)
2988 (if (symbol-value 'tramp-bkup-backup-directory-info
)
2994 (if (and (stringp (car (cdr x
)))
2995 (file-name-absolute-p (car (cdr x
)))
2996 (not (tramp-file-name-p (car (cdr x
)))))
2997 (tramp-make-tramp-file-name
2998 method user host
(car (cdr x
)))
3001 (symbol-value 'tramp-bkup-backup-directory-info
))
3002 (symbol-value 'bkup-backup-directory-info
)))))
3004 (tramp-run-real-handler 'find-backup-file-name
(list filename
)))))
3006 (defun tramp-handle-insert-file-contents
3007 (filename &optional visit beg end replace
)
3008 "Like `insert-file-contents' for Tramp files."
3009 (barf-if-buffer-read-only)
3010 (setq filename
(expand-file-name filename
))
3011 (let (result local-copy remote-copy
)
3012 (with-parsed-tramp-file-name filename nil
3013 (with-tramp-progress-reporter
3014 v
3 (format "Inserting `%s'" filename
)
3016 (if (not (file-exists-p filename
))
3017 ;; We don't raise a Tramp error, because it might be
3018 ;; suppressed, like in `find-file-noselect-1'.
3020 (list "File not found on remote host" filename
))
3022 (if (and (tramp-local-host-p v
)
3023 (let (file-name-handler-alist)
3024 (file-readable-p localname
)))
3025 ;; Short track: if we are on the local host, we can
3028 (tramp-run-real-handler
3029 'insert-file-contents
3030 (list localname visit beg end replace
)))
3032 ;; When we shall insert only a part of the file, we
3033 ;; copy this part. This works only for the shell file
3035 (when (and (or beg end
)
3036 (tramp-get-method-parameter
3037 (tramp-file-name-method v
) 'tramp-login-program
))
3038 (setq remote-copy
(tramp-make-tramp-temp-file v
))
3039 ;; This is defined in tramp-sh.el. Let's assume
3040 ;; this is loaded already.
3041 (tramp-compat-funcall
3046 (format "dd bs=1 skip=%d if=%s count=%d of=%s"
3047 beg
(tramp-shell-quote-argument localname
)
3048 (- end beg
) remote-copy
))
3050 (format "dd bs=1 skip=%d if=%s of=%s"
3051 beg
(tramp-shell-quote-argument localname
)
3054 (format "dd bs=1 count=%d if=%s of=%s"
3055 end
(tramp-shell-quote-argument localname
)
3057 (setq tramp-temp-buffer-file-name nil beg nil end nil
))
3059 ;; `insert-file-contents-literally' takes care to
3060 ;; avoid calling jka-compr. By let-binding
3061 ;; `inhibit-file-name-operation', we propagate that
3062 ;; care to the `file-local-copy' operation.
3064 (let ((inhibit-file-name-operation
3065 (when (eq inhibit-file-name-operation
3066 'insert-file-contents
)
3069 ((stringp remote-copy
)
3071 (tramp-make-tramp-file-name
3072 method user host remote-copy
)))
3073 ((stringp tramp-temp-buffer-file-name
)
3074 (copy-file filename tramp-temp-buffer-file-name
'ok
)
3075 tramp-temp-buffer-file-name
)
3076 (t (file-local-copy filename
)))))
3078 ;; When the file is not readable for the owner, it
3079 ;; cannot be inserted, even if it is readable for the
3080 ;; group or for everybody.
3082 local-copy
(tramp-compat-octal-to-decimal "0600"))
3084 (when (and (null remote-copy
)
3085 (tramp-get-method-parameter
3086 method
'tramp-copy-keep-tmpfile
))
3087 ;; We keep the local file for performance reasons,
3088 ;; useful for "rsync".
3089 (setq tramp-temp-buffer-file-name local-copy
))
3091 ;; We must ensure that `file-coding-system-alist'
3092 ;; matches `local-copy'. We must also use `visit',
3093 ;; otherwise there might be an error in the
3094 ;; `revert-buffer' function under XEmacs.
3095 (let ((file-coding-system-alist
3096 (tramp-find-file-name-coding-system-alist
3097 filename local-copy
)))
3099 (insert-file-contents
3100 local-copy visit beg end replace
)))))
3105 (setq buffer-file-name filename
)
3106 (setq buffer-read-only
(not (file-writable-p filename
)))
3107 (set-visited-file-modtime)
3108 (set-buffer-modified-p nil
))
3109 (when (and (stringp local-copy
)
3110 (or remote-copy
(null tramp-temp-buffer-file-name
)))
3111 (delete-file local-copy
))
3112 (when (stringp remote-copy
)
3114 (tramp-make-tramp-file-name method user host remote-copy
)))))))
3117 (list (expand-file-name filename
)
3120 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix
)
3121 "Like `load' for Tramp files."
3122 (with-parsed-tramp-file-name (expand-file-name file
) nil
3124 (cond ((file-exists-p (concat file
".elc"))
3125 (setq file
(concat file
".elc")))
3126 ((file-exists-p (concat file
".el"))
3127 (setq file
(concat file
".el")))))
3129 ;; The first condition is always true for absolute file names.
3130 ;; Included for safety's sake.
3131 (unless (or (file-name-directory file
)
3132 (string-match "\\.elc?\\'" file
))
3135 "File `%s' does not include a `.el' or `.elc' suffix" file
)))
3137 (when (not (file-exists-p file
))
3138 (tramp-error v
'file-error
"Cannot load nonexistent file `%s'" file
)))
3139 (if (not (file-exists-p file
))
3141 (let ((tramp-message-show-message (not nomessage
)))
3142 (with-tramp-progress-reporter v
0 (format "Loading %s" file
)
3143 (let ((local-copy (file-local-copy file
)))
3144 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
3146 (load local-copy noerror t t
)
3147 (delete-file local-copy
)))))
3150 (defun tramp-handle-shell-command
3151 (command &optional output-buffer error-buffer
)
3152 "Like `shell-command' for Tramp files."
3153 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command
))
3154 ;; We cannot use `shell-file-name' and `shell-command-switch',
3155 ;; they are variables of the local host.
3158 (tramp-get-method-parameter
3159 (tramp-file-name-method
3160 (tramp-dissect-file-name default-directory
))
3161 'tramp-remote-shell
)
3162 (tramp-get-method-parameter
3163 (tramp-file-name-method
3164 (tramp-dissect-file-name default-directory
))
3165 'tramp-remote-shell-args
))
3166 (list (substring command
0 asynchronous
))))
3170 ((bufferp output-buffer
) output-buffer
)
3171 ((stringp output-buffer
) (get-buffer-create output-buffer
))
3173 (setq current-buffer-p t
)
3175 (t (get-buffer-create
3177 "*Async Shell Command*"
3178 "*Shell Command Output*")))))
3181 ((bufferp error-buffer
) error-buffer
)
3182 ((stringp error-buffer
) (get-buffer-create error-buffer
))))
3184 (if (and (not asynchronous
) error-buffer
)
3185 (with-parsed-tramp-file-name default-directory nil
3186 (list output-buffer
(tramp-make-tramp-temp-file v
)))
3188 (p (get-buffer-process output-buffer
)))
3190 ;; Check whether there is another process running. Tramp does not
3191 ;; support 2 (asynchronous) processes in parallel.
3193 (if (yes-or-no-p "A command is running. Kill it? ")
3194 (ignore-errors (kill-process p
))
3195 (tramp-user-error p
"Shell command in progress")))
3197 (if current-buffer-p
3199 (barf-if-buffer-read-only)
3201 (with-current-buffer output-buffer
3202 (setq buffer-read-only nil
)
3205 (if (and (not current-buffer-p
) (integerp asynchronous
))
3208 (setq p
(apply 'start-file-process
"*Async Shell*" buffer args
))
3210 (pop-to-buffer output-buffer
)
3211 (setq mode-line-process
'(":%s"))
3213 (set-process-sentinel p
'shell-command-sentinel
)
3214 (set-process-filter p
'comint-output-filter
))
3218 (apply 'process-file
(car args
) nil buffer nil
(cdr args
))
3219 ;; Insert error messages if they were separated.
3220 (when (listp buffer
)
3221 (with-current-buffer error-buffer
3222 (insert-file-contents (cadr buffer
)))
3223 (delete-file (cadr buffer
)))
3224 (if current-buffer-p
3225 ;; This is like exchange-point-and-mark, but doesn't
3226 ;; activate the mark. It is cleaner to avoid activation,
3227 ;; even though the command loop would deactivate the mark
3228 ;; because we inserted text.
3229 (goto-char (prog1 (mark t
)
3230 (set-marker (mark-marker) (point)
3232 ;; There's some output, display it.
3233 (when (with-current-buffer output-buffer
(> (point-max) (point-min)))
3234 (if (functionp 'display-message-or-buffer
)
3235 (tramp-compat-funcall 'display-message-or-buffer output-buffer
)
3236 (pop-to-buffer output-buffer
))))))))
3238 (defun tramp-handle-substitute-in-file-name (filename)
3239 "Like `substitute-in-file-name' for Tramp files.
3240 \"//\" and \"/~\" substitute only in the local filename part."
3241 ;; First, we must replace environment variables.
3242 (setq filename
(tramp-replace-environment-variables filename
))
3243 (with-parsed-tramp-file-name filename nil
3244 ;; Ignore in LOCALNAME everything before "//" or "/~".
3245 (when (and (stringp localname
) (string-match ".+?/\\(/\\|~\\)" localname
))
3247 (concat (file-remote-p filename
)
3248 (replace-match "\\1" nil nil localname
)))
3249 ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
3250 (when (string-match "~$" filename
)
3251 (setq filename
(concat filename
"/"))))
3252 (tramp-run-real-handler 'substitute-in-file-name
(list filename
))))
3254 (defun tramp-handle-unhandled-file-name-directory (_filename)
3255 "Like `unhandled-file-name-directory' for Tramp files."
3256 ;; With Emacs 23, we could simply return `nil'. But we must keep it
3257 ;; for backward compatibility.
3258 (expand-file-name "~/"))
3260 (defun tramp-handle-set-visited-file-modtime (&optional time-list
)
3261 "Like `set-visited-file-modtime' for Tramp files."
3262 (unless (buffer-file-name)
3263 (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
3266 (let ((remote-file-name-inhibit-cache t
))
3267 ;; '(-1 65535) means file doesn't exists yet.
3269 (or (nth 5 (file-attributes (buffer-file-name))) '(-1 65535)))))
3270 ;; We use '(0 0) as a don't-know value.
3271 (unless (equal time-list
'(0 0))
3272 (tramp-run-real-handler 'set-visited-file-modtime
(list time-list
))))
3274 (defun tramp-handle-verify-visited-file-modtime (&optional buf
)
3275 "Like `verify-visited-file-modtime' for Tramp files.
3276 At the time `verify-visited-file-modtime' calls this function, we
3277 already know that the buffer is visiting a file and that
3278 `visited-file-modtime' does not return 0. Do not call this
3279 function directly, unless those two cases are already taken care
3281 (with-current-buffer (or buf
(current-buffer))
3282 (let ((f (buffer-file-name)))
3283 ;; There is no file visiting the buffer, or the buffer has no
3284 ;; recorded last modification time, or there is no established
3287 (eq (visited-file-modtime) 0)
3288 (not (tramp-file-name-handler 'file-remote-p f nil
'connected
)))
3290 (with-parsed-tramp-file-name f nil
3291 (let* ((remote-file-name-inhibit-cache t
)
3292 (attr (file-attributes f
))
3293 (modtime (nth 5 attr
))
3294 (mt (visited-file-modtime)))
3297 ;; File exists, and has a known modtime.
3298 ((and attr
(not (equal modtime
'(0 0))))
3299 (< (abs (tramp-time-diff
3301 ;; For compatibility, deal with both the old
3302 ;; (HIGH . LOW) and the new (HIGH LOW) return
3303 ;; values of `visited-file-modtime'.
3305 (list (car mt
) (cdr mt
))
3308 ;; Modtime has the don't know value.
3310 ;; If file does not exist, say it is not modified if and
3311 ;; only if that agrees with the buffer's record.
3312 (t (equal mt
'(-1 65535))))))))))
3314 (defun tramp-handle-file-notify-add-watch (filename _flags _callback
)
3315 "Like `file-notify-add-watch' for Tramp files."
3316 ;; This is the default handler. tramp-gvfs.el and tramp-sh.el have
3318 (setq filename
(expand-file-name filename
))
3319 (with-parsed-tramp-file-name filename nil
3321 v
'file-notify-error
"File notification not supported for `%s'" filename
)))
3323 (defun tramp-handle-file-notify-rm-watch (proc)
3324 "Like `file-notify-rm-watch' for Tramp files."
3325 ;; The descriptor must be a process object.
3326 (unless (and (processp proc
) (gethash proc file-notify-descriptors
))
3327 (tramp-error proc
'file-notify-error
"Not a valid descriptor %S" proc
))
3328 (tramp-message proc
6 "Kill %S" proc
)
3329 (kill-process proc
))
3331 ;;; Functions for establishing connection:
3333 ;; The following functions are actions to be taken when seeing certain
3334 ;; prompts from the remote host. See the variable
3335 ;; `tramp-actions-before-shell' for usage of these functions.
3337 (defun tramp-action-login (_proc vec
)
3338 "Send the login name."
3339 (when (not (stringp tramp-current-user
))
3340 (setq tramp-current-user
3341 (with-tramp-connection-property vec
"login-as"
3342 (save-window-excursion
3343 (let ((enable-recursive-minibuffers t
))
3344 (pop-to-buffer (tramp-get-connection-buffer vec
))
3345 (read-string (match-string 0)))))))
3346 (with-current-buffer (tramp-get-connection-buffer vec
)
3347 (tramp-message vec
6 "\n%s" (buffer-string)))
3348 (tramp-message vec
3 "Sending login name `%s'" tramp-current-user
)
3349 (tramp-send-string vec
(concat tramp-current-user tramp-local-end-of-line
)))
3351 (defun tramp-action-password (proc vec
)
3352 "Query the user for a password."
3353 (with-current-buffer (process-buffer proc
)
3354 (let ((enable-recursive-minibuffers t
))
3355 (tramp-check-for-regexp proc tramp-password-prompt-regexp
)
3356 (tramp-message vec
3 "Sending %s" (match-string 1))
3357 ;; We don't call `tramp-send-string' in order to hide the
3358 ;; password from the debug buffer.
3359 (process-send-string
3360 proc
(concat (tramp-read-passwd proc
) tramp-local-end-of-line
))
3361 ;; Hide password prompt.
3362 (narrow-to-region (point-max) (point-max)))))
3364 (defun tramp-action-succeed (_proc _vec
)
3365 "Signal success in finding shell prompt."
3366 (throw 'tramp-action
'ok
))
3368 (defun tramp-action-permission-denied (proc _vec
)
3369 "Signal permission denied."
3371 (throw 'tramp-action
'permission-denied
))
3373 (defun tramp-action-yesno (proc vec
)
3374 "Ask the user for confirmation using `yes-or-no-p'.
3375 Send \"yes\" to remote process on confirmation, abort otherwise.
3376 See also `tramp-action-yn'."
3377 (save-window-excursion
3378 (let ((enable-recursive-minibuffers t
))
3379 (save-match-data (pop-to-buffer (tramp-get-connection-buffer vec
)))
3380 (unless (yes-or-no-p (match-string 0))
3382 (throw 'tramp-action
'permission-denied
))
3383 (with-current-buffer (tramp-get-connection-buffer vec
)
3384 (tramp-message vec
6 "\n%s" (buffer-string)))
3385 (tramp-send-string vec
(concat "yes" tramp-local-end-of-line
)))))
3387 (defun tramp-action-yn (proc vec
)
3388 "Ask the user for confirmation using `y-or-n-p'.
3389 Send \"y\" to remote process on confirmation, abort otherwise.
3390 See also `tramp-action-yesno'."
3391 (save-window-excursion
3392 (let ((enable-recursive-minibuffers t
))
3393 (save-match-data (pop-to-buffer (tramp-get-connection-buffer vec
)))
3394 (unless (y-or-n-p (match-string 0))
3396 (throw 'tramp-action
'permission-denied
))
3397 (with-current-buffer (tramp-get-connection-buffer vec
)
3398 (tramp-message vec
6 "\n%s" (buffer-string)))
3399 (tramp-send-string vec
(concat "y" tramp-local-end-of-line
)))))
3401 (defun tramp-action-terminal (_proc vec
)
3402 "Tell the remote host which terminal type to use.
3403 The terminal type can be configured with `tramp-terminal-type'."
3404 (tramp-message vec
5 "Setting `%s' as terminal type." tramp-terminal-type
)
3405 (with-current-buffer (tramp-get-connection-buffer vec
)
3406 (tramp-message vec
6 "\n%s" (buffer-string)))
3407 (tramp-send-string vec
(concat tramp-terminal-type tramp-local-end-of-line
)))
3409 (defun tramp-action-process-alive (proc _vec
)
3410 "Check, whether a process has finished."
3411 (unless (memq (process-status proc
) '(run open
))
3412 (throw 'tramp-action
'process-died
)))
3414 (defun tramp-action-out-of-band (proc vec
)
3415 "Check, whether an out-of-band copy has finished."
3416 (cond ((and (memq (process-status proc
) '(stop exit
))
3417 (zerop (process-exit-status proc
)))
3418 (tramp-message vec
3 "Process has finished.")
3419 (throw 'tramp-action
'ok
))
3420 ((or (and (memq (process-status proc
) '(stop exit
))
3421 (not (zerop (process-exit-status proc
))))
3422 (memq (process-status proc
) '(signal)))
3423 ;; `scp' could have copied correctly, but set modes could have failed.
3424 ;; This can be ignored.
3425 (with-current-buffer (process-buffer proc
)
3426 (goto-char (point-min))
3427 (if (re-search-forward tramp-operation-not-permitted-regexp nil t
)
3429 (tramp-message vec
5 "'set mode' error ignored.")
3430 (tramp-message vec
3 "Process has finished.")
3431 (throw 'tramp-action
'ok
))
3432 (tramp-message vec
3 "Process has died.")
3433 (throw 'tramp-action
'process-died
))))
3436 ;;; Functions for processing the actions:
3438 (defun tramp-process-one-action (proc vec actions
)
3439 "Wait for output from the shell and perform one action."
3440 (let (found todo item pattern action
)
3442 ;; Reread output once all actions have been performed.
3443 ;; Obviously, the output was not complete.
3444 (tramp-accept-process-output proc
1)
3447 (setq item
(pop todo
))
3448 (setq pattern
(format "\\(%s\\)\\'" (symbol-value (nth 0 item
))))
3449 (setq action
(nth 1 item
))
3451 vec
5 "Looking for regexp \"%s\" from remote shell" pattern
)
3452 (when (tramp-check-for-regexp proc pattern
)
3453 (tramp-message vec
5 "Call `%s'" (symbol-name action
))
3454 (setq found
(funcall action proc vec
)))))
3457 (defun tramp-process-actions (proc vec pos actions
&optional timeout
)
3458 "Perform ACTIONS until success or TIMEOUT.
3459 PROC and VEC indicate the remote connection to be used. POS, if
3460 set, is the starting point of the region to be deleted in the
3462 ;; Enable `auth-source' and `password-cache'. We must use
3463 ;; tramp-current-* variables in case we have several hops.
3464 (tramp-set-connection-property
3465 (tramp-dissect-file-name
3466 (tramp-make-tramp-file-name
3467 tramp-current-method tramp-current-user tramp-current-host
""))
3468 "first-password-request" t
)
3470 (with-tramp-progress-reporter
3471 proc
3 "Waiting for prompts from remote shell"
3474 (with-timeout (timeout (setq exit
'timeout
))
3477 (catch 'tramp-action
3478 (tramp-process-one-action proc vec actions
)))))
3481 (catch 'tramp-action
3482 (tramp-process-one-action proc vec actions
)))))
3483 (with-current-buffer (tramp-get-connection-buffer vec
)
3485 (tramp-message vec
6 "\n%s" (buffer-string)))
3486 (unless (eq exit
'ok
)
3487 (tramp-clear-passwd vec
)
3488 (delete-process proc
)
3489 (tramp-error-with-buffer
3490 (tramp-get-connection-buffer vec
) vec
'file-error
3492 ((eq exit
'permission-denied
) "Permission denied")
3493 ((eq exit
'process-died
)
3495 "Tramp failed to connect. If this happens repeatedly, try\n"
3496 " `M-x tramp-cleanup-this-connection'"))
3499 "Timeout reached, see buffer `%s' for details"
3500 (tramp-get-connection-buffer vec
)))
3501 (t "Login failed")))))
3503 (with-current-buffer (tramp-get-connection-buffer vec
)
3504 (let (buffer-read-only) (delete-region pos
(point))))))))
3506 :;; Utility functions:
3508 (defun tramp-accept-process-output (&optional proc timeout timeout-msecs
)
3509 "Like `accept-process-output' for Tramp processes.
3510 This is needed in order to hide `last-coding-system-used', which is set
3511 for process communication also."
3512 (with-current-buffer (process-buffer proc
)
3513 (tramp-message proc
10 "%s %s" proc
(process-status proc
))
3514 (let (buffer-read-only last-coding-system-used
)
3515 ;; Under Windows XP, accept-process-output doesn't return
3516 ;; sometimes. So we add an additional timeout.
3517 (with-timeout ((or timeout
1))
3518 (if (featurep 'xemacs
)
3519 (accept-process-output proc timeout timeout-msecs
)
3520 (accept-process-output proc timeout timeout-msecs
(and proc t
)))))
3521 (tramp-message proc
10 "\n%s" (buffer-string))))
3523 (defun tramp-check-for-regexp (proc regexp
)
3524 "Check, whether REGEXP is contained in process buffer of PROC.
3525 Erase echoed commands if exists."
3526 (with-current-buffer (process-buffer proc
)
3527 (goto-char (point-min))
3529 ;; Check whether we need to remove echo output.
3530 (when (and (tramp-get-connection-property proc
"check-remote-echo" nil
)
3531 (re-search-forward tramp-echoed-echo-mark-regexp nil t
))
3532 (let ((begin (match-beginning 0)))
3533 (when (re-search-forward tramp-echoed-echo-mark-regexp nil t
)
3534 ;; Discard echo from remote output.
3535 (tramp-set-connection-property proc
"check-remote-echo" nil
)
3536 (tramp-message proc
5 "echo-mark found")
3538 (delete-region begin
(point))
3539 (goto-char (point-min)))))
3541 (when (or (not (tramp-get-connection-property proc
"check-remote-echo" nil
))
3542 ;; Sometimes, the echo string is suppressed on the remote side.
3544 (tramp-compat-funcall
3545 'substring-no-properties tramp-echo-mark-marker
3546 0 (min tramp-echo-mark-marker-length
(1- (point-max))))
3547 (tramp-compat-funcall
3548 'buffer-substring-no-properties
3550 (min (+ (point-min) tramp-echo-mark-marker-length
)
3552 ;; No echo to be handled, now we can look for the regexp.
3553 ;; Sometimes, lines are much to long, and we run into a "Stack
3554 ;; overflow in regexp matcher". For example, //DIRED// lines of
3555 ;; directory listings with some thousand files. Therefore, we
3556 ;; look from the end.
3557 (goto-char (point-max))
3558 (ignore-errors (re-search-backward regexp nil t
)))))
3560 (defun tramp-wait-for-regexp (proc timeout regexp
)
3561 "Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
3562 Expects the output of PROC to be sent to the current buffer. Returns
3563 the string that matched, or nil. Waits indefinitely if TIMEOUT is
3565 (with-current-buffer (process-buffer proc
)
3566 (let ((found (tramp-check-for-regexp proc regexp
))
3567 (start-time (current-time)))
3569 ;; Work around a bug in XEmacs 21, where the timeout
3570 ;; expires faster than it should. This degenerates
3571 ;; to polling for buggy XEmacsen, but oh, well.
3572 (while (and (not found
)
3573 (< (tramp-time-diff (current-time) start-time
)
3575 (with-timeout (timeout)
3577 (tramp-accept-process-output proc
1)
3578 (unless (memq (process-status proc
) '(run open
))
3579 (tramp-error-with-buffer
3580 nil proc
'file-error
"Process has died"))
3581 (setq found
(tramp-check-for-regexp proc regexp
))))))
3584 (tramp-accept-process-output proc
1)
3585 (unless (memq (process-status proc
) '(run open
))
3586 (tramp-error-with-buffer
3587 nil proc
'file-error
"Process has died"))
3588 (setq found
(tramp-check-for-regexp proc regexp
)))))
3589 (tramp-message proc
6 "\n%s" (buffer-string))
3593 proc
'file-error
"[[Regexp `%s' not found in %d secs]]"
3595 (tramp-error proc
'file-error
"[[Regexp `%s' not found]]" regexp
)))
3598 ;; It seems that Tru64 Unix does not like it if long strings are sent
3599 ;; to it in one go. (This happens when sending the Perl
3600 ;; `file-attributes' implementation, for instance.) Therefore, we
3601 ;; have this function which sends the string in chunks.
3602 (defun tramp-send-string (vec string
)
3603 "Send the STRING via connection VEC.
3605 The STRING is expected to use Unix line-endings, but the lines sent to
3606 the remote host use line-endings as defined in the variable
3607 `tramp-rsh-end-of-line'. The communication buffer is erased before sending."
3608 (let* ((p (tramp-get-connection-process vec
))
3609 (chunksize (tramp-get-connection-property p
"chunksize" nil
)))
3612 vec
'file-error
"Can't send string to remote host -- not logged in"))
3613 (tramp-set-connection-property p
"last-cmd-time" (current-time))
3614 (tramp-message vec
10 "%s" string
)
3615 (with-current-buffer (tramp-get-connection-buffer vec
)
3616 ;; Clean up the buffer. We cannot call `erase-buffer' because
3617 ;; narrowing might be in effect.
3618 (let (buffer-read-only) (delete-region (point-min) (point-max)))
3619 ;; Replace "\n" by `tramp-rsh-end-of-line'.
3621 (mapconcat 'identity
3622 (tramp-compat-split-string string
"\n")
3623 tramp-rsh-end-of-line
))
3624 (unless (or (string= string
"")
3625 (string-equal (substring string -
1) tramp-rsh-end-of-line
))
3626 (setq string
(concat string tramp-rsh-end-of-line
)))
3628 (if (and chunksize
(not (zerop chunksize
)))
3630 (end (length string
)))
3633 vec
10 "Sending chunk from %s to %s"
3634 pos
(min (+ pos chunksize
) end
))
3635 (process-send-string
3636 p
(substring string pos
(min (+ pos chunksize
) end
)))
3637 (setq pos
(+ pos chunksize
))))
3638 (process-send-string p string
)))))
3640 (defun tramp-get-inode (vec)
3641 "Returns the virtual inode number.
3642 If it doesn't exist, generate a new one."
3643 (with-tramp-file-property vec
(tramp-file-name-localname vec
) "inode"
3644 (setq tramp-inodes
(1+ tramp-inodes
))))
3646 (defun tramp-get-device (vec)
3647 "Returns the virtual device number.
3648 If it doesn't exist, generate a new one."
3649 (with-tramp-connection-property (tramp-get-connection-process vec
) "device"
3650 (cons -
1 (setq tramp-devices
(1+ tramp-devices
)))))
3652 (defun tramp-equal-remote (file1 file2
)
3653 "Check, whether the remote parts of FILE1 and FILE2 are identical.
3654 The check depends on method, user and host name of the files. If
3655 one of the components is missing, the default values are used.
3656 The local file name parts of FILE1 and FILE2 are not taken into
3661 (tramp-equal-remote \"/ssh::/etc\" \"/<your host name>:/home\")
3663 would yield `t'. On the other hand, the following check results in nil:
3665 (tramp-equal-remote \"/sudo::/etc\" \"/su::/etc\")"
3666 (and (tramp-tramp-file-p file1
)
3667 (tramp-tramp-file-p file2
)
3668 (string-equal (file-remote-p file1
) (file-remote-p file2
))))
3670 ;;;###tramp-autoload
3671 (defun tramp-mode-string-to-int (mode-string)
3672 "Converts a ten-letter `drwxrwxrwx'-style mode string into mode bits."
3673 (let* (case-fold-search
3674 (mode-chars (string-to-vector mode-string
))
3675 (owner-read (aref mode-chars
1))
3676 (owner-write (aref mode-chars
2))
3677 (owner-execute-or-setid (aref mode-chars
3))
3678 (group-read (aref mode-chars
4))
3679 (group-write (aref mode-chars
5))
3680 (group-execute-or-setid (aref mode-chars
6))
3681 (other-read (aref mode-chars
7))
3682 (other-write (aref mode-chars
8))
3683 (other-execute-or-sticky (aref mode-chars
9)))
3687 ((char-equal owner-read ?r
) (tramp-compat-octal-to-decimal "00400"))
3688 ((char-equal owner-read ?-
) 0)
3689 (t (error "Second char `%c' must be one of `r-'" owner-read
)))
3691 ((char-equal owner-write ?w
) (tramp-compat-octal-to-decimal "00200"))
3692 ((char-equal owner-write ?-
) 0)
3693 (t (error "Third char `%c' must be one of `w-'" owner-write
)))
3695 ((char-equal owner-execute-or-setid ?x
)
3696 (tramp-compat-octal-to-decimal "00100"))
3697 ((char-equal owner-execute-or-setid ?S
)
3698 (tramp-compat-octal-to-decimal "04000"))
3699 ((char-equal owner-execute-or-setid ?s
)
3700 (tramp-compat-octal-to-decimal "04100"))
3701 ((char-equal owner-execute-or-setid ?-
) 0)
3702 (t (error "Fourth char `%c' must be one of `xsS-'"
3703 owner-execute-or-setid
)))
3705 ((char-equal group-read ?r
) (tramp-compat-octal-to-decimal "00040"))
3706 ((char-equal group-read ?-
) 0)
3707 (t (error "Fifth char `%c' must be one of `r-'" group-read
)))
3709 ((char-equal group-write ?w
) (tramp-compat-octal-to-decimal "00020"))
3710 ((char-equal group-write ?-
) 0)
3711 (t (error "Sixth char `%c' must be one of `w-'" group-write
)))
3713 ((char-equal group-execute-or-setid ?x
)
3714 (tramp-compat-octal-to-decimal "00010"))
3715 ((char-equal group-execute-or-setid ?S
)
3716 (tramp-compat-octal-to-decimal "02000"))
3717 ((char-equal group-execute-or-setid ?s
)
3718 (tramp-compat-octal-to-decimal "02010"))
3719 ((char-equal group-execute-or-setid ?-
) 0)
3720 (t (error "Seventh char `%c' must be one of `xsS-'"
3721 group-execute-or-setid
)))
3723 ((char-equal other-read ?r
)
3724 (tramp-compat-octal-to-decimal "00004"))
3725 ((char-equal other-read ?-
) 0)
3726 (t (error "Eighth char `%c' must be one of `r-'" other-read
)))
3728 ((char-equal other-write ?w
) (tramp-compat-octal-to-decimal "00002"))
3729 ((char-equal other-write ?-
) 0)
3730 (t (error "Ninth char `%c' must be one of `w-'" other-write
)))
3732 ((char-equal other-execute-or-sticky ?x
)
3733 (tramp-compat-octal-to-decimal "00001"))
3734 ((char-equal other-execute-or-sticky ?T
)
3735 (tramp-compat-octal-to-decimal "01000"))
3736 ((char-equal other-execute-or-sticky ?t
)
3737 (tramp-compat-octal-to-decimal "01001"))
3738 ((char-equal other-execute-or-sticky ?-
) 0)
3739 (t (error "Tenth char `%c' must be one of `xtT-'"
3740 other-execute-or-sticky
)))))))
3742 (defconst tramp-file-mode-type-map
3743 '((0 .
"-") ; Normal file (SVID-v2 and XPG2)
3745 (2 .
"c") ; character device
3746 (3 .
"m") ; multiplexed character device (v7)
3747 (4 .
"d") ; directory
3748 (5 .
"?") ; Named special file (XENIX)
3749 (6 .
"b") ; block device
3750 (7 .
"?") ; multiplexed block device (v7)
3751 (8 .
"-") ; regular file
3752 (9 .
"n") ; network special file (HP-UX)
3753 (10 .
"l") ; symlink
3754 (11 .
"?") ; ACL shadow inode (Solaris, not userspace)
3756 (13 .
"D") ; door special (Solaris)
3757 (14 .
"w")) ; whiteout (BSD)
3758 "A list of file types returned from the `stat' system call.
3759 This is used to map a mode number to a permission string.")
3761 ;;;###tramp-autoload
3762 (defun tramp-file-mode-from-int (mode)
3763 "Turn an integer representing a file mode into an ls(1)-like string."
3765 (assoc (logand (lsh mode -
12) 15) tramp-file-mode-type-map
)))
3766 (user (logand (lsh mode -
6) 7))
3767 (group (logand (lsh mode -
3) 7))
3768 (other (logand (lsh mode -
0) 7))
3769 (suid (> (logand (lsh mode -
9) 4) 0))
3770 (sgid (> (logand (lsh mode -
9) 2) 0))
3771 (sticky (> (logand (lsh mode -
9) 1) 0)))
3772 (setq user
(tramp-file-mode-permissions user suid
"s"))
3773 (setq group
(tramp-file-mode-permissions group sgid
"s"))
3774 (setq other
(tramp-file-mode-permissions other sticky
"t"))
3775 (concat type user group other
)))
3777 (defun tramp-file-mode-permissions (perm suid suid-text
)
3778 "Convert a permission bitset into a string.
3779 This is used internally by `tramp-file-mode-from-int'."
3780 (let ((r (> (logand perm
4) 0))
3781 (w (> (logand perm
2) 0))
3782 (x (> (logand perm
1) 0)))
3783 (concat (or (and r
"r") "-")
3784 (or (and w
"w") "-")
3785 (or (and suid x suid-text
) ; suid, execute
3786 (and suid
(upcase suid-text
)) ; suid, !execute
3787 (and x
"x") "-")))) ; !suid
3789 ;;;###tramp-autoload
3790 (defun tramp-get-local-uid (id-format)
3791 (if (equal id-format
'integer
) (user-uid) (user-login-name)))
3793 ;;;###tramp-autoload
3794 (defun tramp-get-local-gid (id-format)
3795 (if (and (fboundp 'group-gid
) (equal id-format
'integer
))
3796 (tramp-compat-funcall 'group-gid
)
3797 (nth 3 (tramp-compat-file-attributes "~/" id-format
))))
3799 ;;;###tramp-autoload
3800 (defun tramp-check-cached-permissions (vec access
)
3801 "Check `file-attributes' caches for VEC.
3802 Return t if according to the cache access type ACCESS is known to
3808 ((eq ?x access
) 3))))
3809 (dolist (suffix '("string" "integer") result
)
3815 (tramp-get-file-property
3816 vec
(tramp-file-name-localname vec
)
3817 (concat "file-attributes-" suffix
) nil
))
3819 (tramp-get-connection-property
3820 vec
(concat "uid-" suffix
) nil
))
3822 (tramp-get-connection-property
3823 vec
(concat "gid-" suffix
) nil
)))
3828 (eq t
(car file-attr
))
3829 (null (car file-attr
)))
3831 ;; World accessible.
3832 (eq access
(aref (nth 8 file-attr
) (+ offset
6)))
3833 ;; User accessible and owned by user.
3835 (eq access
(aref (nth 8 file-attr
) offset
))
3836 (equal remote-uid
(nth 2 file-attr
)))
3837 ;; Group accessible and owned by user's
3840 (eq access
(aref (nth 8 file-attr
) (+ offset
3)))
3841 (equal remote-gid
(nth 3 file-attr
)))))))))))
3843 ;;;###tramp-autoload
3844 (defun tramp-local-host-p (vec)
3845 "Return t if this points to the local host, nil otherwise."
3846 ;; We cannot use `tramp-file-name-real-host'. A port is an
3847 ;; indication for an ssh tunnel or alike.
3848 (let ((host (tramp-file-name-host vec
)))
3851 (string-match tramp-local-host-regexp host
)
3852 ;; The method shall be applied to one of the shell file name
3853 ;; handlers. `tramp-local-host-p' is also called for "smb" and
3854 ;; alike, where it must fail.
3855 (tramp-get-method-parameter
3856 (tramp-file-name-method vec
) 'tramp-login-program
)
3857 ;; The local temp directory must be writable for the other user.
3859 (tramp-make-tramp-file-name
3860 (tramp-file-name-method vec
)
3861 (tramp-file-name-user vec
)
3863 (tramp-compat-temporary-file-directory)))
3864 ;; On some systems, chown runs only for root.
3865 (or (zerop (user-uid))
3866 ;; This is defined in tramp-sh.el. Let's assume this is
3868 (zerop (tramp-compat-funcall 'tramp-get-remote-uid vec
'integer
))))))
3870 (defun tramp-get-remote-tmpdir (vec)
3871 "Return directory for temporary files on the remote host identified by VEC."
3872 (with-tramp-connection-property vec
"tmpdir"
3873 (let ((dir (tramp-make-tramp-file-name
3874 (tramp-file-name-method vec
)
3875 (tramp-file-name-user vec
)
3876 (tramp-file-name-host vec
)
3878 (tramp-get-method-parameter
3879 (tramp-file-name-method vec
) 'tramp-tmpdir
)
3881 (if (and (file-directory-p dir
) (file-writable-p dir
))
3883 (tramp-error vec
'file-error
"Directory %s not accessible" dir
)))))
3885 ;;;###tramp-autoload
3886 (defun tramp-make-tramp-temp-file (vec)
3887 "Create a temporary file on the remote host identified by VEC.
3888 Return the local name of the temporary file."
3889 (let ((prefix (expand-file-name
3890 tramp-temp-name-prefix
(tramp-get-remote-tmpdir vec
)))
3893 ;; `make-temp-file' would be the natural choice for
3894 ;; implementation. But it calls `write-region' internally,
3895 ;; which also needs a temporary file - we would end in an
3897 (setq result
(make-temp-name prefix
))
3898 (if (file-exists-p result
)
3900 ;; This creates the file by side effect.
3901 (set-file-times result
)
3902 (set-file-modes result
(tramp-compat-octal-to-decimal "0700"))))
3904 ;; Return the local part.
3905 (with-parsed-tramp-file-name result nil localname
)))
3907 (defun tramp-delete-temp-file-function ()
3908 "Remove temporary files related to current buffer."
3909 (when (stringp tramp-temp-buffer-file-name
)
3910 (ignore-errors (delete-file tramp-temp-buffer-file-name
))))
3912 (add-hook 'kill-buffer-hook
'tramp-delete-temp-file-function
)
3913 (add-hook 'tramp-unload-hook
3915 (remove-hook 'kill-buffer-hook
3916 'tramp-delete-temp-file-function
)))
3918 ;;; Auto saving to a special directory:
3920 (defun tramp-handle-make-auto-save-file-name ()
3921 "Like `make-auto-save-file-name' for Tramp files.
3922 Returns a file name in `tramp-auto-save-directory' for autosaving this file."
3923 (let ((tramp-auto-save-directory tramp-auto-save-directory
)
3925 (tramp-subst-strs-in-string
3932 (buffer-file-name))))
3933 ;; File name must be unique. This is ensured with Emacs 22 (see
3934 ;; UNIQUIFY element of `auto-save-file-name-transforms'); but for
3935 ;; all other cases we must do it ourselves.
3936 (when (boundp 'auto-save-file-name-transforms
)
3939 (when (and (string-match (car x
) buffer-file-name
)
3940 (not (car (cddr x
))))
3941 (setq tramp-auto-save-directory
3942 (or tramp-auto-save-directory
3943 (tramp-compat-temporary-file-directory)))))
3944 (symbol-value 'auto-save-file-name-transforms
)))
3945 ;; Create directory.
3946 (when tramp-auto-save-directory
3947 (setq buffer-file-name
3948 (expand-file-name buffer-file-name tramp-auto-save-directory
))
3949 (unless (file-exists-p tramp-auto-save-directory
)
3950 (make-directory tramp-auto-save-directory t
)))
3951 ;; Run plain `make-auto-save-file-name'. There might be an advice when
3952 ;; it is not a magic file name operation (since Emacs 22).
3953 ;; We must deactivate it temporarily.
3954 (if (not (ad-is-active 'make-auto-save-file-name
))
3955 (tramp-run-real-handler 'make-auto-save-file-name nil
)
3957 (ad-deactivate 'make-auto-save-file-name
)
3959 (tramp-run-real-handler 'make-auto-save-file-name nil
)
3960 (ad-activate 'make-auto-save-file-name
)))))
3962 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name
)
3963 (defadvice make-auto-save-file-name
3964 (around tramp-advice-make-auto-save-file-name
() activate
)
3965 "Invoke `tramp-*-handle-make-auto-save-file-name' for Tramp files."
3966 (if (tramp-tramp-file-p (buffer-file-name))
3967 ;; We cannot call `tramp-handle-make-auto-save-file-name'
3968 ;; directly, because this would bypass the locking mechanism.
3969 (setq ad-return-value
3970 (tramp-file-name-handler 'make-auto-save-file-name
))
3976 'make-auto-save-file-name
3977 'around
'tramp-advice-make-auto-save-file-name
)
3978 (ad-activate 'make-auto-save-file-name
))))
3980 ;; In XEmacs < 21.5, autosaved remote files have permission 0666 minus
3981 ;; umask. This is a security threat.
3983 (defun tramp-set-auto-save-file-modes ()
3984 "Set permissions of autosaved remote files to the original permissions."
3985 (let ((bfn (buffer-file-name)))
3986 (when (and (tramp-tramp-file-p bfn
)
3988 (stringp buffer-auto-save-file-name
)
3989 (not (equal bfn buffer-auto-save-file-name
)))
3990 (unless (file-exists-p buffer-auto-save-file-name
)
3991 (write-region "" nil buffer-auto-save-file-name
))
3992 ;; Permissions should be set always, because there might be an old
3993 ;; auto-saved file belonging to another original file. This could
3994 ;; be a security threat.
3996 buffer-auto-save-file-name
3997 (or (file-modes bfn
) (tramp-compat-octal-to-decimal "0600"))))))
3999 (unless (and (featurep 'xemacs
)
4000 (= emacs-major-version
21)
4001 (> emacs-minor-version
4))
4002 (add-hook 'auto-save-hook
'tramp-set-auto-save-file-modes
)
4003 (add-hook 'tramp-unload-hook
4005 (remove-hook 'auto-save-hook
'tramp-set-auto-save-file-modes
))))
4007 (defun tramp-subst-strs-in-string (alist string
)
4008 "Replace all occurrences of the string FROM with TO in STRING.
4009 ALIST is of the form ((FROM . TO) ...)."
4012 (let* ((pr (car alist
))
4015 (while (string-match (regexp-quote from
) string
)
4016 (setq string
(replace-match to t t string
)))
4017 (setq alist
(cdr alist
))))
4020 ;;; Compatibility functions section:
4022 (defun tramp-call-process
4023 (program &optional infile destination display
&rest args
)
4024 "Calls `call-process' on the local host.
4025 This is needed because for some Emacs flavors Tramp has
4026 defadvised `call-process' to behave like `process-file'. The
4027 Lisp error raised when PROGRAM is nil is trapped also, returning 1.
4028 Furthermore, traces are written with verbosity of 6."
4030 (vector tramp-current-method tramp-current-user tramp-current-host nil nil
)
4031 6 "%s %s %s" program infile args
)
4032 (if (executable-find program
)
4033 (apply 'call-process program infile destination display args
)
4036 ;;;###tramp-autoload
4037 (defun tramp-read-passwd (proc &optional prompt
)
4038 "Read a password from user (compat function).
4039 Consults the auth-source package.
4040 Invokes `password-read' if available, `read-passwd' else."
4041 (let* ((key (tramp-make-tramp-file-name
4042 tramp-current-method tramp-current-user
4043 tramp-current-host
""))
4046 (with-current-buffer (process-buffer proc
)
4047 (tramp-check-for-regexp proc tramp-password-prompt-regexp
)
4048 (format "%s for %s " (capitalize (match-string 1)) key
))))
4049 auth-info auth-passwd
)
4050 (with-parsed-tramp-file-name key nil
4053 ;; See if auth-sources contains something useful, if it's
4054 ;; bound. `auth-source-user-or-password' is an obsoleted
4055 ;; function, it has been replaced by `auth-source-search'.
4056 (and (boundp 'auth-sources
)
4057 (tramp-get-connection-property v
"first-password-request" nil
)
4058 ;; Try with Tramp's current method.
4059 (if (fboundp 'auth-source-search
)
4061 (tramp-compat-funcall
4064 :user
(or tramp-current-user t
)
4065 :host tramp-current-host
4066 :port tramp-current-method
)
4067 auth-passwd
(plist-get (nth 0 auth-info
) :secret
)
4068 auth-passwd
(if (functionp auth-passwd
)
4069 (funcall auth-passwd
)
4071 (tramp-compat-funcall
4072 'auth-source-user-or-password
4073 "password" tramp-current-host tramp-current-method
)))
4074 ;; Try the password cache.
4075 (when (functionp 'password-read
)
4076 (unless (tramp-get-connection-property
4077 v
"first-password-request" nil
)
4078 (tramp-compat-funcall 'password-cache-remove key
))
4080 (tramp-compat-funcall 'password-read pw-prompt key
)))
4081 (tramp-compat-funcall 'password-cache-add key password
)
4083 ;; Else, get the password interactively.
4084 (read-passwd pw-prompt
))
4085 (tramp-set-connection-property v
"first-password-request" nil
)))))
4087 ;;;###tramp-autoload
4088 (defun tramp-clear-passwd (vec)
4089 "Clear password cache for connection related to VEC."
4090 (tramp-compat-funcall
4091 'password-cache-remove
4092 (tramp-make-tramp-file-name
4093 (tramp-file-name-method vec
)
4094 (tramp-file-name-user vec
)
4095 (tramp-file-name-host vec
)
4098 ;; Snarfed code from time-date.el and parse-time.el
4100 (defconst tramp-half-a-year
'(241 17024)
4101 "Evaluated by \"(days-to-time 183)\".")
4103 (defconst tramp-parse-time-months
4104 '(("jan" .
1) ("feb" .
2) ("mar" .
3)
4105 ("apr" .
4) ("may" .
5) ("jun" .
6)
4106 ("jul" .
7) ("aug" .
8) ("sep" .
9)
4107 ("oct" .
10) ("nov" .
11) ("dec" .
12))
4108 "Alist mapping month names to integers.")
4110 ;; FIXME: Shouldn't this also look at any subseconds parts of T1 and T2?
4111 ;;;###tramp-autoload
4112 (defun tramp-time-less-p (t1 t2
)
4113 "Say whether time value T1 is less than time value T2."
4114 (unless t1
(setq t1
'(0 0)))
4115 (unless t2
(setq t2
'(0 0)))
4116 (or (< (car t1
) (car t2
))
4117 (and (= (car t1
) (car t2
))
4118 (< (nth 1 t1
) (nth 1 t2
)))))
4120 ;; FIXME: Shouldn't this also look at any subseconds parts of T1 and T2?
4121 (defun tramp-time-subtract (t1 t2
)
4122 "Subtract two time values.
4123 Return the difference in the format of a time value."
4124 (unless t1
(setq t1
'(0 0)))
4125 (unless t2
(setq t2
'(0 0)))
4126 (let ((borrow (< (cadr t1
) (cadr t2
))))
4127 (list (- (car t1
) (car t2
) (if borrow
1 0))
4128 (- (+ (if borrow
65536 0) (cadr t1
)) (cadr t2
)))))
4130 ;;;###tramp-autoload
4131 (defun tramp-time-diff (t1 t2
)
4132 "Return the difference between the two times, in seconds.
4133 T1 and T2 are time values (as returned by `current-time' for example)."
4134 (cond ((and (fboundp 'subtract-time
)
4135 (fboundp 'float-time
))
4136 (tramp-compat-funcall
4137 'float-time
(tramp-compat-funcall 'subtract-time t1 t2
)))
4138 ((and (fboundp 'subtract-time
)
4139 (fboundp 'time-to-seconds
))
4140 (tramp-compat-funcall
4141 'time-to-seconds
(tramp-compat-funcall 'subtract-time t1 t2
)))
4142 ((fboundp 'itimer-time-difference
)
4143 (tramp-compat-funcall
4144 'itimer-time-difference
4145 (if (< (length t1
) 3) (append t1
'(0)) t1
)
4146 (if (< (length t2
) 3) (append t2
'(0)) t2
)))
4148 (let ((time (tramp-time-subtract t1 t2
)))
4149 (+ (* (car time
) 65536.0)
4151 (/ (or (nth 2 time
) 0) 1000000.0))))))
4153 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
4154 ;; does not deal well with newline characters. Newline is replaced by
4155 ;; backslash newline. But if, say, the string `a backslash newline b'
4156 ;; is passed to a shell, the shell will expand this into "ab",
4157 ;; completely omitting the newline. This is not what was intended.
4158 ;; It does not appear to be possible to make the function
4159 ;; `shell-quote-argument' work with newlines without making it
4160 ;; dependent on the shell used. But within this package, we know that
4161 ;; we will always use a Bourne-like shell, so we use an approach which
4164 ;; The approach is simple: we call `shell-quote-argument', then
4165 ;; massage the newline part of the result.
4167 ;; This function should produce a string which is grokked by a Unix
4168 ;; shell, even if the Emacs is running on Windows. Since this is the
4169 ;; kludges section, we bind `system-type' in such a way that
4170 ;; `shell-quote-arguments' behaves as if on Unix.
4172 ;; Thanks to Mario DeWeerd for the hint that it is sufficient for this
4173 ;; function to work with Bourne-like shells.
4175 ;; CCC: This function should be rewritten so that
4176 ;; `shell-quote-argument' is not used. This way, we are safe from
4177 ;; changes in `shell-quote-argument'.
4178 ;;;###tramp-autoload
4179 (defun tramp-shell-quote-argument (s)
4180 "Similar to `shell-quote-argument', but groks newlines.
4181 Only works for Bourne-like shells."
4182 (let ((system-type 'not-windows
))
4184 (let ((result (shell-quote-argument s
))
4185 (nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line
))))
4186 (when (and (>= (length result
) 2)
4187 (string= (substring result
0 2) "\\~"))
4188 (setq result
(substring result
1)))
4189 (while (string-match nl result
)
4190 (setq result
(replace-match (format "'%s'" tramp-rsh-end-of-line
)
4194 ;;; Integration of eshell.el:
4196 ;; eshell.el keeps the path in `eshell-path-env'. We must change it
4197 ;; when `default-directory' points to another host.
4198 (defun tramp-eshell-directory-change ()
4199 "Set `eshell-path-env' to $PATH of the host related to `default-directory'."
4200 (setq eshell-path-env
4201 (if (tramp-tramp-file-p default-directory
)
4202 (with-parsed-tramp-file-name default-directory nil
4206 ;; When `tramp-own-remote-path' is in `tramp-remote-path',
4207 ;; the remote path is only set in the session cache.
4208 (tramp-get-connection-property
4209 (tramp-get-connection-process v
) "remote-path" nil
)
4210 (tramp-get-connection-property v
"remote-path" nil
))
4214 (eval-after-load "esh-util"
4216 (tramp-eshell-directory-change)
4217 (add-hook 'eshell-directory-change-hook
4218 'tramp-eshell-directory-change
)
4219 (add-hook 'tramp-unload-hook
4221 (remove-hook 'eshell-directory-change-hook
4222 'tramp-eshell-directory-change
)))))
4224 ;; Checklist for `tramp-unload-hook'
4225 ;; - Unload all `tramp-*' packages
4226 ;; - Reset `file-name-handler-alist'
4227 ;; - Cleanup hooks where Tramp functions are in
4228 ;; - Cleanup advised functions
4229 ;; - Cleanup autoloads
4231 (defun tramp-unload-tramp ()
4232 "Discard Tramp from loading remote files."
4234 ;; ange-ftp settings must be enabled.
4235 (tramp-compat-funcall 'tramp-ftp-enable-ange-ftp
)
4236 ;; Maybe it's not loaded yet.
4237 (ignore-errors (unload-feature 'tramp
'force
)))
4243 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
4244 ;; `shell-quote-argument'.
4245 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
4246 ;; by the files in that directory. Add this here.
4247 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
4248 ;; * abbreviate-file-name
4249 ;; * Better error checking. At least whenever we see something
4250 ;; strange when doing zerop, we should kill the process and start
4251 ;; again. (Greg Stark)
4252 ;; * Username and hostname completion.
4253 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'.
4254 ;; * Make `tramp-default-user' obsolete.
4255 ;; * Implement a general server-local-variable mechanism, as there are
4256 ;; probably other variables that need different values for different
4257 ;; servers too. The user could then configure a variable (such as
4258 ;; tramp-server-local-variable-alist) to define any such variables
4259 ;; that they need to, which would then be let bound as appropriate
4260 ;; in tramp functions. (Jason Rumney)
4261 ;; * IMHO, it's a drawback that currently Tramp doesn't support
4262 ;; Unicode in Dired file names by default. Is it possible to
4263 ;; improve Tramp to set LC_ALL to "C" only for commands where Tramp
4264 ;; expects English? Or just to set LC_MESSAGES to "C" if Tramp
4265 ;; expects only English messages? (Juri Linkov)
4266 ;; * Make shadowfile.el grok Tramp filenames. (Bug#4526, Bug#4846)
4267 ;; * I was wondering if it would be possible to use tramp even if I'm
4268 ;; actually using sshfs. But when I launch a command I would like
4269 ;; to get it executed on the remote machine where the files really
4270 ;; are. (Andrea Crotti)
4271 ;; * Run emerge on two remote files. Bug is described here:
4272 ;; <http://www.mail-archive.com/tramp-devel@nongnu.org/msg01041.html>.
4274 ;; * Use also port to distinguish connections. This is needed for
4275 ;; different hosts sitting behind a single router (distinguished by
4276 ;; different port numbers). (Tzvi Edelman)
4278 ;;; tramp.el ends here