]> code.delx.au - gnu-emacs/blob - lisp/net/tramp.el
Merge from mainline.
[gnu-emacs] / lisp / net / tramp.el
1 ;;; tramp.el --- Transparent Remote Access, Multiple Protocol
2
3 ;; Copyright (C) 1998-2012 Free Software Foundation, Inc.
4
5 ;; Author: Kai Großjohann <kai.grossjohann@gmx.net>
6 ;; Michael Albinus <michael.albinus@gmx.de>
7 ;; Keywords: comm, processes
8 ;; Package: tramp
9
10 ;; This file is part of GNU Emacs.
11
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.
16
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.
21
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/>.
24
25 ;;; Commentary:
26
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.
31 ;;
32 ;; For more detailed instructions, please see the info file.
33 ;;
34 ;; Notes:
35 ;; -----
36 ;;
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.
40 ;;
41 ;; Also see the todo list at the bottom of this file.
42 ;;
43 ;; The current version of Tramp can be retrieved from the following URL:
44 ;; http://ftp.gnu.org/gnu/tramp/
45 ;;
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
50 ;;
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.
55 ;;
56 ;; Don't forget to put on your asbestos longjohns, first!
57
58 ;;; Code:
59
60 (eval-when-compile (require 'cl)) ; ignore-errors
61 (require 'tramp-compat)
62
63 ;;; User Customizable Internal Variables:
64
65 (defgroup tramp nil
66 "Edit remote files with a combination of ssh, scp, etc."
67 :group 'files
68 :group 'comm
69 :version "22.1")
70
71 ;; Maybe we need once a real Tramp mode, with key bindings etc.
72 ;;;###autoload
73 (defcustom tramp-mode t
74 "Whether Tramp is enabled.
75 If it is set to nil, all remote file names are used literally."
76 :group 'tramp
77 :type 'boolean)
78
79 (defcustom tramp-verbose 3
80 "Verbosity level for Tramp messages.
81 Any level x includes messages for all levels 1 .. x-1. The levels are
82
83 0 silent (no tramp messages at all)
84 1 errors
85 2 warnings
86 3 connection to remote hosts (default level)
87 4 activities
88 5 internal
89 6 sent and received strings
90 7 file caching
91 8 connection properties
92 9 test commands
93 10 traces (huge)."
94 :group 'tramp
95 :type 'integer)
96
97 ;; Emacs case.
98 (eval-and-compile
99 (when (boundp 'backup-directory-alist)
100 (defcustom tramp-backup-directory-alist nil
101 "Alist of filename patterns and backup directory names.
102 Each element looks like (REGEXP . DIRECTORY), with the same meaning like
103 in `backup-directory-alist'. If a Tramp file is backed up, and DIRECTORY
104 is a local file name, the backup directory is prepended with Tramp file
105 name prefix \(method, user, host\) of file.
106
107 \(setq tramp-backup-directory-alist backup-directory-alist\)
108
109 gives the same backup policy for Tramp files on their hosts like the
110 policy for local files."
111 :group 'tramp
112 :type '(repeat (cons (regexp :tag "Regexp matching filename")
113 (directory :tag "Backup directory name"))))))
114
115 ;; XEmacs case. We cannot check for `bkup-backup-directory-info', because
116 ;; the package "backup-dir" might not be loaded yet.
117 (eval-and-compile
118 (when (featurep 'xemacs)
119 (defcustom tramp-bkup-backup-directory-info nil
120 "Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
121 It has the same meaning like `bkup-backup-directory-info' from package
122 `backup-dir'. If a Tramp file is backed up, and BACKUP-DIR is a local
123 file name, the backup directory is prepended with Tramp file name prefix
124 \(method, user, host\) of file.
125
126 \(setq tramp-bkup-backup-directory-info bkup-backup-directory-info\)
127
128 gives the same backup policy for Tramp files on their hosts like the
129 policy for local files."
130 :type '(repeat
131 (list (regexp :tag "File regexp")
132 (string :tag "Backup Dir")
133 (set :inline t
134 (const ok-create)
135 (const full-path)
136 (const prepend-name)
137 (const search-upward))))
138 :group 'tramp)))
139
140 (defcustom tramp-auto-save-directory nil
141 "Put auto-save files in this directory, if set.
142 The idea is to use a local directory so that auto-saving is faster."
143 :group 'tramp
144 :type '(choice (const nil) string))
145
146 (defcustom tramp-encoding-shell
147 (if (memq system-type '(windows-nt))
148 (getenv "COMSPEC")
149 "/bin/sh")
150 "Use this program for encoding and decoding commands on the local host.
151 This shell is used to execute the encoding and decoding command on the
152 local host, so if you want to use `~' in those commands, you should
153 choose a shell here which groks tilde expansion. `/bin/sh' normally
154 does not understand tilde expansion.
155
156 For encoding and decoding, commands like the following are executed:
157
158 /bin/sh -c COMMAND < INPUT > OUTPUT
159
160 This variable can be used to change the \"/bin/sh\" part. See the
161 variable `tramp-encoding-command-switch' for the \"-c\" part.
162
163 If the shell must be forced to be interactive, see
164 `tramp-encoding-command-interactive'.
165
166 Note that this variable is not used for remote commands. There are
167 mechanisms in tramp.el which automatically determine the right shell to
168 use for the remote host."
169 :group 'tramp
170 :type '(file :must-match t))
171
172 (defcustom tramp-encoding-command-switch
173 (if (string-match "cmd\\.exe" tramp-encoding-shell)
174 "/c"
175 "-c")
176 "Use this switch together with `tramp-encoding-shell' for local commands.
177 See the variable `tramp-encoding-shell' for more information."
178 :group 'tramp
179 :type 'string)
180
181 (defcustom tramp-encoding-command-interactive
182 (unless (string-match "cmd\\.exe" tramp-encoding-shell) "-i")
183 "Use this switch together with `tramp-encoding-shell' for interactive shells.
184 See the variable `tramp-encoding-shell' for more information."
185 :version "24.1"
186 :group 'tramp
187 :type '(choice (const nil) string))
188
189 ;;;###tramp-autoload
190 (defvar tramp-methods nil
191 "Alist of methods for remote files.
192 This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
193 Each NAME stands for a remote access method. Each PARAM is a
194 pair of the form (KEY VALUE). The following KEYs are defined:
195 * `tramp-remote-shell'
196 This specifies the shell to use on the remote host. This
197 MUST be a Bourne-like shell. It is normally not necessary to
198 set this to any value other than \"/bin/sh\": Tramp wants to
199 use a shell which groks tilde expansion, but it can search
200 for it. Also note that \"/bin/sh\" exists on all Unixen,
201 this might not be true for the value that you decide to use.
202 You Have Been Warned.
203 * `tramp-remote-shell-args'
204 For implementation of `shell-command', this specifies the
205 arguments to let `tramp-remote-shell' run a single command.
206 * `tramp-login-program'
207 This specifies the name of the program to use for logging in to the
208 remote host. This may be the name of rsh or a workalike program,
209 or the name of telnet or a workalike, or the name of su or a workalike.
210 * `tramp-login-args'
211 This specifies the list of arguments to pass to the above
212 mentioned program. Please note that this is a list of list of arguments,
213 that is, normally you don't want to put \"-a -b\" or \"-f foo\"
214 here. Instead, you want a list (\"-a\" \"-b\"), or (\"-f\" \"foo\").
215 There are some patterns: \"%h\" in this list is replaced by the host
216 name, \"%u\" is replaced by the user name, \"%p\" is replaced by the
217 port number, and \"%%\" can be used to obtain a literal percent character.
218 If a list containing \"%h\", \"%u\" or \"%p\" is unchanged during
219 expansion (i.e. no host or no user specified), this list is not used as
220 argument. By this, arguments like (\"-l\" \"%u\") are optional.
221 \"%t\" is replaced by the temporary file name produced with
222 `tramp-make-tramp-temp-file'. \"%k\" indicates the keep-date
223 parameter of a program, if exists.
224 * `tramp-async-args'
225 When an asynchronous process is started, we know already that
226 the connection works. Therefore, we can pass additional
227 parameters to suppress diagnostic messages, in order not to
228 tamper the process output.
229 * `tramp-copy-program'
230 This specifies the name of the program to use for remotely copying
231 the file; this might be the absolute filename of rcp or the name of
232 a workalike program.
233 * `tramp-copy-args'
234 This specifies the list of parameters to pass to the above mentioned
235 program, the hints for `tramp-login-args' also apply here.
236 * `tramp-copy-keep-date'
237 This specifies whether the copying program when the preserves the
238 timestamp of the original file.
239 * `tramp-copy-keep-tmpfile'
240 This specifies whether a temporary local file shall be kept
241 for optimization reasons (useful for \"rsync\" methods).
242 * `tramp-copy-recursive'
243 Whether the operation copies directories recursively.
244 * `tramp-default-port'
245 The default port of a method is needed in case of gateway connections.
246 Additionally, it is used as indication which method is prepared for
247 passing gateways.
248 * `tramp-gw-args'
249 As the attribute name says, additional arguments are specified here
250 when a method is applied via a gateway.
251 * `tramp-tmpdir'
252 A directory on the remote host for temporary files. If not
253 specified, \"/tmp\" is taken as default.
254
255 What does all this mean? Well, you should specify `tramp-login-program'
256 for all methods; this program is used to log in to the remote site. Then,
257 there are two ways to actually transfer the files between the local and the
258 remote side. One way is using an additional rcp-like program. If you want
259 to do this, set `tramp-copy-program' in the method.
260
261 Another possibility for file transfer is inline transfer, i.e. the
262 file is passed through the same buffer used by `tramp-login-program'. In
263 this case, the file contents need to be protected since the
264 `tramp-login-program' might use escape codes or the connection might not
265 be eight-bit clean. Therefore, file contents are encoded for transit.
266 See the variables `tramp-local-coding-commands' and
267 `tramp-remote-coding-commands' for details.
268
269 So, to summarize: if the method is an out-of-band method, then you
270 must specify `tramp-copy-program' and `tramp-copy-args'. If it is an
271 inline method, then these two parameters should be nil. Methods which
272 are fit for gateways must have `tramp-default-port' at least.
273
274 Notes:
275
276 When using `su' or `sudo' the phrase `open connection to a remote
277 host' sounds strange, but it is used nevertheless, for consistency.
278 No connection is opened to a remote host, but `su' or `sudo' is
279 started on the local host. You should specify a remote host
280 `localhost' or the name of the local host. Another host name is
281 useful only in combination with `tramp-default-proxies-alist'.")
282
283 (defun tramp-detect-ssh-controlmaster ()
284 "Call ssh to detect whether it supports the ControlMaster argument.
285 This function may return nil when the argument is supported, but
286 shouldn't return t when it isn't."
287 (ignore-errors
288 (with-temp-buffer
289 (call-process "ssh" nil t nil "-o" "ControlMaster")
290 (goto-char (point-min))
291 (search-forward-regexp "Missing ControlMaster argument" nil t))))
292
293 (defcustom tramp-default-method
294 ;; An external copy method seems to be preferred, because it performs
295 ;; much better for large files, and it hasn't too serious delays
296 ;; for small files. But it must be ensured that there aren't
297 ;; permanent password queries. Either a password agent like
298 ;; "ssh-agent" or "Pageant" shall run, or the optional
299 ;; password-cache.el or auth-sources.el packages shall be active for
300 ;; password caching. "scpc" is chosen if we detect that the user is
301 ;; running OpenSSH 4.0 or newer.
302 (cond
303 ;; PuTTY is installed. We don't take it, if it is installed on a
304 ;; non-windows system, or pscp from the pssh (parallel ssh) package
305 ;; is found.
306 ((and (eq system-type 'windows-nt)
307 (executable-find "pscp"))
308 (if (or (fboundp 'password-read)
309 (fboundp 'auth-source-user-or-password)
310 (fboundp 'auth-source-search)
311 ;; Pageant is running.
312 (tramp-compat-process-running-p "Pageant"))
313 "pscp"
314 "plink"))
315 ;; There is an ssh installation.
316 ((executable-find "scp")
317 (cond
318 ((tramp-detect-ssh-controlmaster) "scpc")
319 ((or (fboundp 'password-read)
320 (fboundp 'auth-source-user-or-password)
321 (fboundp 'auth-source-search)
322 ;; ssh-agent is running.
323 (getenv "SSH_AUTH_SOCK")
324 (getenv "SSH_AGENT_PID"))
325 "scp")
326 (t "ssh")))
327 ;; Fallback.
328 (t "ftp"))
329 "Default method to use for transferring files.
330 See `tramp-methods' for possibilities.
331 Also see `tramp-default-method-alist'."
332 :group 'tramp
333 :type 'string)
334
335 ;;;###tramp-autoload
336 (defcustom tramp-default-method-alist nil
337 "Default method to use for specific host/user pairs.
338 This is an alist of items (HOST USER METHOD). The first matching item
339 specifies the method to use for a file name which does not specify a
340 method. HOST and USER are regular expressions or nil, which is
341 interpreted as a regular expression which always matches. If no entry
342 matches, the variable `tramp-default-method' takes effect.
343
344 If the file name does not specify the user, lookup is done using the
345 empty string for the user name.
346
347 See `tramp-methods' for a list of possibilities for METHOD."
348 :group 'tramp
349 :type '(repeat (list (choice :tag "Host regexp" regexp sexp)
350 (choice :tag "User regexp" regexp sexp)
351 (choice :tag "Method name" string (const nil)))))
352
353 (defcustom tramp-default-user nil
354 "Default user to use for transferring files.
355 It is nil by default; otherwise settings in configuration files like
356 \"~/.ssh/config\" would be overwritten. Also see `tramp-default-user-alist'.
357
358 This variable is regarded as obsolete, and will be removed soon."
359 :group 'tramp
360 :type '(choice (const nil) string))
361
362 ;;;###tramp-autoload
363 (defcustom tramp-default-user-alist nil
364 "Default user to use for specific method/host pairs.
365 This is an alist of items (METHOD HOST USER). The first matching item
366 specifies the user to use for a file name which does not specify a
367 user. METHOD and USER are regular expressions or nil, which is
368 interpreted as a regular expression which always matches. If no entry
369 matches, the variable `tramp-default-user' takes effect.
370
371 If the file name does not specify the method, lookup is done using the
372 empty string for the method name."
373 :group 'tramp
374 :type '(repeat (list (choice :tag "Method regexp" regexp sexp)
375 (choice :tag " Host regexp" regexp sexp)
376 (choice :tag " User name" string (const nil)))))
377
378 (defcustom tramp-default-host (system-name)
379 "Default host to use for transferring files.
380 Useful for su and sudo methods mostly."
381 :group 'tramp
382 :type 'string)
383
384 (defcustom tramp-default-proxies-alist nil
385 "Route to be followed for specific host/user pairs.
386 This is an alist of items (HOST USER PROXY). The first matching
387 item specifies the proxy to be passed for a file name located on
388 a remote target matching USER@HOST. HOST and USER are regular
389 expressions. PROXY must be a Tramp filename without a localname
390 part. Method and user name on PROXY are optional, which is
391 interpreted with the default values. PROXY can contain the
392 patterns %h and %u, which are replaced by the strings matching
393 HOST or USER, respectively.
394
395 HOST, USER or PROXY could also be Lisp forms, which will be
396 evaluated. The result must be a string or nil, which is
397 interpreted as a regular expression which always matches."
398 :group 'tramp
399 :type '(repeat (list (choice :tag "Host regexp" regexp sexp)
400 (choice :tag "User regexp" regexp sexp)
401 (choice :tag " Proxy name" string (const nil)))))
402
403 (defcustom tramp-save-ad-hoc-proxies nil
404 "Whether to save ad-hoc proxies persistently."
405 :group 'tramp
406 :version "24.3"
407 :type 'boolean)
408
409 (defcustom tramp-restricted-shell-hosts-alist
410 (when (memq system-type '(windows-nt))
411 (list (concat "\\`" (regexp-quote (system-name)) "\\'")))
412 "List of hosts, which run a restricted shell.
413 This is a list of regular expressions, which denote hosts running
414 a registered shell like \"rbash\". Those hosts can be used as
415 proxies only, see `tramp-default-proxies-alist'. If the local
416 host runs a registered shell, it shall be added to this list, too."
417 :version "24.3"
418 :group 'tramp
419 :type '(repeat (regexp :tag "Host regexp")))
420
421 ;;;###tramp-autoload
422 (defconst tramp-local-host-regexp
423 (concat
424 "\\`"
425 (regexp-opt
426 (list "localhost" "localhost6" (system-name) "127\.0\.0\.1" "::1") t)
427 "\\'")
428 "Host names which are regarded as local host.")
429
430 (defvar tramp-completion-function-alist nil
431 "Alist of methods for remote files.
432 This is a list of entries of the form \(NAME PAIR1 PAIR2 ...\).
433 Each NAME stands for a remote access method. Each PAIR is of the form
434 \(FUNCTION FILE\). FUNCTION is responsible to extract user names and host
435 names from FILE for completion. The following predefined FUNCTIONs exists:
436
437 * `tramp-parse-rhosts' for \"~/.rhosts\" like files,
438 * `tramp-parse-shosts' for \"~/.ssh/known_hosts\" like files,
439 * `tramp-parse-sconfig' for \"~/.ssh/config\" like files,
440 * `tramp-parse-shostkeys' for \"~/.ssh2/hostkeys/*\" like files,
441 * `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
442 * `tramp-parse-hosts' for \"/etc/hosts\" like files,
443 * `tramp-parse-passwd' for \"/etc/passwd\" like files.
444 * `tramp-parse-netrc' for \"~/.netrc\" like files.
445 * `tramp-parse-putty' for PuTTY registered sessions.
446
447 FUNCTION can also be a customer defined function. For more details see
448 the info pages.")
449
450 (defconst tramp-echo-mark-marker "_echo"
451 "String marker to surround echoed commands.")
452
453 (defconst tramp-echo-mark-marker-length (length tramp-echo-mark-marker)
454 "String length of `tramp-echo-mark-marker'.")
455
456 (defconst tramp-echo-mark
457 (concat tramp-echo-mark-marker
458 (make-string tramp-echo-mark-marker-length ?\b))
459 "String mark to be transmitted around shell commands.
460 Used to separate their echo from the output they produce. This
461 will only be used if we cannot disable remote echo via stty.
462 This string must have no effect on the remote shell except for
463 producing some echo which can later be detected by
464 `tramp-echoed-echo-mark-regexp'. Using `tramp-echo-mark-marker',
465 followed by an equal number of backspaces to erase them will
466 usually suffice.")
467
468 (defconst tramp-echoed-echo-mark-regexp
469 (format "%s\\(\b\\( \b\\)?\\)\\{%d\\}"
470 tramp-echo-mark-marker tramp-echo-mark-marker-length)
471 "Regexp which matches `tramp-echo-mark' as it gets echoed by
472 the remote shell.")
473
474 (defcustom tramp-local-end-of-line
475 (if (memq system-type '(windows-nt)) "\r\n" "\n")
476 "String used for end of line in local processes."
477 :version "24.1"
478 :group 'tramp
479 :type 'string)
480
481 (defcustom tramp-rsh-end-of-line "\n"
482 "String used for end of line in rsh connections.
483 I don't think this ever needs to be changed, so please tell me about it
484 if you need to change this."
485 :group 'tramp
486 :type 'string)
487
488 (defcustom tramp-login-prompt-regexp
489 ".*ogin\\( .*\\)?: *"
490 "Regexp matching login-like prompts.
491 The regexp should match at end of buffer.
492
493 Sometimes the prompt is reported to look like \"login as:\"."
494 :group 'tramp
495 :type 'regexp)
496
497 (defcustom tramp-shell-prompt-pattern
498 ;; Allow a prompt to start right after a ^M since it indeed would be
499 ;; displayed at the beginning of the line (and Zsh uses it). This
500 ;; regexp works only for GNU Emacs.
501 ;; Allow also [] style prompts. They can appear only during
502 ;; connection initialization; Tramp redefines the prompt afterwards.
503 (concat (if (featurep 'xemacs) "" "\\(?:^\\|\r\\)")
504 "[^]#$%>\n]*#?[]#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*")
505 "Regexp to match prompts from remote shell.
506 Normally, Tramp expects you to configure `shell-prompt-pattern'
507 correctly, but sometimes it happens that you are connecting to a
508 remote host which sends a different kind of shell prompt. Therefore,
509 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
510 and also things matched by this variable. The default value of this
511 variable is similar to the default value of `shell-prompt-pattern',
512 which should work well in many cases.
513
514 This regexp must match both `tramp-initial-end-of-output' and
515 `tramp-end-of-output'."
516 :group 'tramp
517 :type 'regexp)
518
519 (defcustom tramp-password-prompt-regexp
520 "^.*\\([pP]assword\\|[pP]assphrase\\).*:\^@? *"
521 "Regexp matching password-like prompts.
522 The regexp should match at end of buffer.
523
524 The `sudo' program appears to insert a `^@' character into the prompt."
525 :group 'tramp
526 :type 'regexp)
527
528 (defcustom tramp-wrong-passwd-regexp
529 (concat "^.*"
530 ;; These strings should be on the last line
531 (regexp-opt '("Permission denied"
532 "Login incorrect"
533 "Login Incorrect"
534 "Connection refused"
535 "Connection closed"
536 "Timeout, server not responding."
537 "Sorry, try again."
538 "Name or service not known"
539 "Host key verification failed."
540 "No supported authentication methods left to try!") t)
541 ".*"
542 "\\|"
543 "^.*\\("
544 ;; Here comes a list of regexes, separated by \\|
545 "Received signal [0-9]+"
546 "\\).*")
547 "Regexp matching a `login failed' message.
548 The regexp should match at end of buffer."
549 :group 'tramp
550 :type 'regexp)
551
552 (defcustom tramp-yesno-prompt-regexp
553 (concat
554 (regexp-opt '("Are you sure you want to continue connecting (yes/no)?") t)
555 "\\s-*")
556 "Regular expression matching all yes/no queries which need to be confirmed.
557 The confirmation should be done with yes or no.
558 The regexp should match at end of buffer.
559 See also `tramp-yn-prompt-regexp'."
560 :group 'tramp
561 :type 'regexp)
562
563 (defcustom tramp-yn-prompt-regexp
564 (concat
565 (regexp-opt '("Store key in cache? (y/n)"
566 "Update cached key? (y/n, Return cancels connection)") t)
567 "\\s-*")
568 "Regular expression matching all y/n queries which need to be confirmed.
569 The confirmation should be done with y or n.
570 The regexp should match at end of buffer.
571 See also `tramp-yesno-prompt-regexp'."
572 :group 'tramp
573 :type 'regexp)
574
575 (defcustom tramp-terminal-prompt-regexp
576 (concat "\\("
577 "TERM = (.*)"
578 "\\|"
579 "Terminal type\\? \\[.*\\]"
580 "\\)\\s-*")
581 "Regular expression matching all terminal setting prompts.
582 The regexp should match at end of buffer.
583 The answer will be provided by `tramp-action-terminal', which see."
584 :group 'tramp
585 :type 'regexp)
586
587 (defcustom tramp-operation-not-permitted-regexp
588 (concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
589 (regexp-opt '("Operation not permitted") t))
590 "Regular expression matching keep-date problems in (s)cp operations.
591 Copying has been performed successfully already, so this message can
592 be ignored safely."
593 :group 'tramp
594 :type 'regexp)
595
596 (defcustom tramp-copy-failed-regexp
597 (concat "\\(.+: "
598 (regexp-opt '("Permission denied"
599 "not a regular file"
600 "is a directory"
601 "No such file or directory") t)
602 "\\)\\s-*")
603 "Regular expression matching copy problems in (s)cp operations."
604 :group 'tramp
605 :type 'regexp)
606
607 (defcustom tramp-process-alive-regexp
608 ""
609 "Regular expression indicating a process has finished.
610 In fact this expression is empty by intention, it will be used only to
611 check regularly the status of the associated process.
612 The answer will be provided by `tramp-action-process-alive',
613 `tramp-action-out-of-band', which see."
614 :group 'tramp
615 :type 'regexp)
616
617 (defconst tramp-temp-name-prefix "tramp."
618 "Prefix to use for temporary files.
619 If this is a relative file name (such as \"tramp.\"), it is considered
620 relative to the directory name returned by the function
621 `tramp-compat-temporary-file-directory' (which see). It may also be an
622 absolute file name; don't forget to include a prefix for the filename
623 part, though.")
624
625 (defconst tramp-temp-buffer-name " *tramp temp*"
626 "Buffer name for a temporary buffer.
627 It shall be used in combination with `generate-new-buffer-name'.")
628
629 (defvar tramp-temp-buffer-file-name nil
630 "File name of a persistent local temporary file.
631 Useful for \"rsync\" like methods.")
632 (make-variable-buffer-local 'tramp-temp-buffer-file-name)
633 (put 'tramp-temp-buffer-file-name 'permanent-local t)
634
635 ;; XEmacs is distributed with few Lisp packages. Further packages are
636 ;; installed using EFS. If we use a unified filename format, then
637 ;; Tramp is required in addition to EFS. (But why can't Tramp just
638 ;; disable EFS when Tramp is loaded? Then XEmacs can ship with EFS
639 ;; just like before.) Another reason for using a separate filename
640 ;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
641 ;; Tramp only knows how to deal with `file-name-handler-alist', not
642 ;; the other places.
643
644 ;; Currently, we have the choice between 'ftp, 'sep, and 'url.
645 ;;;###autoload
646 (defcustom tramp-syntax
647 (if (featurep 'xemacs) 'sep 'ftp)
648 "Tramp filename syntax to be used.
649
650 It can have the following values:
651
652 'ftp -- Ange-FTP respective EFS like syntax (GNU Emacs default)
653 'sep -- Syntax as defined for XEmacs (not available yet for GNU Emacs)
654 'url -- URL-like syntax."
655 :group 'tramp
656 :type (if (featurep 'xemacs)
657 '(choice (const :tag "EFS" ftp)
658 (const :tag "XEmacs" sep)
659 (const :tag "URL" url))
660 '(choice (const :tag "Ange-FTP" ftp)
661 (const :tag "URL" url))))
662
663 (defconst tramp-prefix-format
664 (cond ((equal tramp-syntax 'ftp) "/")
665 ((equal tramp-syntax 'sep) "/[")
666 ((equal tramp-syntax 'url) "/")
667 (t (error "Wrong `tramp-syntax' defined")))
668 "String matching the very beginning of Tramp file names.
669 Used in `tramp-make-tramp-file-name'.")
670
671 (defconst tramp-prefix-regexp
672 (concat "^" (regexp-quote tramp-prefix-format))
673 "Regexp matching the very beginning of Tramp file names.
674 Should always start with \"^\". Derived from `tramp-prefix-format'.")
675
676 (defconst tramp-method-regexp
677 "[a-zA-Z_0-9-]+"
678 "Regexp matching methods identifiers.")
679
680 (defconst tramp-postfix-method-format
681 (cond ((equal tramp-syntax 'ftp) ":")
682 ((equal tramp-syntax 'sep) "/")
683 ((equal tramp-syntax 'url) "://")
684 (t (error "Wrong `tramp-syntax' defined")))
685 "String matching delimiter between method and user or host names.
686 Used in `tramp-make-tramp-file-name'.")
687
688 (defconst tramp-postfix-method-regexp
689 (regexp-quote tramp-postfix-method-format)
690 "Regexp matching delimiter between method and user or host names.
691 Derived from `tramp-postfix-method-format'.")
692
693 (defconst tramp-user-regexp "[^/|: \t]+"
694 "Regexp matching user names.")
695
696 ;;;###tramp-autoload
697 (defconst tramp-prefix-domain-format "%"
698 "String matching delimiter between user and domain names.")
699
700 ;;;###tramp-autoload
701 (defconst tramp-prefix-domain-regexp
702 (regexp-quote tramp-prefix-domain-format)
703 "Regexp matching delimiter between user and domain names.
704 Derived from `tramp-prefix-domain-format'.")
705
706 (defconst tramp-domain-regexp "[-a-zA-Z0-9_.]+"
707 "Regexp matching domain names.")
708
709 (defconst tramp-user-with-domain-regexp
710 (concat "\\(" tramp-user-regexp "\\)"
711 tramp-prefix-domain-regexp
712 "\\(" tramp-domain-regexp "\\)")
713 "Regexp matching user names with domain names.")
714
715 (defconst tramp-postfix-user-format "@"
716 "String matching delimiter between user and host names.
717 Used in `tramp-make-tramp-file-name'.")
718
719 (defconst tramp-postfix-user-regexp
720 (regexp-quote tramp-postfix-user-format)
721 "Regexp matching delimiter between user and host names.
722 Derived from `tramp-postfix-user-format'.")
723
724 (defconst tramp-host-regexp "[a-zA-Z0-9_.-]+"
725 "Regexp matching host names.")
726
727 (defconst tramp-prefix-ipv6-format
728 (cond ((equal tramp-syntax 'ftp) "[")
729 ((equal tramp-syntax 'sep) "")
730 ((equal tramp-syntax 'url) "[")
731 (t (error "Wrong `tramp-syntax' defined")))
732 "String matching left hand side of IPv6 addresses.
733 Used in `tramp-make-tramp-file-name'.")
734
735 (defconst tramp-prefix-ipv6-regexp
736 (regexp-quote tramp-prefix-ipv6-format)
737 "Regexp matching left hand side of IPv6 addresses.
738 Derived from `tramp-prefix-ipv6-format'.")
739
740 ;; The following regexp is a bit sloppy. But it shall serve our
741 ;; purposes. It covers also IPv4 mapped IPv6 addresses, like in
742 ;; "::ffff:192.168.0.1".
743 (defconst tramp-ipv6-regexp
744 "\\(?:\\(?:[a-zA-Z0-9]+\\)?:\\)+[a-zA-Z0-9.]+"
745 "Regexp matching IPv6 addresses.")
746
747 (defconst tramp-postfix-ipv6-format
748 (cond ((equal tramp-syntax 'ftp) "]")
749 ((equal tramp-syntax 'sep) "")
750 ((equal tramp-syntax 'url) "]")
751 (t (error "Wrong `tramp-syntax' defined")))
752 "String matching right hand side of IPv6 addresses.
753 Used in `tramp-make-tramp-file-name'.")
754
755 (defconst tramp-postfix-ipv6-regexp
756 (regexp-quote tramp-postfix-ipv6-format)
757 "Regexp matching right hand side of IPv6 addresses.
758 Derived from `tramp-postfix-ipv6-format'.")
759
760 (defconst tramp-prefix-port-format
761 (cond ((equal tramp-syntax 'ftp) "#")
762 ((equal tramp-syntax 'sep) "#")
763 ((equal tramp-syntax 'url) ":")
764 (t (error "Wrong `tramp-syntax' defined")))
765 "String matching delimiter between host names and port numbers.")
766
767 (defconst tramp-prefix-port-regexp
768 (regexp-quote tramp-prefix-port-format)
769 "Regexp matching delimiter between host names and port numbers.
770 Derived from `tramp-prefix-port-format'.")
771
772 (defconst tramp-port-regexp "[0-9]+"
773 "Regexp matching port numbers.")
774
775 (defconst tramp-host-with-port-regexp
776 (concat "\\(" tramp-host-regexp "\\)"
777 tramp-prefix-port-regexp
778 "\\(" tramp-port-regexp "\\)")
779 "Regexp matching host names with port numbers.")
780
781 (defconst tramp-postfix-hop-format "|"
782 "String matching delimiter after ad-hoc hop definitions.")
783
784 (defconst tramp-postfix-hop-regexp
785 (regexp-quote tramp-postfix-hop-format)
786 "Regexp matching delimiter after ad-hoc hop definitions.
787 Derived from `tramp-postfix-hop-format'.")
788
789 (defconst tramp-postfix-host-format
790 (cond ((equal tramp-syntax 'ftp) ":")
791 ((equal tramp-syntax 'sep) "]")
792 ((equal tramp-syntax 'url) "")
793 (t (error "Wrong `tramp-syntax' defined")))
794 "String matching delimiter between host names and localnames.
795 Used in `tramp-make-tramp-file-name'.")
796
797 (defconst tramp-postfix-host-regexp
798 (regexp-quote tramp-postfix-host-format)
799 "Regexp matching delimiter between host names and localnames.
800 Derived from `tramp-postfix-host-format'.")
801
802 (defconst tramp-localname-regexp ".*$"
803 "Regexp matching localnames.")
804
805 ;;; File name format:
806
807 (defconst tramp-remote-file-name-spec-regexp
808 (concat
809 "\\(?:" "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp "\\)?"
810 "\\(?:" "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp "\\)?"
811 "\\(" "\\(?:" tramp-host-regexp "\\|"
812 tramp-prefix-ipv6-regexp tramp-ipv6-regexp
813 tramp-postfix-ipv6-regexp "\\)"
814 "\\(?:" tramp-prefix-port-regexp tramp-port-regexp "\\)?" "\\)?")
815 "Regular expression matching a Tramp file name between prefix and postfix.")
816
817 (defconst tramp-file-name-structure
818 (list
819 (concat
820 tramp-prefix-regexp
821 "\\(" "\\(?:" tramp-remote-file-name-spec-regexp
822 tramp-postfix-hop-regexp "\\)+" "\\)?"
823 tramp-remote-file-name-spec-regexp tramp-postfix-host-regexp
824 "\\(" tramp-localname-regexp "\\)")
825 5 6 7 8 1)
826 "List of six elements (REGEXP METHOD USER HOST FILE HOP), detailing \
827 the Tramp file name structure.
828
829 The first element REGEXP is a regular expression matching a Tramp file
830 name. The regex should contain parentheses around the method name,
831 the user name, the host name, and the file name parts.
832
833 The second element METHOD is a number, saying which pair of
834 parentheses matches the method name. The third element USER is
835 similar, but for the user name. The fourth element HOST is similar,
836 but for the host name. The fifth element FILE is for the file name.
837 The last element HOP is the ad-hoc hop definition, which could be a
838 cascade of several hops.
839
840 These numbers are passed directly to `match-string', which see. That
841 means the opening parentheses are counted to identify the pair.
842
843 See also `tramp-file-name-regexp'.")
844
845 ;;;###autoload
846 (defconst tramp-file-name-regexp-unified
847 (if (memq system-type '(cygwin windows-nt))
848 "\\`/\\([^[/|:]\\{2,\\}\\|[^/|]\\{2,\\}]\\):"
849 "\\`/\\([^[/|:]+\\|[^/|]+]\\):")
850 "Value for `tramp-file-name-regexp' for unified remoting.
851 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
852 Tramp. See `tramp-file-name-structure' for more explanations.
853
854 On W32 systems, the volume letter must be ignored.")
855
856 ;;;###autoload
857 (defconst tramp-file-name-regexp-separate "\\`/\\[.*\\]"
858 "Value for `tramp-file-name-regexp' for separate remoting.
859 XEmacs uses a separate filename syntax for Tramp and EFS.
860 See `tramp-file-name-structure' for more explanations.")
861
862 ;;;###autoload
863 (defconst tramp-file-name-regexp-url "\\`/[^/|:]+://"
864 "Value for `tramp-file-name-regexp' for URL-like remoting.
865 See `tramp-file-name-structure' for more explanations.")
866
867 ;;;###autoload
868 (defconst tramp-file-name-regexp
869 (cond ((equal tramp-syntax 'ftp) tramp-file-name-regexp-unified)
870 ((equal tramp-syntax 'sep) tramp-file-name-regexp-separate)
871 ((equal tramp-syntax 'url) tramp-file-name-regexp-url)
872 (t (error "Wrong `tramp-syntax' defined")))
873 "Regular expression matching file names handled by Tramp.
874 This regexp should match Tramp file names but no other file names.
875 When tramp.el is loaded, this regular expression is prepended to
876 `file-name-handler-alist', and that is searched sequentially. Thus,
877 if the Tramp entry appears rather early in the `file-name-handler-alist'
878 and is a bit too general, then some files might be considered Tramp
879 files which are not really Tramp files.
880
881 Please note that the entry in `file-name-handler-alist' is made when
882 this file \(tramp.el\) is loaded. This means that this variable must be set
883 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
884 updated after changing this variable.
885
886 Also see `tramp-file-name-structure'.")
887
888 ;;;###autoload
889 (defconst tramp-completion-file-name-regexp-unified
890 (if (memq system-type '(cygwin windows-nt))
891 "\\`/[^/]\\{2,\\}\\'" "\\`/[^/]*\\'")
892 "Value for `tramp-completion-file-name-regexp' for unified remoting.
893 GNU Emacs uses a unified filename syntax for Tramp and Ange-FTP.
894 See `tramp-file-name-structure' for more explanations.
895
896 On W32 systems, the volume letter must be ignored.")
897
898 ;;;###autoload
899 (defconst tramp-completion-file-name-regexp-separate
900 "\\`/\\([[][^]]*\\)?\\'"
901 "Value for `tramp-completion-file-name-regexp' for separate remoting.
902 XEmacs uses a separate filename syntax for Tramp and EFS.
903 See `tramp-file-name-structure' for more explanations.")
904
905 ;;;###autoload
906 (defconst tramp-completion-file-name-regexp-url
907 "\\`/[^/:]+\\(:\\(/\\(/[^/]*\\)?\\)?\\)?\\'"
908 "Value for `tramp-completion-file-name-regexp' for URL-like remoting.
909 See `tramp-file-name-structure' for more explanations.")
910
911 ;;;###autoload
912 (defconst tramp-completion-file-name-regexp
913 (cond ((equal tramp-syntax 'ftp) tramp-completion-file-name-regexp-unified)
914 ((equal tramp-syntax 'sep) tramp-completion-file-name-regexp-separate)
915 ((equal tramp-syntax 'url) tramp-completion-file-name-regexp-url)
916 (t (error "Wrong `tramp-syntax' defined")))
917 "Regular expression matching file names handled by Tramp completion.
918 This regexp should match partial Tramp file names only.
919
920 Please note that the entry in `file-name-handler-alist' is made when
921 this file (tramp.el) is loaded. This means that this variable must be set
922 before loading tramp.el. Alternatively, `file-name-handler-alist' can be
923 updated after changing this variable.
924
925 Also see `tramp-file-name-structure'.")
926
927 ;; Chunked sending kludge. We set this to 500 for black-listed constellations
928 ;; known to have a bug in `process-send-string'; some ssh connections appear
929 ;; to drop bytes when data is sent too quickly. There is also a connection
930 ;; buffer local variable, which is computed depending on remote host properties
931 ;; when `tramp-chunksize' is zero or nil.
932 (defcustom tramp-chunksize
933 (when (and (not (featurep 'xemacs))
934 (memq system-type '(hpux)))
935 500)
936 ;; Parentheses in docstring starting at beginning of line are escaped.
937 ;; Fontification is messed up when
938 ;; `open-paren-in-column-0-is-defun-start' set to t.
939 "If non-nil, chunksize for sending input to local process.
940 It is necessary only on systems which have a buggy `process-send-string'
941 implementation. The necessity, whether this variable must be set, can be
942 checked via the following code:
943
944 (with-temp-buffer
945 (let* ((user \"xxx\") (host \"yyy\")
946 (init 0) (step 50)
947 (sent init) (received init))
948 (while (= sent received)
949 (setq sent (+ sent step))
950 (erase-buffer)
951 (let ((proc (start-process (buffer-name) (current-buffer)
952 \"ssh\" \"-l\" user host \"wc\" \"-c\")))
953 (when (memq (process-status proc) '(run open))
954 (process-send-string proc (make-string sent ?\\ ))
955 (process-send-eof proc)
956 (process-send-eof proc))
957 (while (not (progn (goto-char (point-min))
958 (re-search-forward \"\\\\w+\" (point-max) t)))
959 (accept-process-output proc 1))
960 (when (memq (process-status proc) '(run open))
961 (setq received (string-to-number (match-string 0)))
962 (delete-process proc)
963 (message \"Bytes sent: %s\\tBytes received: %s\" sent received)
964 (sit-for 0))))
965 (if (> sent (+ init step))
966 (message \"You should set `tramp-chunksize' to a maximum of %s\"
967 (- sent step))
968 (message \"Test does not work\")
969 (display-buffer (current-buffer))
970 (sit-for 30))))
971
972 In the Emacs normally running Tramp, evaluate the above code
973 \(replace \"xxx\" and \"yyy\" by the remote user and host name,
974 respectively\). You can do this, for example, by pasting it into
975 the `*scratch*' buffer and then hitting C-j with the cursor after the
976 last closing parenthesis. Note that it works only if you have configured
977 \"ssh\" to run without password query, see ssh-agent\(1\).
978
979 You will see the number of bytes sent successfully to the remote host.
980 If that number exceeds 1000, you can stop the execution by hitting
981 C-g, because your Emacs is likely clean.
982
983 When it is necessary to set `tramp-chunksize', you might consider to
984 use an out-of-the-band method \(like \"scp\"\) instead of an internal one
985 \(like \"ssh\"\), because setting `tramp-chunksize' to non-nil decreases
986 performance.
987
988 If your Emacs is buggy, the code stops and gives you an indication
989 about the value `tramp-chunksize' should be set. Maybe you could just
990 experiment a bit, e.g. changing the values of `init' and `step'
991 in the third line of the code.
992
993 Please raise a bug report via \"M-x tramp-bug\" if your system needs
994 this variable to be set as well."
995 :group 'tramp
996 :type '(choice (const nil) integer))
997
998 ;; Logging in to a remote host normally requires obtaining a pty. But
999 ;; Emacs on MacOS X has process-connection-type set to nil by default,
1000 ;; so on those systems Tramp doesn't obtain a pty. Here, we allow
1001 ;; for an override of the system default.
1002 (defcustom tramp-process-connection-type t
1003 "Overrides `process-connection-type' for connections from Tramp.
1004 Tramp binds process-connection-type to the value given here before
1005 opening a connection to a remote host."
1006 :group 'tramp
1007 :type '(choice (const nil) (const t) (const pty)))
1008
1009 (defcustom tramp-completion-reread-directory-timeout 10
1010 "Defines seconds since last remote command before rereading a directory.
1011 A remote directory might have changed its contents. In order to
1012 make it visible during file name completion in the minibuffer,
1013 Tramp flushes its cache and rereads the directory contents when
1014 more than `tramp-completion-reread-directory-timeout' seconds
1015 have been gone since last remote command execution. A value of `t'
1016 would require an immediate reread during filename completion, `nil'
1017 means to use always cached values for the directory contents."
1018 :group 'tramp
1019 :type '(choice (const nil) integer))
1020
1021 ;;; Internal Variables:
1022
1023 (defvar tramp-current-method nil
1024 "Connection method for this *tramp* buffer.")
1025
1026 (defvar tramp-current-user nil
1027 "Remote login name for this *tramp* buffer.")
1028
1029 (defvar tramp-current-host nil
1030 "Remote host for this *tramp* buffer.")
1031
1032 ;;;###autoload
1033 (defconst tramp-completion-file-name-handler-alist
1034 '((file-name-all-completions . tramp-completion-handle-file-name-all-completions)
1035 (file-name-completion . tramp-completion-handle-file-name-completion))
1036 "Alist of completion handler functions.
1037 Used for file names matching `tramp-file-name-regexp'. Operations
1038 not mentioned here will be handled by Tramp's file name handler
1039 functions, or the normal Emacs functions.")
1040
1041 ;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
1042 ;;;###tramp-autoload
1043 (defvar tramp-foreign-file-name-handler-alist nil
1044 "Alist of elements (FUNCTION . HANDLER) for foreign methods handled specially.
1045 If (FUNCTION FILENAME) returns non-nil, then all I/O on that file is done by
1046 calling HANDLER.")
1047
1048 ;;; Internal functions which must come first:
1049
1050 ;; Conversion functions between external representation and
1051 ;; internal data structure. Convenience functions for internal
1052 ;; data structure.
1053
1054 (defun tramp-get-method-parameter (method param)
1055 "Return the method parameter PARAM.
1056 If the `tramp-methods' entry does not exist, return nil."
1057 (let ((entry (assoc param (assoc method tramp-methods))))
1058 (when entry (cadr entry))))
1059
1060 (defun tramp-file-name-p (vec)
1061 "Check, whether VEC is a Tramp object."
1062 (and (vectorp vec) (= 5 (length vec))))
1063
1064 (defun tramp-file-name-method (vec)
1065 "Return method component of VEC."
1066 (and (tramp-file-name-p vec) (aref vec 0)))
1067
1068 (defun tramp-file-name-user (vec)
1069 "Return user component of VEC."
1070 (and (tramp-file-name-p vec) (aref vec 1)))
1071
1072 (defun tramp-file-name-host (vec)
1073 "Return host component of VEC."
1074 (and (tramp-file-name-p vec) (aref vec 2)))
1075
1076 (defun tramp-file-name-localname (vec)
1077 "Return localname component of VEC."
1078 (and (tramp-file-name-p vec) (aref vec 3)))
1079
1080 (defun tramp-file-name-hop (vec)
1081 "Return hop component of VEC."
1082 (and (tramp-file-name-p vec) (aref vec 4)))
1083
1084 ;; The user part of a Tramp file name vector can be of kind
1085 ;; "user%domain". Sometimes, we must extract these parts.
1086 (defun tramp-file-name-real-user (vec)
1087 "Return the user name of VEC without domain."
1088 (save-match-data
1089 (let ((user (tramp-file-name-user vec)))
1090 (if (and (stringp user)
1091 (string-match tramp-user-with-domain-regexp user))
1092 (match-string 1 user)
1093 user))))
1094
1095 (defun tramp-file-name-domain (vec)
1096 "Return the domain name of VEC."
1097 (save-match-data
1098 (let ((user (tramp-file-name-user vec)))
1099 (and (stringp user)
1100 (string-match tramp-user-with-domain-regexp user)
1101 (match-string 2 user)))))
1102
1103 ;; The host part of a Tramp file name vector can be of kind
1104 ;; "host#port". Sometimes, we must extract these parts.
1105 (defun tramp-file-name-real-host (vec)
1106 "Return the host name of VEC without port."
1107 (save-match-data
1108 (let ((host (tramp-file-name-host vec)))
1109 (if (and (stringp host)
1110 (string-match tramp-host-with-port-regexp host))
1111 (match-string 1 host)
1112 host))))
1113
1114 (defun tramp-file-name-port (vec)
1115 "Return the port number of VEC."
1116 (save-match-data
1117 (let ((method (tramp-file-name-method vec))
1118 (host (tramp-file-name-host vec)))
1119 (or (and (stringp host)
1120 (string-match tramp-host-with-port-regexp host)
1121 (string-to-number (match-string 2 host)))
1122 (tramp-get-method-parameter method 'tramp-default-port)))))
1123
1124 ;;;###tramp-autoload
1125 (defun tramp-tramp-file-p (name)
1126 "Return t if NAME is a string with Tramp file name syntax."
1127 (save-match-data
1128 (and (stringp name) (string-match tramp-file-name-regexp name))))
1129
1130 (defun tramp-find-method (method user host)
1131 "Return the right method string to use.
1132 This is METHOD, if non-nil. Otherwise, do a lookup in
1133 `tramp-default-method-alist'."
1134 (or method
1135 (let ((choices tramp-default-method-alist)
1136 lmethod item)
1137 (while choices
1138 (setq item (pop choices))
1139 (when (and (string-match (or (nth 0 item) "") (or host ""))
1140 (string-match (or (nth 1 item) "") (or user "")))
1141 (setq lmethod (nth 2 item))
1142 (setq choices nil)))
1143 lmethod)
1144 tramp-default-method))
1145
1146 (defun tramp-find-user (method user host)
1147 "Return the right user string to use.
1148 This is USER, if non-nil. Otherwise, do a lookup in
1149 `tramp-default-user-alist'."
1150 (or user
1151 (let ((choices tramp-default-user-alist)
1152 luser item)
1153 (while choices
1154 (setq item (pop choices))
1155 (when (and (string-match (or (nth 0 item) "") (or method ""))
1156 (string-match (or (nth 1 item) "") (or host "")))
1157 (setq luser (nth 2 item))
1158 (setq choices nil)))
1159 luser)
1160 tramp-default-user))
1161
1162 (defun tramp-find-host (method user host)
1163 "Return the right host string to use.
1164 This is HOST, if non-nil. Otherwise, it is `tramp-default-host'."
1165 (or (and (> (length host) 0) host)
1166 tramp-default-host))
1167
1168 (defun tramp-dissect-file-name (name &optional nodefault)
1169 "Return a `tramp-file-name' structure.
1170 The structure consists of remote method, remote user, remote host
1171 and localname (file name on remote host). If NODEFAULT is
1172 non-nil, the file name parts are not expanded to their default
1173 values."
1174 (save-match-data
1175 (let ((match (string-match (nth 0 tramp-file-name-structure) name)))
1176 (unless match (error "Not a Tramp file name: %s" name))
1177 (let ((method (match-string (nth 1 tramp-file-name-structure) name))
1178 (user (match-string (nth 2 tramp-file-name-structure) name))
1179 (host (match-string (nth 3 tramp-file-name-structure) name))
1180 (localname (match-string (nth 4 tramp-file-name-structure) name))
1181 (hop (match-string (nth 5 tramp-file-name-structure) name)))
1182 (when host
1183 (when (string-match tramp-prefix-ipv6-regexp host)
1184 (setq host (replace-match "" nil t host)))
1185 (when (string-match tramp-postfix-ipv6-regexp host)
1186 (setq host (replace-match "" nil t host))))
1187 (if nodefault
1188 (vector method user host localname hop)
1189 (vector
1190 (tramp-find-method method user host)
1191 (tramp-find-user method user host)
1192 (tramp-find-host method user host)
1193 localname hop))))))
1194
1195 (defun tramp-buffer-name (vec)
1196 "A name for the connection buffer VEC."
1197 ;; We must use `tramp-file-name-real-host', because for gateway
1198 ;; methods the default port will be expanded later on, which would
1199 ;; tamper the name.
1200 (let ((method (tramp-file-name-method vec))
1201 (user (tramp-file-name-user vec))
1202 (host (tramp-file-name-real-host vec)))
1203 (if (not (zerop (length user)))
1204 (format "*tramp/%s %s@%s*" method user host)
1205 (format "*tramp/%s %s*" method host))))
1206
1207 (defun tramp-make-tramp-file-name (method user host localname &optional hop)
1208 "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME.
1209 When not nil, an optional HOP is prepended."
1210 (concat tramp-prefix-format hop
1211 (when (not (zerop (length method)))
1212 (concat method tramp-postfix-method-format))
1213 (when (not (zerop (length user)))
1214 (concat user tramp-postfix-user-format))
1215 (when host
1216 (if (string-match tramp-ipv6-regexp host)
1217 (concat tramp-prefix-ipv6-format host tramp-postfix-ipv6-format)
1218 host))
1219 tramp-postfix-host-format
1220 (when localname localname)))
1221
1222 (defun tramp-completion-make-tramp-file-name (method user host localname)
1223 "Constructs a Tramp file name from METHOD, USER, HOST and LOCALNAME.
1224 It must not be a complete Tramp file name, but as long as there are
1225 necessary only. This function will be used in file name completion."
1226 (concat tramp-prefix-format
1227 (when (not (zerop (length method)))
1228 (concat method tramp-postfix-method-format))
1229 (when (not (zerop (length user)))
1230 (concat user tramp-postfix-user-format))
1231 (when (not (zerop (length host)))
1232 (concat
1233 (if (string-match tramp-ipv6-regexp host)
1234 (concat
1235 tramp-prefix-ipv6-format host tramp-postfix-ipv6-format)
1236 host)
1237 tramp-postfix-host-format))
1238 (when localname localname)))
1239
1240 (defun tramp-get-buffer (vec)
1241 "Get the connection buffer to be used for VEC."
1242 (or (get-buffer (tramp-buffer-name vec))
1243 (with-current-buffer (get-buffer-create (tramp-buffer-name vec))
1244 (setq buffer-undo-list t)
1245 (setq default-directory
1246 (tramp-make-tramp-file-name
1247 (tramp-file-name-method vec)
1248 (tramp-file-name-user vec)
1249 (tramp-file-name-host vec)
1250 "/"))
1251 (current-buffer))))
1252
1253 (defun tramp-get-connection-buffer (vec)
1254 "Get the connection buffer to be used for VEC.
1255 In case a second asynchronous communication has been started, it is different
1256 from `tramp-get-buffer'."
1257 (or (tramp-get-connection-property vec "process-buffer" nil)
1258 (tramp-get-buffer vec)))
1259
1260 (defun tramp-get-connection-name (vec)
1261 "Get the connection name to be used for VEC.
1262 In case a second asynchronous communication has been started, it is different
1263 from the default one."
1264 (or (tramp-get-connection-property vec "process-name" nil)
1265 (tramp-buffer-name vec)))
1266
1267 (defun tramp-get-connection-process (vec)
1268 "Get the connection process to be used for VEC.
1269 In case a second asynchronous communication has been started, it is different
1270 from the default one."
1271 (get-process (tramp-get-connection-name vec)))
1272
1273 (defun tramp-debug-buffer-name (vec)
1274 "A name for the debug buffer for VEC."
1275 ;; We must use `tramp-file-name-real-host', because for gateway
1276 ;; methods the default port will be expanded later on, which would
1277 ;; tamper the name.
1278 (let ((method (tramp-file-name-method vec))
1279 (user (tramp-file-name-user vec))
1280 (host (tramp-file-name-real-host vec)))
1281 (if (not (zerop (length user)))
1282 (format "*debug tramp/%s %s@%s*" method user host)
1283 (format "*debug tramp/%s %s*" method host))))
1284
1285 (defconst tramp-debug-outline-regexp
1286 "[0-9]+:[0-9]+:[0-9]+\\.[0-9]+ [a-z0-9-]+ (\\([0-9]+\\)) #"
1287 "Used for highlighting Tramp debug buffers in `outline-mode'.")
1288
1289 (defun tramp-debug-outline-level ()
1290 "Return the depth to which a statement is nested in the outline.
1291 Point must be at the beginning of a header line.
1292
1293 The outline level is equal to the verbosity of the Tramp message."
1294 (1+ (string-to-number (match-string 1))))
1295
1296 (defun tramp-get-debug-buffer (vec)
1297 "Get the debug buffer for VEC."
1298 (with-current-buffer
1299 (get-buffer-create (tramp-debug-buffer-name vec))
1300 (when (bobp)
1301 (setq buffer-undo-list t)
1302 ;; Activate `outline-mode'. This runs `text-mode-hook' and
1303 ;; `outline-mode-hook'. We must prevent that local processes
1304 ;; die. Yes: I've seen `flyspell-mode', which starts "ispell".
1305 ;; Furthermore, `outline-regexp' must have the correct value
1306 ;; already, because it is used by `font-lock-compile-keywords'.
1307 (let ((default-directory (tramp-compat-temporary-file-directory))
1308 (outline-regexp tramp-debug-outline-regexp))
1309 (outline-mode))
1310 (set (make-local-variable 'outline-regexp) tramp-debug-outline-regexp)
1311 (set (make-local-variable 'outline-level) 'tramp-debug-outline-level))
1312 (current-buffer)))
1313
1314 (defsubst tramp-debug-message (vec fmt-string &rest args)
1315 "Append message to debug buffer.
1316 Message is formatted with FMT-STRING as control string and the remaining
1317 ARGS to actually emit the message (if applicable)."
1318 (when (get-buffer (tramp-buffer-name vec))
1319 (with-current-buffer (tramp-get-debug-buffer vec)
1320 (goto-char (point-max))
1321 ;; Headline.
1322 (when (bobp)
1323 (insert
1324 (format
1325 ";; %sEmacs: %s Tramp: %s -*- mode: outline; -*-"
1326 (if (featurep 'sxemacs) "SX" (if (featurep 'xemacs) "X" "GNU "))
1327 emacs-version tramp-version)))
1328 (unless (bolp)
1329 (insert "\n"))
1330 ;; Timestamp.
1331 (let ((now (current-time)))
1332 (insert (format-time-string "%T." now))
1333 (insert (format "%06d " (nth 2 now))))
1334 ;; Calling Tramp function. We suppress compat and trace
1335 ;; functions from being displayed.
1336 (let ((btn 1) btf fn)
1337 (while (not fn)
1338 (setq btf (nth 1 (backtrace-frame btn)))
1339 (if (not btf)
1340 (setq fn "")
1341 (when (symbolp btf)
1342 (setq fn (symbol-name btf))
1343 (unless
1344 (and
1345 (string-match "^tramp" fn)
1346 (not
1347 (string-match
1348 (concat
1349 "^"
1350 (regexp-opt
1351 '("tramp-compat-funcall"
1352 "tramp-compat-with-temp-message"
1353 "tramp-debug-message"
1354 "tramp-error"
1355 "tramp-error-with-buffer"
1356 "tramp-message"
1357 "tramp-with-progress-reporter")
1358 t)
1359 "$")
1360 fn)))
1361 (setq fn nil)))
1362 (setq btn (1+ btn))))
1363 ;; The following code inserts filename and line number.
1364 ;; Should be inactive by default, because it is time
1365 ;; consuming.
1366 ; (let ((ffn (find-function-noselect (intern fn))))
1367 ; (insert
1368 ; (format
1369 ; "%s:%d: "
1370 ; (file-name-nondirectory (buffer-file-name (car ffn)))
1371 ; (with-current-buffer (car ffn)
1372 ; (1+ (count-lines (point-min) (cdr ffn)))))))
1373 (insert (format "%s " fn)))
1374 ;; The message.
1375 (insert (apply 'format fmt-string args)))))
1376
1377 (defvar tramp-message-show-message t
1378 "Show Tramp message in the minibuffer.
1379 This variable is used to disable messages from `tramp-error'.
1380 The messages are visible anyway, because an error is raised.")
1381
1382 (defvar tramp-message-show-progress-reporter-message t
1383 "Show Tramp progress reporter message in the minibuffer.
1384 This variable is used to disable recursive progress reporter messages.")
1385
1386 (defsubst tramp-message (vec-or-proc level fmt-string &rest args)
1387 "Emit a message depending on verbosity level.
1388 VEC-OR-PROC identifies the Tramp buffer to use. It can be either a
1389 vector or a process. LEVEL says to be quiet if `tramp-verbose' is
1390 less than LEVEL. The message is emitted only if `tramp-verbose' is
1391 greater than or equal to LEVEL.
1392
1393 The message is also logged into the debug buffer when `tramp-verbose'
1394 is greater than or equal 4.
1395
1396 Calls functions `message' and `tramp-debug-message' with FMT-STRING as
1397 control string and the remaining ARGS to actually emit the message (if
1398 applicable)."
1399 (ignore-errors
1400 (when (<= level tramp-verbose)
1401 ;; Match data must be preserved!
1402 (save-match-data
1403 ;; Display only when there is a minimum level.
1404 (when (and tramp-message-show-message (<= level 3))
1405 (apply 'message
1406 (concat
1407 (cond
1408 ((= level 0) "")
1409 ((= level 1) "")
1410 ((= level 2) "Warning: ")
1411 (t "Tramp: "))
1412 fmt-string)
1413 args))
1414 ;; Log only when there is a minimum level.
1415 (when (>= tramp-verbose 4)
1416 (when (and vec-or-proc
1417 (processp vec-or-proc)
1418 (buffer-name (process-buffer vec-or-proc)))
1419 (with-current-buffer (process-buffer vec-or-proc)
1420 ;; Translate proc to vec.
1421 (setq vec-or-proc (tramp-dissect-file-name default-directory))))
1422 (when (and vec-or-proc (vectorp vec-or-proc))
1423 (apply 'tramp-debug-message
1424 vec-or-proc
1425 (concat (format "(%d) # " level) fmt-string)
1426 args)))))))
1427
1428 (defsubst tramp-error (vec-or-proc signal fmt-string &rest args)
1429 "Emit an error.
1430 VEC-OR-PROC identifies the connection to use, SIGNAL is the
1431 signal identifier to be raised, remaining args passed to
1432 `tramp-message'. Finally, signal SIGNAL is raised."
1433 (let (tramp-message-show-message)
1434 (tramp-message
1435 vec-or-proc 1 "%s"
1436 (error-message-string
1437 (list signal
1438 (get signal 'error-message)
1439 (apply 'format fmt-string args))))
1440 (signal signal (list (apply 'format fmt-string args)))))
1441
1442 (defsubst tramp-error-with-buffer
1443 (buffer vec-or-proc signal fmt-string &rest args)
1444 "Emit an error, and show BUFFER.
1445 If BUFFER is nil, show the connection buffer. Wait for 30\", or until
1446 an input event arrives. The other arguments are passed to `tramp-error'."
1447 (save-window-excursion
1448 (unwind-protect
1449 (apply 'tramp-error vec-or-proc signal fmt-string args)
1450 (when (and vec-or-proc
1451 tramp-message-show-message
1452 (not (zerop tramp-verbose))
1453 (not (tramp-completion-mode-p)))
1454 (let ((enable-recursive-minibuffers t))
1455 (pop-to-buffer
1456 (or (and (bufferp buffer) buffer)
1457 (and (processp vec-or-proc) (process-buffer vec-or-proc))
1458 (tramp-get-connection-buffer vec-or-proc)))
1459 (sit-for 30))))))
1460
1461 (defmacro with-parsed-tramp-file-name (filename var &rest body)
1462 "Parse a Tramp filename and make components available in the body.
1463
1464 First arg FILENAME is evaluated and dissected into its components.
1465 Second arg VAR is a symbol. It is used as a variable name to hold
1466 the filename structure. It is also used as a prefix for the variables
1467 holding the components. For example, if VAR is the symbol `foo', then
1468 `foo' will be bound to the whole structure, `foo-method' will be bound to
1469 the method component, and so on for `foo-user', `foo-host', `foo-localname',
1470 `foo-hop'.
1471
1472 Remaining args are Lisp expressions to be evaluated (inside an implicit
1473 `progn').
1474
1475 If VAR is nil, then we bind `v' to the structure and `method', `user',
1476 `host', `localname', `hop' to the components."
1477 `(let* ((,(or var 'v) (tramp-dissect-file-name ,filename))
1478 (,(if var (intern (concat (symbol-name var) "-method")) 'method)
1479 (tramp-file-name-method ,(or var 'v)))
1480 (,(if var (intern (concat (symbol-name var) "-user")) 'user)
1481 (tramp-file-name-user ,(or var 'v)))
1482 (,(if var (intern (concat (symbol-name var) "-host")) 'host)
1483 (tramp-file-name-host ,(or var 'v)))
1484 (,(if var (intern (concat (symbol-name var) "-localname")) 'localname)
1485 (tramp-file-name-localname ,(or var 'v)))
1486 (,(if var (intern (concat (symbol-name var) "-hop")) 'hop)
1487 (tramp-file-name-hop ,(or var 'v))))
1488 ,@body))
1489
1490 (put 'with-parsed-tramp-file-name 'lisp-indent-function 2)
1491 (put 'with-parsed-tramp-file-name 'edebug-form-spec '(form symbolp body))
1492 (tramp-compat-font-lock-add-keywords
1493 'emacs-lisp-mode '("\\<with-parsed-tramp-file-name\\>"))
1494
1495 (defun tramp-progress-reporter-update (reporter &optional value)
1496 (let* ((parameters (cdr reporter))
1497 (message (aref parameters 3)))
1498 (when (string-match message (or (current-message) ""))
1499 (tramp-compat-funcall 'progress-reporter-update reporter value))))
1500
1501 (defmacro tramp-with-progress-reporter (vec level message &rest body)
1502 "Executes BODY, spinning a progress reporter with MESSAGE.
1503 If LEVEL does not fit for visible messages, or if this is a
1504 nested call of the macro, there are only traces without a visible
1505 progress reporter."
1506 (declare (indent 3) (debug t))
1507 `(let (pr tm)
1508 (tramp-message ,vec ,level "%s..." ,message)
1509 ;; We start a pulsing progress reporter after 3 seconds. Feature
1510 ;; introduced in Emacs 24.1.
1511 (when (and tramp-message-show-progress-reporter-message
1512 tramp-message-show-message
1513 ;; Display only when there is a minimum level.
1514 (<= ,level (min tramp-verbose 3)))
1515 (ignore-errors
1516 (setq pr (tramp-compat-funcall 'make-progress-reporter ,message)
1517 tm (when pr
1518 (run-at-time 3 0.1 'tramp-progress-reporter-update pr)))))
1519 (unwind-protect
1520 ;; Execute the body. Suppress concurrent progress reporter
1521 ;; messages.
1522 (let ((tramp-message-show-progress-reporter-message
1523 (and tramp-message-show-progress-reporter-message (not tm))))
1524 ,@body)
1525 ;; Stop progress reporter.
1526 (if tm (tramp-compat-funcall 'cancel-timer tm))
1527 (tramp-message ,vec ,level "%s...done" ,message))))
1528
1529 (tramp-compat-font-lock-add-keywords
1530 'emacs-lisp-mode '("\\<tramp-with-progress-reporter\\>"))
1531
1532 (defalias 'tramp-drop-volume-letter
1533 (if (memq system-type '(cygwin windows-nt))
1534 (lambda (name)
1535 "Cut off unnecessary drive letter from file NAME.
1536 The functions `tramp-*-handle-expand-file-name' call `expand-file-name'
1537 locally on a remote file name. When the local system is a W32 system
1538 but the remote system is Unix, this introduces a superfluous drive
1539 letter into the file name. This function removes it."
1540 (save-match-data
1541 (if (string-match "\\`[a-zA-Z]:/" name)
1542 (replace-match "/" nil t name)
1543 name)))
1544
1545 'identity))
1546
1547 (if (featurep 'xemacs)
1548 (defalias 'tramp-drop-volume-letter 'identity))
1549
1550 (defun tramp-cleanup (vec)
1551 "Cleanup connection VEC, but keep the debug buffer."
1552 (with-current-buffer (tramp-get-debug-buffer vec)
1553 ;; Keep the debug buffer.
1554 (rename-buffer
1555 (generate-new-buffer-name tramp-temp-buffer-name) 'unique)
1556 (tramp-cleanup-connection vec)
1557 (if (= (point-min) (point-max))
1558 (kill-buffer nil)
1559 (rename-buffer (tramp-debug-buffer-name vec) 'unique))
1560 ;; We call `tramp-get-buffer' in order to keep the debug buffer.
1561 (tramp-get-buffer vec)))
1562
1563 ;;; Config Manipulation Functions:
1564
1565 ;;;###tramp-autoload
1566 (defun tramp-set-completion-function (method function-list)
1567 "Sets the list of completion functions for METHOD.
1568 FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
1569 The FUNCTION is intended to parse FILE according its syntax.
1570 It might be a predefined FUNCTION, or a user defined FUNCTION.
1571 For the list of predefined FUNCTIONs see `tramp-completion-function-alist'.
1572
1573 Example:
1574
1575 (tramp-set-completion-function
1576 \"ssh\"
1577 '((tramp-parse-sconfig \"/etc/ssh_config\")
1578 (tramp-parse-sconfig \"~/.ssh/config\")))"
1579
1580 (let ((r function-list)
1581 (v function-list))
1582 (setq tramp-completion-function-alist
1583 (delete (assoc method tramp-completion-function-alist)
1584 tramp-completion-function-alist))
1585
1586 (while v
1587 ;; Remove double entries.
1588 (when (member (car v) (cdr v))
1589 (setcdr v (delete (car v) (cdr v))))
1590 ;; Check for function and file or registry key.
1591 (unless (and (functionp (nth 0 (car v)))
1592 (if (string-match "^HKEY_CURRENT_USER" (nth 1 (car v)))
1593 ;; Windows registry.
1594 (and (memq system-type '(cygwin windows-nt))
1595 (zerop
1596 (tramp-compat-call-process
1597 "reg" nil nil nil "query" (nth 1 (car v)))))
1598 ;; Configuration file.
1599 (file-exists-p (nth 1 (car v)))))
1600 (setq r (delete (car v) r)))
1601 (setq v (cdr v)))
1602
1603 (when r
1604 (add-to-list 'tramp-completion-function-alist
1605 (cons method r)))))
1606
1607 (defun tramp-get-completion-function (method)
1608 "Returns a list of completion functions for METHOD.
1609 For definition of that list see `tramp-set-completion-function'."
1610 (cons
1611 ;; Hosts visited once shall be remembered.
1612 `(tramp-parse-connection-properties ,method)
1613 ;; The method related defaults.
1614 (cdr (assoc method tramp-completion-function-alist))))
1615
1616
1617 ;;; Fontification of `read-file-name':
1618
1619 ;; rfn-eshadow.el is part of Emacs 22. It is autoloaded.
1620 (defvar tramp-rfn-eshadow-overlay)
1621 (make-variable-buffer-local 'tramp-rfn-eshadow-overlay)
1622
1623 (defun tramp-rfn-eshadow-setup-minibuffer ()
1624 "Set up a minibuffer for `file-name-shadow-mode'.
1625 Adds another overlay hiding filename parts according to Tramp's
1626 special handling of `substitute-in-file-name'."
1627 (when (symbol-value 'minibuffer-completing-file-name)
1628 (setq tramp-rfn-eshadow-overlay
1629 (tramp-compat-funcall
1630 'make-overlay
1631 (tramp-compat-funcall 'minibuffer-prompt-end)
1632 (tramp-compat-funcall 'minibuffer-prompt-end)))
1633 ;; Copy rfn-eshadow-overlay properties.
1634 (let ((props (tramp-compat-funcall
1635 'overlay-properties (symbol-value 'rfn-eshadow-overlay))))
1636 (while props
1637 ;; The `field' property prevents correct minibuffer
1638 ;; completion; we exclude it.
1639 (if (not (eq (car props) 'field))
1640 (tramp-compat-funcall
1641 'overlay-put tramp-rfn-eshadow-overlay (pop props) (pop props))
1642 (pop props) (pop props))))))
1643
1644 (when (boundp 'rfn-eshadow-setup-minibuffer-hook)
1645 (add-hook 'rfn-eshadow-setup-minibuffer-hook
1646 'tramp-rfn-eshadow-setup-minibuffer)
1647 (add-hook 'tramp-unload-hook
1648 (lambda ()
1649 (remove-hook 'rfn-eshadow-setup-minibuffer-hook
1650 'tramp-rfn-eshadow-setup-minibuffer))))
1651
1652 (defconst tramp-rfn-eshadow-update-overlay-regexp
1653 (format "[^%s/~]*\\(/\\|~\\)" tramp-postfix-host-format))
1654
1655 (defun tramp-rfn-eshadow-update-overlay ()
1656 "Update `rfn-eshadow-overlay' to cover shadowed part of minibuffer input.
1657 This is intended to be used as a minibuffer `post-command-hook' for
1658 `file-name-shadow-mode'; the minibuffer should have already
1659 been set up by `rfn-eshadow-setup-minibuffer'."
1660 ;; In remote files name, there is a shadowing just for the local part.
1661 (ignore-errors
1662 (let ((end (or (tramp-compat-funcall
1663 'overlay-end (symbol-value 'rfn-eshadow-overlay))
1664 (tramp-compat-funcall 'minibuffer-prompt-end)))
1665 ;; We do not want to send any remote command.
1666 (non-essential t))
1667 (when
1668 (file-remote-p
1669 (tramp-compat-funcall
1670 'buffer-substring-no-properties end (point-max)))
1671 (save-excursion
1672 (save-restriction
1673 (narrow-to-region
1674 (1+ (or (string-match
1675 tramp-rfn-eshadow-update-overlay-regexp
1676 (buffer-string) end)
1677 end))
1678 (point-max))
1679 (let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay)
1680 (rfn-eshadow-update-overlay-hook nil)
1681 file-name-handler-alist)
1682 (tramp-compat-funcall
1683 'move-overlay rfn-eshadow-overlay (point-max) (point-max))
1684 (tramp-compat-funcall 'rfn-eshadow-update-overlay))))))))
1685
1686 (when (boundp 'rfn-eshadow-update-overlay-hook)
1687 (add-hook 'rfn-eshadow-update-overlay-hook
1688 'tramp-rfn-eshadow-update-overlay)
1689 (add-hook 'tramp-unload-hook
1690 (lambda ()
1691 (remove-hook 'rfn-eshadow-update-overlay-hook
1692 'tramp-rfn-eshadow-update-overlay))))
1693
1694 ;; Inodes don't exist for some file systems. Therefore we must
1695 ;; generate virtual ones. Used in `find-buffer-visiting'. The method
1696 ;; applied might be not so efficient (Ange-FTP uses hashes). But
1697 ;; performance isn't the major issue given that file transfer will
1698 ;; take time.
1699 (defvar tramp-inodes 0
1700 "Keeps virtual inodes numbers.")
1701
1702 ;; Devices must distinguish physical file systems. The device numbers
1703 ;; provided by "lstat" aren't unique, because we operate on different hosts.
1704 ;; So we use virtual device numbers, generated by Tramp. Both Ange-FTP and
1705 ;; EFS use device number "-1". In order to be different, we use device number
1706 ;; (-1 . x), whereby "x" is unique for a given (method user host).
1707 (defvar tramp-devices 0
1708 "Keeps virtual device numbers.")
1709
1710 (defun tramp-default-file-modes (filename)
1711 "Return file modes of FILENAME as integer.
1712 If the file modes of FILENAME cannot be determined, return the
1713 value of `default-file-modes', without execute permissions."
1714 (or (file-modes filename)
1715 (logand (default-file-modes) (tramp-compat-octal-to-decimal "0666"))))
1716
1717 (defun tramp-replace-environment-variables (filename)
1718 "Replace environment variables in FILENAME.
1719 Return the string with the replaced variables."
1720 (save-match-data
1721 (let ((idx (string-match "$\\(\\w+\\)" filename)))
1722 ;; `$' is coded as `$$'.
1723 (when (and idx
1724 (or (zerop idx) (not (eq ?$ (aref filename (1- idx)))))
1725 (getenv (match-string 1 filename)))
1726 (setq filename
1727 (replace-match
1728 (substitute-in-file-name (match-string 0 filename))
1729 t nil filename)))
1730 filename)))
1731
1732 ;; In XEmacs, electricity is implemented via a key map for ?/ and ?~,
1733 ;; which calls corresponding functions (see minibuf.el).
1734 (when (fboundp 'minibuffer-electric-separator)
1735 (mapc
1736 (lambda (x)
1737 (eval
1738 `(defadvice ,x
1739 (around ,(intern (format "tramp-advice-%s" x)) activate)
1740 "Invoke `substitute-in-file-name' for Tramp files."
1741 (if (and (symbol-value 'minibuffer-electric-file-name-behavior)
1742 (tramp-tramp-file-p (buffer-substring)))
1743 ;; We don't need to handle `last-input-event', because
1744 ;; due to the key map we know it must be ?/ or ?~.
1745 (let ((s (concat (buffer-substring (point-min) (point))
1746 (string last-command-char))))
1747 (delete-region (point-min) (point))
1748 (insert (substitute-in-file-name s))
1749 (setq ad-return-value last-command-char))
1750 ad-do-it)))
1751 (eval
1752 `(add-hook
1753 'tramp-unload-hook
1754 (lambda ()
1755 (ad-remove-advice ',x 'around ',(intern (format "tramp-advice-%s" x)))
1756 (ad-activate ',x)))))
1757
1758 '(minibuffer-electric-separator
1759 minibuffer-electric-tilde)))
1760
1761 (defun tramp-find-file-name-coding-system-alist (filename tmpname)
1762 "Like `find-operation-coding-system' for Tramp filenames.
1763 Tramp's `insert-file-contents' and `write-region' work over
1764 temporary file names. If `file-coding-system-alist' contains an
1765 expression, which matches more than the file name suffix, the
1766 coding system might not be determined. This function repairs it."
1767 (let (result)
1768 (dolist (elt file-coding-system-alist result)
1769 (when (and (consp elt) (string-match (car elt) filename))
1770 ;; We found a matching entry in `file-coding-system-alist'.
1771 ;; So we add a similar entry, but with the temporary file name
1772 ;; as regexp.
1773 (add-to-list
1774 'result (cons (regexp-quote tmpname) (cdr elt)) 'append)))))
1775
1776 ;;;###autoload
1777 (progn (defun tramp-run-real-handler (operation args)
1778 "Invoke normal file name handler for OPERATION.
1779 First arg specifies the OPERATION, second arg is a list of arguments to
1780 pass to the OPERATION."
1781 (let* ((inhibit-file-name-handlers
1782 `(tramp-file-name-handler
1783 tramp-vc-file-name-handler
1784 tramp-completion-file-name-handler
1785 cygwin-mount-name-hook-function
1786 cygwin-mount-map-drive-hook-function
1787 .
1788 ,(and (eq inhibit-file-name-operation operation)
1789 inhibit-file-name-handlers)))
1790 (inhibit-file-name-operation operation))
1791 (apply operation args))))
1792
1793 ;;;###autoload
1794 (progn (defun tramp-completion-run-real-handler (operation args)
1795 "Invoke `tramp-file-name-handler' for OPERATION.
1796 First arg specifies the OPERATION, second arg is a list of arguments to
1797 pass to the OPERATION."
1798 (let* ((inhibit-file-name-handlers
1799 `(tramp-completion-file-name-handler
1800 cygwin-mount-name-hook-function
1801 cygwin-mount-map-drive-hook-function
1802 .
1803 ,(and (eq inhibit-file-name-operation operation)
1804 inhibit-file-name-handlers)))
1805 (inhibit-file-name-operation operation))
1806 (apply operation args))))
1807
1808 ;; We handle here all file primitives. Most of them have the file
1809 ;; name as first parameter; nevertheless we check for them explicitly
1810 ;; in order to be signaled if a new primitive appears. This
1811 ;; scenario is needed because there isn't a way to decide by
1812 ;; syntactical means whether a foreign method must be called. It would
1813 ;; ease the life if `file-name-handler-alist' would support a decision
1814 ;; function as well but regexp only.
1815 (defun tramp-file-name-for-operation (operation &rest args)
1816 "Return file name related to OPERATION file primitive.
1817 ARGS are the arguments OPERATION has been called with."
1818 (cond
1819 ;; FILE resp DIRECTORY.
1820 ((member operation
1821 (list 'access-file 'byte-compiler-base-file-name 'delete-directory
1822 'delete-file 'diff-latest-backup-file 'directory-file-name
1823 'directory-files 'directory-files-and-attributes
1824 'dired-compress-file 'dired-uncache
1825 'file-accessible-directory-p 'file-attributes
1826 'file-directory-p 'file-executable-p 'file-exists-p
1827 'file-local-copy 'file-remote-p 'file-modes
1828 'file-name-as-directory 'file-name-directory
1829 'file-name-nondirectory 'file-name-sans-versions
1830 'file-ownership-preserved-p 'file-readable-p
1831 'file-regular-p 'file-symlink-p 'file-truename
1832 'file-writable-p 'find-backup-file-name 'find-file-noselect
1833 'get-file-buffer 'insert-directory 'insert-file-contents
1834 'load 'make-directory 'make-directory-internal
1835 'set-file-modes 'substitute-in-file-name
1836 'unhandled-file-name-directory 'vc-registered
1837 ;; Emacs 22+ only.
1838 'set-file-times
1839 ;; Emacs 24+ only.
1840 'file-selinux-context 'set-file-selinux-context
1841 ;; XEmacs only.
1842 'abbreviate-file-name 'create-file-buffer
1843 'dired-file-modtime 'dired-make-compressed-filename
1844 'dired-recursive-delete-directory 'dired-set-file-modtime
1845 'dired-shell-unhandle-file-name 'dired-uucode-file
1846 'insert-file-contents-literally 'make-temp-name 'recover-file
1847 'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail))
1848 (if (file-name-absolute-p (nth 0 args))
1849 (nth 0 args)
1850 (expand-file-name (nth 0 args))))
1851 ;; FILE DIRECTORY resp FILE1 FILE2.
1852 ((member operation
1853 (list 'add-name-to-file 'copy-file 'expand-file-name
1854 'file-name-all-completions 'file-name-completion
1855 'file-newer-than-file-p 'make-symbolic-link 'rename-file
1856 ;; Emacs 23+ only.
1857 'copy-directory
1858 ;; Emacs 24+ only.
1859 'file-in-directory-p 'file-equal-p
1860 ;; XEmacs only.
1861 'dired-make-relative-symlink
1862 'vm-imap-move-mail 'vm-pop-move-mail 'vm-spool-move-mail))
1863 (save-match-data
1864 (cond
1865 ((string-match tramp-file-name-regexp (nth 0 args)) (nth 0 args))
1866 ((string-match tramp-file-name-regexp (nth 1 args)) (nth 1 args))
1867 (t (buffer-file-name (current-buffer))))))
1868 ;; START END FILE.
1869 ((eq operation 'write-region)
1870 (nth 2 args))
1871 ;; BUFFER.
1872 ((member operation
1873 (list 'set-visited-file-modtime 'verify-visited-file-modtime
1874 ;; Emacs 22+ only.
1875 'make-auto-save-file-name
1876 ;; XEmacs only.
1877 'backup-buffer))
1878 (buffer-file-name
1879 (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer))))
1880 ;; COMMAND.
1881 ((member operation
1882 (list ;; not in Emacs 23+.
1883 'dired-call-process
1884 ;; Emacs only.
1885 'shell-command
1886 ;; Emacs 22+ only.
1887 'process-file
1888 ;; Emacs 23+ only.
1889 'start-file-process
1890 ;; XEmacs only.
1891 'dired-print-file 'dired-shell-call-process
1892 ;; nowhere yet.
1893 'executable-find 'start-process
1894 'call-process 'call-process-region))
1895 default-directory)
1896 ;; Unknown file primitive.
1897 (t (error "unknown file I/O primitive: %s" operation))))
1898
1899 (defun tramp-find-foreign-file-name-handler (filename)
1900 "Return foreign file name handler if exists."
1901 (when (tramp-tramp-file-p filename)
1902 (let ((v (tramp-dissect-file-name filename t))
1903 (handler tramp-foreign-file-name-handler-alist)
1904 elt res)
1905 ;; When we are not fully sure that filename completion is safe,
1906 ;; we should not return a handler.
1907 (when (or (tramp-file-name-method v) (tramp-file-name-user v)
1908 (and (tramp-file-name-host v)
1909 (not (member (tramp-file-name-host v)
1910 (mapcar 'car tramp-methods))))
1911 (not (tramp-completion-mode-p)))
1912 (while handler
1913 (setq elt (car handler)
1914 handler (cdr handler))
1915 (when (funcall (car elt) filename)
1916 (setq handler nil
1917 res (cdr elt))))
1918 res))))
1919
1920 ;; Main function.
1921 ;;;###autoload
1922 (defun tramp-file-name-handler (operation &rest args)
1923 "Invoke Tramp file name handler.
1924 Falls back to normal file name handler if no Tramp file name handler exists."
1925 (if tramp-mode
1926 (save-match-data
1927 (let* ((filename
1928 (tramp-replace-environment-variables
1929 (apply 'tramp-file-name-for-operation operation args)))
1930 (completion (tramp-completion-mode-p))
1931 (foreign (tramp-find-foreign-file-name-handler filename)))
1932 (with-parsed-tramp-file-name filename nil
1933 ;; Call the backend function.
1934 (if foreign
1935 (tramp-compat-condition-case-unless-debug err
1936 (let ((sf (symbol-function foreign))
1937 result)
1938 ;; Some packages set the default directory to a
1939 ;; remote path, before respective Tramp packages
1940 ;; are already loaded. This results in
1941 ;; recursive loading. Therefore, we load the
1942 ;; Tramp packages locally.
1943 (when (and (listp sf) (eq (car sf) 'autoload))
1944 (let ((default-directory
1945 (tramp-compat-temporary-file-directory)))
1946 (load (cadr sf) 'noerror 'nomessage)))
1947 ;; If `non-essential' is non-nil, Tramp shall
1948 ;; not open a new connection.
1949 ;; If Tramp detects that it shouldn't continue
1950 ;; to work, it throws the `suppress' event.
1951 ;; This could happen for example, when Tramp
1952 ;; tries to open the same connection twice in a
1953 ;; short time frame.
1954 ;; In both cases, we try the default handler then.
1955 (setq result
1956 (catch 'non-essential
1957 (catch 'suppress
1958 (apply foreign operation args))))
1959 (cond
1960 ((eq result 'non-essential)
1961 (tramp-message
1962 v 5 "Non-essential received in operation %s"
1963 (append (list operation) args))
1964 (tramp-run-real-handler operation args))
1965 ((eq result 'suppress)
1966 (let (tramp-message-show-message)
1967 (tramp-message
1968 v 1 "Suppress received in operation %s"
1969 (append (list operation) args))
1970 (tramp-cleanup v)
1971 (tramp-run-real-handler operation args)))
1972 (t result)))
1973
1974 ;; Trace that somebody has interrupted the operation.
1975 ((debug quit)
1976 (let (tramp-message-show-message)
1977 (tramp-message
1978 v 1 "Interrupt received in operation %s"
1979 (append (list operation) args)))
1980 ;; Propagate the quit signal.
1981 (signal (car err) (cdr err)))
1982
1983 ;; When we are in completion mode, some failed
1984 ;; operations shall return at least a default value
1985 ;; in order to give the user a chance to correct the
1986 ;; file name in the minibuffer.
1987 ;; In order to get a full backtrace, one could apply
1988 ;; (setq debug-on-error t debug-on-signal t)
1989 (error
1990 (cond
1991 ((and completion (zerop (length localname))
1992 (memq operation '(file-exists-p file-directory-p)))
1993 t)
1994 ((and completion (zerop (length localname))
1995 (memq operation
1996 '(expand-file-name file-name-as-directory)))
1997 filename)
1998 ;; Propagate the error.
1999 (t (signal (car err) (cdr err))))))
2000
2001 ;; Nothing to do for us.
2002 (tramp-run-real-handler operation args)))))
2003
2004 ;; When `tramp-mode' is not enabled, we don't do anything.
2005 (tramp-run-real-handler operation args)))
2006
2007 ;; In Emacs, there is some concurrency due to timers. If a timer
2008 ;; interrupts Tramp and wishes to use the same connection buffer as
2009 ;; the "main" Emacs, then garbage might occur in the connection
2010 ;; buffer. Therefore, we need to make sure that a timer does not use
2011 ;; the same connection buffer as the "main" Emacs. We implement a
2012 ;; cheap global lock, instead of locking each connection buffer
2013 ;; separately. The global lock is based on two variables,
2014 ;; `tramp-locked' and `tramp-locker'. `tramp-locked' is set to true
2015 ;; (with setq) to indicate a lock. But Tramp also calls itself during
2016 ;; processing of a single file operation, so we need to allow
2017 ;; recursive calls. That's where the `tramp-locker' variable comes in
2018 ;; -- it is let-bound to t during the execution of the current
2019 ;; handler. So if `tramp-locked' is t and `tramp-locker' is also t,
2020 ;; then we should just proceed because we have been called
2021 ;; recursively. But if `tramp-locker' is nil, then we are a timer
2022 ;; interrupting the "main" Emacs, and then we signal an error.
2023
2024 (defvar tramp-locked nil
2025 "If non-nil, then Tramp is currently busy.
2026 Together with `tramp-locker', this implements a locking mechanism
2027 preventing reentrant calls of Tramp.")
2028
2029 (defvar tramp-locker nil
2030 "If non-nil, then a caller has locked Tramp.
2031 Together with `tramp-locked', this implements a locking mechanism
2032 preventing reentrant calls of Tramp.")
2033
2034 ;;;###autoload
2035 (progn (defun tramp-completion-file-name-handler (operation &rest args)
2036 "Invoke Tramp file name completion handler.
2037 Falls back to normal file name handler if no Tramp file name handler exists."
2038 ;; We bind `directory-sep-char' here for XEmacs on Windows, which
2039 ;; would otherwise use backslash.
2040 (let ((directory-sep-char ?/)
2041 (fn (assoc operation tramp-completion-file-name-handler-alist)))
2042 (if (and
2043 ;; When `tramp-mode' is not enabled, we don't do anything.
2044 fn tramp-mode
2045 ;; For other syntaxes than `sep', the regexp matches many common
2046 ;; situations where the user doesn't actually want to use Tramp.
2047 ;; So to avoid autoloading Tramp after typing just "/s", we
2048 ;; disable this part of the completion, unless the user implicitly
2049 ;; indicated his interest in using a fancier completion system.
2050 (or (eq tramp-syntax 'sep)
2051 (featurep 'tramp) ;; If it's loaded, we may as well use it.
2052 ;; `partial-completion-mode' does not exist in XEmacs.
2053 ;; It is obsoleted with Emacs 24.1.
2054 (and (boundp 'partial-completion-mode)
2055 (symbol-value 'partial-completion-mode))
2056 ;; FIXME: These may have been loaded even if the user never
2057 ;; intended to use them.
2058 (featurep 'ido)
2059 (featurep 'icicles)))
2060 (save-match-data (apply (cdr fn) args))
2061 (tramp-completion-run-real-handler operation args)))))
2062
2063 ;;;###autoload
2064 (progn (defun tramp-register-file-name-handlers ()
2065 "Add Tramp file name handlers to `file-name-handler-alist'."
2066 ;; Remove autoloaded handlers from file name handler alist. Useful,
2067 ;; if `tramp-syntax' has been changed.
2068 (let ((a1 (rassq 'tramp-file-name-handler file-name-handler-alist)))
2069 (setq file-name-handler-alist (delq a1 file-name-handler-alist)))
2070 (let ((a1 (rassq
2071 'tramp-completion-file-name-handler file-name-handler-alist)))
2072 (setq file-name-handler-alist (delq a1 file-name-handler-alist)))
2073 ;; Add the handlers.
2074 (add-to-list 'file-name-handler-alist
2075 (cons tramp-file-name-regexp 'tramp-file-name-handler))
2076 (put 'tramp-file-name-handler 'safe-magic t)
2077 (add-to-list 'file-name-handler-alist
2078 (cons tramp-completion-file-name-regexp
2079 'tramp-completion-file-name-handler))
2080 (put 'tramp-completion-file-name-handler 'safe-magic t)
2081 ;; If jka-compr or epa-file are already loaded, move them to the
2082 ;; front of `file-name-handler-alist'.
2083 (dolist (fnh '(epa-file-handler jka-compr-handler))
2084 (let ((entry (rassoc fnh file-name-handler-alist)))
2085 (when entry
2086 (setq file-name-handler-alist
2087 (cons entry (delete entry file-name-handler-alist))))))))
2088
2089 ;; `tramp-file-name-handler' must be registered before evaluation of
2090 ;; site-start and init files, because there might exist remote files
2091 ;; already, f.e. files kept via recentf-mode.
2092 ;;;###autoload
2093 (tramp-register-file-name-handlers)
2094
2095 (defun tramp-exists-file-name-handler (operation &rest args)
2096 "Check, whether OPERATION runs a file name handler."
2097 ;; The file name handler is determined on base of either an
2098 ;; argument, `buffer-file-name', or `default-directory'.
2099 (ignore-errors
2100 (let* ((buffer-file-name "/")
2101 (default-directory "/")
2102 (fnha file-name-handler-alist)
2103 (check-file-name-operation operation)
2104 (file-name-handler-alist
2105 (list
2106 (cons "/"
2107 (lambda (operation &rest args)
2108 "Returns OPERATION if it is the one to be checked."
2109 (if (equal check-file-name-operation operation)
2110 operation
2111 (let ((file-name-handler-alist fnha))
2112 (apply operation args))))))))
2113 (equal (apply operation args) operation))))
2114
2115 ;;;###autoload
2116 (defun tramp-unload-file-name-handlers ()
2117 (setq file-name-handler-alist
2118 (delete (rassoc 'tramp-file-name-handler
2119 file-name-handler-alist)
2120 (delete (rassoc 'tramp-completion-file-name-handler
2121 file-name-handler-alist)
2122 file-name-handler-alist))))
2123
2124 (add-hook 'tramp-unload-hook 'tramp-unload-file-name-handlers)
2125
2126 ;;; File name handler functions for completion mode:
2127
2128 (defvar tramp-completion-mode nil
2129 "If non-nil, external packages signal that they are in file name completion.
2130
2131 This is necessary, because Tramp uses a heuristic depending on last
2132 input event. This fails when external packages use other characters
2133 but <TAB>, <SPACE> or ?\\? for file name completion. This variable
2134 should never be set globally, the intention is to let-bind it.")
2135
2136 ;; Necessary because `tramp-file-name-regexp-unified' and
2137 ;; `tramp-completion-file-name-regexp-unified' aren't different. If
2138 ;; nil, `tramp-completion-run-real-handler' is called (i.e. forwarding
2139 ;; to `tramp-file-name-handler'). Otherwise, it takes
2140 ;; `tramp-run-real-handler'. Using `last-input-event' is a little bit
2141 ;; risky, because completing a file might require loading other files,
2142 ;; like "~/.netrc", and for them it shouldn't be decided based on that
2143 ;; variable. On the other hand, those files shouldn't have partial
2144 ;; Tramp file name syntax. Maybe another variable should be introduced
2145 ;; overwriting this check in such cases. Or we change Tramp file name
2146 ;; syntax in order to avoid ambiguities, like in XEmacs ...
2147 ;;;###tramp-autoload
2148 (defun tramp-completion-mode-p ()
2149 "Check, whether method / user name / host name completion is active."
2150 (or
2151 ;; Signal from outside. `non-essential' has been introduced in Emacs 24.
2152 (and (boundp 'non-essential) (symbol-value 'non-essential))
2153 tramp-completion-mode
2154 ;; Emacs.
2155 (equal last-input-event 'tab)
2156 (and (natnump last-input-event)
2157 (or
2158 ;; ?\t has event-modifier 'control.
2159 (equal last-input-event ?\t)
2160 (and (not (event-modifiers last-input-event))
2161 (or (equal last-input-event ?\?)
2162 (equal last-input-event ?\ )))))
2163 ;; XEmacs.
2164 (and (featurep 'xemacs)
2165 ;; `last-input-event' might be nil.
2166 (not (null last-input-event))
2167 ;; `last-input-event' may have no character approximation.
2168 (tramp-compat-funcall 'event-to-character last-input-event)
2169 (or
2170 ;; ?\t has event-modifier 'control.
2171 (equal
2172 (tramp-compat-funcall 'event-to-character last-input-event) ?\t)
2173 (and (not (event-modifiers last-input-event))
2174 (or (equal
2175 (tramp-compat-funcall 'event-to-character last-input-event)
2176 ?\?)
2177 (equal
2178 (tramp-compat-funcall 'event-to-character last-input-event)
2179 ?\ )))))))
2180
2181 (defun tramp-connectable-p (filename)
2182 "Check, whether it is possible to connect the remote host w/o side-effects.
2183 This is true, if either the remote host is already connected, or if we are
2184 not in completion mode."
2185 (and (tramp-tramp-file-p filename)
2186 (with-parsed-tramp-file-name filename nil
2187 (or (not (tramp-completion-mode-p))
2188 (let ((p (tramp-get-connection-process v)))
2189 (and p (processp p) (memq (process-status p) '(run open))))))))
2190
2191 ;; Method, host name and user name completion.
2192 ;; `tramp-completion-dissect-file-name' returns a list of
2193 ;; tramp-file-name structures. For all of them we return possible completions.
2194 ;;;###autoload
2195 (defun tramp-completion-handle-file-name-all-completions (filename directory)
2196 "Like `file-name-all-completions' for partial Tramp files."
2197
2198 (let ((fullname
2199 (tramp-drop-volume-letter (expand-file-name filename directory)))
2200 hop result result1)
2201
2202 ;; Suppress hop from completion.
2203 (when (string-match
2204 (concat
2205 tramp-prefix-regexp
2206 "\\(" "\\(" tramp-remote-file-name-spec-regexp
2207 tramp-postfix-hop-regexp
2208 "\\)+" "\\)")
2209 fullname)
2210 (setq hop (match-string 1 fullname)
2211 fullname (replace-match "" nil nil fullname 1)))
2212
2213 ;; Possible completion structures.
2214 (dolist (elt (tramp-completion-dissect-file-name fullname))
2215 (let* ((method (tramp-file-name-method elt))
2216 (user (tramp-file-name-user elt))
2217 (host (tramp-file-name-host elt))
2218 (localname (tramp-file-name-localname elt))
2219 (m (tramp-find-method method user host))
2220 (tramp-current-user user) ; see `tramp-parse-passwd'
2221 all-user-hosts)
2222
2223 (unless localname ;; Nothing to complete.
2224
2225 (if (or user host)
2226
2227 ;; Method dependent user / host combinations.
2228 (progn
2229 (mapc
2230 (lambda (x)
2231 (setq all-user-hosts
2232 (append all-user-hosts
2233 (funcall (nth 0 x) (nth 1 x)))))
2234 (tramp-get-completion-function m))
2235
2236 (setq result
2237 (append result
2238 (mapcar
2239 (lambda (x)
2240 (tramp-get-completion-user-host
2241 method user host (nth 0 x) (nth 1 x)))
2242 (delq nil all-user-hosts)))))
2243
2244 ;; Possible methods.
2245 (setq result
2246 (append result (tramp-get-completion-methods m)))))))
2247
2248 ;; Unify list, add hop, remove nil elements.
2249 (dolist (elt result)
2250 (when elt
2251 (string-match tramp-prefix-regexp elt)
2252 (setq elt (replace-match (concat tramp-prefix-format hop) nil nil elt))
2253 (add-to-list
2254 'result1
2255 (substring elt (length (tramp-drop-volume-letter directory))))))
2256
2257 ;; Complete local parts.
2258 (append
2259 result1
2260 (ignore-errors
2261 (apply (if (tramp-connectable-p fullname)
2262 'tramp-completion-run-real-handler
2263 'tramp-run-real-handler)
2264 'file-name-all-completions (list (list filename directory)))))))
2265
2266 ;; Method, host name and user name completion for a file.
2267 ;;;###autoload
2268 (defun tramp-completion-handle-file-name-completion
2269 (filename directory &optional predicate)
2270 "Like `file-name-completion' for Tramp files."
2271 (try-completion
2272 filename
2273 (mapcar 'list (file-name-all-completions filename directory))
2274 (when (and predicate
2275 (tramp-connectable-p (expand-file-name filename directory)))
2276 (lambda (x) (funcall predicate (expand-file-name (car x) directory))))))
2277
2278 ;; I misuse a little bit the tramp-file-name structure in order to handle
2279 ;; completion possibilities for partial methods / user names / host names.
2280 ;; Return value is a list of tramp-file-name structures according to possible
2281 ;; completions. If "localname" is non-nil it means there
2282 ;; shouldn't be a completion anymore.
2283
2284 ;; Expected results:
2285
2286 ;; "/x" "/[x" "/x@" "/[x@" "/x@y" "/[x@y"
2287 ;; [nil nil "x" nil] [nil "x" nil nil] [nil "x" "y" nil]
2288 ;; [nil "x" nil nil]
2289 ;; ["x" nil nil nil]
2290
2291 ;; "/x:" "/x:y" "/x:y:"
2292 ;; [nil nil "x" ""] [nil nil "x" "y"] ["x" nil "y" ""]
2293 ;; "/[x/" "/[x/y"
2294 ;; ["x" nil "" nil] ["x" nil "y" nil]
2295 ;; ["x" "" nil nil] ["x" "y" nil nil]
2296
2297 ;; "/x:y@" "/x:y@z" "/x:y@z:"
2298 ;; [nil nil "x" "y@"] [nil nil "x" "y@z"] ["x" "y" "z" ""]
2299 ;; "/[x/y@" "/[x/y@z"
2300 ;; ["x" nil "y" nil] ["x" "y" "z" nil]
2301 (defun tramp-completion-dissect-file-name (name)
2302 "Returns a list of `tramp-file-name' structures.
2303 They are collected by `tramp-completion-dissect-file-name1'."
2304
2305 (let* ((result)
2306 (x-nil "\\|\\(\\)")
2307 (tramp-completion-ipv6-regexp
2308 (format
2309 "[^%s]*"
2310 (if (zerop (length tramp-postfix-ipv6-format))
2311 tramp-postfix-host-format
2312 tramp-postfix-ipv6-format)))
2313 ;; "/method" "/[method"
2314 (tramp-completion-file-name-structure1
2315 (list (concat tramp-prefix-regexp "\\(" tramp-method-regexp x-nil "\\)$")
2316 1 nil nil nil))
2317 ;; "/user" "/[user"
2318 (tramp-completion-file-name-structure2
2319 (list (concat tramp-prefix-regexp "\\(" tramp-user-regexp x-nil "\\)$")
2320 nil 1 nil nil))
2321 ;; "/host" "/[host"
2322 (tramp-completion-file-name-structure3
2323 (list (concat tramp-prefix-regexp "\\(" tramp-host-regexp x-nil "\\)$")
2324 nil nil 1 nil))
2325 ;; "/[ipv6" "/[ipv6"
2326 (tramp-completion-file-name-structure4
2327 (list (concat tramp-prefix-regexp
2328 tramp-prefix-ipv6-regexp
2329 "\\(" tramp-completion-ipv6-regexp x-nil "\\)$")
2330 nil nil 1 nil))
2331 ;; "/user@host" "/[user@host"
2332 (tramp-completion-file-name-structure5
2333 (list (concat tramp-prefix-regexp
2334 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
2335 "\\(" tramp-host-regexp x-nil "\\)$")
2336 nil 1 2 nil))
2337 ;; "/user@[ipv6" "/[user@ipv6"
2338 (tramp-completion-file-name-structure6
2339 (list (concat tramp-prefix-regexp
2340 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
2341 tramp-prefix-ipv6-regexp
2342 "\\(" tramp-completion-ipv6-regexp x-nil "\\)$")
2343 nil 1 2 nil))
2344 ;; "/method:user" "/[method/user" "/method://user"
2345 (tramp-completion-file-name-structure7
2346 (list (concat tramp-prefix-regexp
2347 "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
2348 "\\(" tramp-user-regexp x-nil "\\)$")
2349 1 2 nil nil))
2350 ;; "/method:host" "/[method/host" "/method://host"
2351 (tramp-completion-file-name-structure8
2352 (list (concat tramp-prefix-regexp
2353 "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
2354 "\\(" tramp-host-regexp x-nil "\\)$")
2355 1 nil 2 nil))
2356 ;; "/method:[ipv6" "/[method/ipv6" "/method://[ipv6"
2357 (tramp-completion-file-name-structure9
2358 (list (concat tramp-prefix-regexp
2359 "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
2360 tramp-prefix-ipv6-regexp
2361 "\\(" tramp-completion-ipv6-regexp x-nil "\\)$")
2362 1 nil 2 nil))
2363 ;; "/method:user@host" "/[method/user@host" "/method://user@host"
2364 (tramp-completion-file-name-structure10
2365 (list (concat tramp-prefix-regexp
2366 "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
2367 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
2368 "\\(" tramp-host-regexp x-nil "\\)$")
2369 1 2 3 nil))
2370 ;; "/method:user@[ipv6" "/[method/user@ipv6" "/method://user@[ipv6"
2371 (tramp-completion-file-name-structure11
2372 (list (concat tramp-prefix-regexp
2373 "\\(" tramp-method-regexp "\\)" tramp-postfix-method-regexp
2374 "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp
2375 tramp-prefix-ipv6-regexp
2376 "\\(" tramp-completion-ipv6-regexp x-nil "\\)$")
2377 1 2 3 nil))
2378 ;; "/method: "/method:/"
2379 (tramp-completion-file-name-structure12
2380 (list
2381 (if (equal tramp-syntax 'url)
2382 (concat tramp-prefix-regexp
2383 "\\(" tramp-method-regexp "\\)"
2384 "\\(" (substring tramp-postfix-method-regexp 0 1)
2385 "\\|" (substring tramp-postfix-method-regexp 1 2) "\\)"
2386 "\\(" "\\)$")
2387 ;; Should not match if not URL syntax.
2388 (concat tramp-prefix-regexp "/$"))
2389 1 3 nil nil))
2390 ;; "/method: "/method:/"
2391 (tramp-completion-file-name-structure13
2392 (list
2393 (if (equal tramp-syntax 'url)
2394 (concat tramp-prefix-regexp
2395 "\\(" tramp-method-regexp "\\)"
2396 "\\(" (substring tramp-postfix-method-regexp 0 1)
2397 "\\|" (substring tramp-postfix-method-regexp 1 2) "\\)"
2398 "\\(" "\\)$")
2399 ;; Should not match if not URL syntax.
2400 (concat tramp-prefix-regexp "/$"))
2401 1 nil 3 nil)))
2402
2403 (mapc (lambda (structure)
2404 (add-to-list 'result
2405 (tramp-completion-dissect-file-name1 structure name)))
2406 (list
2407 tramp-completion-file-name-structure1
2408 tramp-completion-file-name-structure2
2409 tramp-completion-file-name-structure3
2410 tramp-completion-file-name-structure4
2411 tramp-completion-file-name-structure5
2412 tramp-completion-file-name-structure6
2413 tramp-completion-file-name-structure7
2414 tramp-completion-file-name-structure8
2415 tramp-completion-file-name-structure9
2416 tramp-completion-file-name-structure10
2417 tramp-completion-file-name-structure11
2418 tramp-completion-file-name-structure12
2419 tramp-completion-file-name-structure13
2420 tramp-file-name-structure))
2421
2422 (delq nil result)))
2423
2424 (defun tramp-completion-dissect-file-name1 (structure name)
2425 "Returns a `tramp-file-name' structure matching STRUCTURE.
2426 The structure consists of remote method, remote user,
2427 remote host and localname (filename on remote host)."
2428
2429 (save-match-data
2430 (when (string-match (nth 0 structure) name)
2431 (let ((method (and (nth 1 structure)
2432 (match-string (nth 1 structure) name)))
2433 (user (and (nth 2 structure)
2434 (match-string (nth 2 structure) name)))
2435 (host (and (nth 3 structure)
2436 (match-string (nth 3 structure) name)))
2437 (localname (and (nth 4 structure)
2438 (match-string (nth 4 structure) name))))
2439 (vector method user host localname nil)))))
2440
2441 ;; This function returns all possible method completions, adding the
2442 ;; trailing method delimiter.
2443 (defun tramp-get-completion-methods (partial-method)
2444 "Returns all method completions for PARTIAL-METHOD."
2445 (mapcar
2446 (lambda (method)
2447 (and method
2448 (string-match (concat "^" (regexp-quote partial-method)) method)
2449 (tramp-completion-make-tramp-file-name method nil nil nil)))
2450 (mapcar 'car tramp-methods)))
2451
2452 ;; Compares partial user and host names with possible completions.
2453 (defun tramp-get-completion-user-host
2454 (method partial-user partial-host user host)
2455 "Returns the most expanded string for user and host name completion.
2456 PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
2457 (cond
2458
2459 ((and partial-user partial-host)
2460 (if (and host
2461 (string-match (concat "^" (regexp-quote partial-host)) host)
2462 (string-equal partial-user (or user partial-user)))
2463 (setq user partial-user)
2464 (setq user nil
2465 host nil)))
2466
2467 (partial-user
2468 (setq host nil)
2469 (unless
2470 (and user (string-match (concat "^" (regexp-quote partial-user)) user))
2471 (setq user nil)))
2472
2473 (partial-host
2474 (setq user nil)
2475 (unless
2476 (and host (string-match (concat "^" (regexp-quote partial-host)) host))
2477 (setq host nil)))
2478
2479 (t (setq user nil
2480 host nil)))
2481
2482 (unless (zerop (+ (length user) (length host)))
2483 (tramp-completion-make-tramp-file-name method user host nil)))
2484
2485 ;; Generic function.
2486 (defun tramp-parse-group (regexp match-level skip-regexp)
2487 "Return a (user host) tuple allowed to access.
2488 User is always nil."
2489 (let (result)
2490 (when (re-search-forward regexp (point-at-eol) t)
2491 (setq result (list nil (match-string match-level))))
2492 (or
2493 (> (skip-chars-forward skip-regexp) 0)
2494 (forward-line 1))
2495 result))
2496
2497 ;; Generic function.
2498 (defun tramp-parse-file (filename function)
2499 "Return a list of (user host) tuples allowed to access.
2500 User is always nil."
2501 ;; On Windows, there are problems in completion when
2502 ;; `default-directory' is remote.
2503 (let ((default-directory (tramp-compat-temporary-file-directory)))
2504 (when (file-readable-p filename)
2505 (with-temp-buffer
2506 (insert-file-contents filename)
2507 (goto-char (point-min))
2508 (loop while (not (eobp)) collect (funcall function))))))
2509
2510 ;;;###tramp-autoload
2511 (defun tramp-parse-rhosts (filename)
2512 "Return a list of (user host) tuples allowed to access.
2513 Either user or host may be nil."
2514 (tramp-parse-file filename 'tramp-parse-rhosts-group))
2515
2516 (defun tramp-parse-rhosts-group ()
2517 "Return a (user host) tuple allowed to access.
2518 Either user or host may be nil."
2519 (let ((result)
2520 (regexp
2521 (concat
2522 "^\\(" tramp-host-regexp "\\)"
2523 "\\([ \t]+" "\\(" tramp-user-regexp "\\)" "\\)?")))
2524 (when (re-search-forward regexp (point-at-eol) t)
2525 (setq result (append (list (match-string 3) (match-string 1)))))
2526 (forward-line 1)
2527 result))
2528
2529 ;;;###tramp-autoload
2530 (defun tramp-parse-shosts (filename)
2531 "Return a list of (user host) tuples allowed to access.
2532 User is always nil."
2533 (tramp-parse-file filename 'tramp-parse-shosts-group))
2534
2535 (defun tramp-parse-shosts-group ()
2536 "Return a (user host) tuple allowed to access.
2537 User is always nil."
2538 (tramp-parse-group (concat "^\\(" tramp-host-regexp "\\)") 1 ","))
2539
2540 ;;;###tramp-autoload
2541 (defun tramp-parse-sconfig (filename)
2542 "Return a list of (user host) tuples allowed to access.
2543 User is always nil."
2544 (tramp-parse-file filename 'tramp-parse-sconfig-group))
2545
2546 (defun tramp-parse-sconfig-group ()
2547 "Return a (user host) tuple allowed to access.
2548 User is always nil."
2549 (tramp-parse-group
2550 (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp "\\)") 1 ","))
2551
2552 ;; Generic function.
2553 (defun tramp-parse-shostkeys-sknownhosts (dirname regexp)
2554 "Return a list of (user host) tuples allowed to access.
2555 User is always nil."
2556 ;; On Windows, there are problems in completion when
2557 ;; `default-directory' is remote.
2558 (let* ((default-directory (tramp-compat-temporary-file-directory))
2559 (files (and (file-directory-p dirname) (directory-files dirname))))
2560 (loop for f in files
2561 when (and (not (string-match "^\\.\\.?$" f)) (string-match regexp f))
2562 collect (list nil (match-string 1 f)))))
2563
2564 ;;;###tramp-autoload
2565 (defun tramp-parse-shostkeys (dirname)
2566 "Return a list of (user host) tuples allowed to access.
2567 User is always nil."
2568 (tramp-parse-shostkeys-sknownhosts
2569 dirname (concat "^key_[0-9]+_\\(" tramp-host-regexp "\\)\\.pub$")))
2570
2571 ;;;###tramp-autoload
2572 (defun tramp-parse-sknownhosts (dirname)
2573 "Return a list of (user host) tuples allowed to access.
2574 User is always nil."
2575 (tramp-parse-shostkeys-sknownhosts
2576 dirname
2577 (concat "^\\(" tramp-host-regexp "\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$")))
2578
2579 ;;;###tramp-autoload
2580 (defun tramp-parse-hosts (filename)
2581 "Return a list of (user host) tuples allowed to access.
2582 User is always nil."
2583 (tramp-parse-file filename 'tramp-parse-hosts-group))
2584
2585 (defun tramp-parse-hosts-group ()
2586 "Return a (user host) tuple allowed to access.
2587 User is always nil."
2588 (tramp-parse-group
2589 (concat "^\\(" tramp-ipv6-regexp "\\|" tramp-host-regexp "\\)") 1 " \t"))
2590
2591 ;; For su-alike methods it would be desirable to return "root@localhost"
2592 ;; as default. Unfortunately, we have no information whether any user name
2593 ;; has been typed already. So we use `tramp-current-user' as indication,
2594 ;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
2595 ;;;###tramp-autoload
2596 (defun tramp-parse-passwd (filename)
2597 "Return a list of (user host) tuples allowed to access.
2598 Host is always \"localhost\"."
2599 (if (zerop (length tramp-current-user))
2600 '(("root" nil))
2601 (tramp-parse-file filename 'tramp-parse-passwd-group)))
2602
2603 (defun tramp-parse-passwd-group ()
2604 "Return a (user host) tuple allowed to access.
2605 Host is always \"localhost\"."
2606 (let ((result)
2607 (regexp (concat "^\\(" tramp-user-regexp "\\):")))
2608 (when (re-search-forward regexp (point-at-eol) t)
2609 (setq result (list (match-string 1) "localhost")))
2610 (forward-line 1)
2611 result))
2612
2613 ;;;###tramp-autoload
2614 (defun tramp-parse-netrc (filename)
2615 "Return a list of (user host) tuples allowed to access.
2616 User may be nil."
2617 (tramp-parse-file filename 'tramp-parse-netrc-group))
2618
2619 (defun tramp-parse-netrc-group ()
2620 "Return a (user host) tuple allowed to access.
2621 User may be nil."
2622 (let ((result)
2623 (regexp
2624 (concat
2625 "^[ \t]*machine[ \t]+" "\\(" tramp-host-regexp "\\)"
2626 "\\([ \t]+login[ \t]+" "\\(" tramp-user-regexp "\\)" "\\)?")))
2627 (when (re-search-forward regexp (point-at-eol) t)
2628 (setq result (list (match-string 3) (match-string 1))))
2629 (forward-line 1)
2630 result))
2631
2632 ;;;###tramp-autoload
2633 (defun tramp-parse-putty (registry-or-dirname)
2634 "Return a list of (user host) tuples allowed to access.
2635 User is always nil."
2636 (if (memq system-type '(windows-nt))
2637 (with-temp-buffer
2638 (when (zerop (tramp-compat-call-process
2639 "reg" nil t nil "query" registry-or-dirname))
2640 (goto-char (point-min))
2641 (loop while (not (eobp)) collect
2642 (tramp-parse-putty-group registry-or-dirname))))
2643 ;; UNIX case.
2644 (tramp-parse-shostkeys-sknownhosts
2645 registry-or-dirname (concat "^\\(" tramp-host-regexp "\\)$"))))
2646
2647 (defun tramp-parse-putty-group (registry)
2648 "Return a (user host) tuple allowed to access.
2649 User is always nil."
2650 (let ((result)
2651 (regexp (concat (regexp-quote registry) "\\\\\\(.+\\)")))
2652 (when (re-search-forward regexp (point-at-eol) t)
2653 (setq result (list nil (match-string 1))))
2654 (forward-line 1)
2655 result))
2656
2657 ;;; Common file name handler functions for different backends:
2658
2659 (defvar tramp-handle-file-local-copy-hook nil
2660 "Normal hook to be run at the end of `tramp-*-handle-file-local-copy'.")
2661
2662 (defvar tramp-handle-write-region-hook nil
2663 "Normal hook to be run at the end of `tramp-*-handle-write-region'.")
2664
2665 (defun tramp-handle-directory-file-name (directory)
2666 "Like `directory-file-name' for Tramp files."
2667 ;; If localname component of filename is "/", leave it unchanged.
2668 ;; Otherwise, remove any trailing slash from localname component.
2669 ;; Method, host, etc, are unchanged. Does it make sense to try
2670 ;; to avoid parsing the filename?
2671 (with-parsed-tramp-file-name directory nil
2672 (if (and (not (zerop (length localname)))
2673 (eq (aref localname (1- (length localname))) ?/)
2674 (not (string= localname "/")))
2675 (substring directory 0 -1)
2676 directory)))
2677
2678 (defun tramp-handle-directory-files
2679 (directory &optional full match nosort files-only)
2680 "Like `directory-files' for Tramp files."
2681 ;; FILES-ONLY is valid for XEmacs only.
2682 (when (file-directory-p directory)
2683 (setq directory (file-name-as-directory (expand-file-name directory)))
2684 (let ((temp (nreverse (file-name-all-completions "" directory)))
2685 result item)
2686
2687 (while temp
2688 (setq item (directory-file-name (pop temp)))
2689 (when (and (or (null match) (string-match match item))
2690 (or (null files-only)
2691 ;; Files only.
2692 (and (equal files-only t) (file-regular-p item))
2693 ;; Directories only.
2694 (file-directory-p item)))
2695 (push (if full (concat directory item) item)
2696 result)))
2697 (if nosort result (sort result 'string<)))))
2698
2699 (defun tramp-handle-directory-files-and-attributes
2700 (directory &optional full match nosort id-format)
2701 "Like `directory-files-and-attributes' for Tramp files."
2702 (mapcar
2703 (lambda (x)
2704 (cons x (tramp-compat-file-attributes
2705 (if full x (expand-file-name x directory)) id-format)))
2706 (directory-files directory full match nosort)))
2707
2708 (defun tramp-handle-dired-uncache (dir &optional dir-p)
2709 "Like `dired-uncache' for Tramp files."
2710 ;; DIR-P is valid for XEmacs only.
2711 (with-parsed-tramp-file-name
2712 (if (or dir-p (file-directory-p dir)) dir (file-name-directory dir)) nil
2713 (tramp-flush-directory-property v localname)))
2714
2715 (defun tramp-handle-file-exists-p (filename)
2716 "Like `file-exists-p' for Tramp files."
2717 (not (null (file-attributes filename))))
2718
2719 (defun tramp-handle-file-modes (filename)
2720 "Like `file-modes' for Tramp files."
2721 (let ((truename (or (file-truename filename) filename)))
2722 (when (file-exists-p truename)
2723 (tramp-mode-string-to-int (nth 8 (file-attributes truename))))))
2724
2725 ;; Localname manipulation functions that grok Tramp localnames...
2726 (defun tramp-handle-file-name-as-directory (file)
2727 "Like `file-name-as-directory' but aware of Tramp files."
2728 ;; `file-name-as-directory' would be sufficient except localname is
2729 ;; the empty string.
2730 (let ((v (tramp-dissect-file-name file t)))
2731 ;; Run the command on the localname portion only.
2732 (tramp-make-tramp-file-name
2733 (tramp-file-name-method v)
2734 (tramp-file-name-user v)
2735 (tramp-file-name-host v)
2736 (tramp-run-real-handler
2737 'file-name-as-directory (list (or (tramp-file-name-localname v) ""))))))
2738
2739 (defun tramp-handle-file-name-completion
2740 (filename directory &optional predicate)
2741 "Like `file-name-completion' for Tramp files."
2742 (unless (tramp-tramp-file-p directory)
2743 (error
2744 "tramp-handle-file-name-completion invoked on non-tramp directory `%s'"
2745 directory))
2746 (try-completion
2747 filename
2748 (mapcar 'list (file-name-all-completions filename directory))
2749 (when predicate
2750 (lambda (x) (funcall predicate (expand-file-name (car x) directory))))))
2751
2752 (defun tramp-handle-file-name-directory (file)
2753 "Like `file-name-directory' but aware of Tramp files."
2754 ;; Everything except the last filename thing is the directory. We
2755 ;; cannot apply `with-parsed-tramp-file-name', because this expands
2756 ;; the remote file name parts. This is a problem when we are in
2757 ;; file name completion.
2758 (let ((v (tramp-dissect-file-name file t)))
2759 ;; Run the command on the localname portion only.
2760 (tramp-make-tramp-file-name
2761 (tramp-file-name-method v)
2762 (tramp-file-name-user v)
2763 (tramp-file-name-host v)
2764 (tramp-run-real-handler
2765 'file-name-directory (list (or (tramp-file-name-localname v) ""))))))
2766
2767 (defun tramp-handle-file-name-nondirectory (file)
2768 "Like `file-name-nondirectory' but aware of Tramp files."
2769 (with-parsed-tramp-file-name file nil
2770 (tramp-run-real-handler 'file-name-nondirectory (list localname))))
2771
2772 (defun tramp-handle-file-newer-than-file-p (file1 file2)
2773 "Like `file-newer-than-file-p' for Tramp files."
2774 (cond
2775 ((not (file-exists-p file1)) nil)
2776 ((not (file-exists-p file2)) t)
2777 (t (tramp-time-less-p (nth 5 (file-attributes file2))
2778 (nth 5 (file-attributes file1))))))
2779
2780 (defun tramp-handle-file-regular-p (filename)
2781 "Like `file-regular-p' for Tramp files."
2782 (and (file-exists-p filename)
2783 (eq ?- (aref (nth 8 (file-attributes filename)) 0))))
2784
2785 (defun tramp-handle-file-remote-p (filename &optional identification connected)
2786 "Like `file-remote-p' for Tramp files."
2787 (let ((tramp-verbose 3))
2788 (when (tramp-tramp-file-p filename)
2789 (let* ((v (tramp-dissect-file-name filename))
2790 (p (tramp-get-connection-process v))
2791 (c (and p (processp p) (memq (process-status p) '(run open)))))
2792 ;; We expand the file name only, if there is already a connection.
2793 (with-parsed-tramp-file-name
2794 (if c (expand-file-name filename) filename) nil
2795 (and (or (not connected) c)
2796 (cond
2797 ((eq identification 'method) method)
2798 ((eq identification 'user) user)
2799 ((eq identification 'host) host)
2800 ((eq identification 'localname) localname)
2801 (t (tramp-make-tramp-file-name method user host "")))))))))
2802
2803 (defun tramp-handle-file-symlink-p (filename)
2804 "Like `file-symlink-p' for Tramp files."
2805 (with-parsed-tramp-file-name filename nil
2806 (let ((x (car (file-attributes filename))))
2807 (when (stringp x)
2808 ;; When Tramp is running on VMS, then `file-name-absolute-p'
2809 ;; might do weird things.
2810 (if (file-name-absolute-p x)
2811 (tramp-make-tramp-file-name method user host x)
2812 x)))))
2813
2814 (defun tramp-handle-find-backup-file-name (filename)
2815 "Like `find-backup-file-name' for Tramp files."
2816 (with-parsed-tramp-file-name filename nil
2817 ;; We set both variables. It doesn't matter whether it is
2818 ;; Emacs or XEmacs.
2819 (let ((backup-directory-alist
2820 ;; Emacs case.
2821 (when (boundp 'backup-directory-alist)
2822 (if (symbol-value 'tramp-backup-directory-alist)
2823 (mapcar
2824 (lambda (x)
2825 (cons
2826 (car x)
2827 (if (and (stringp (cdr x))
2828 (file-name-absolute-p (cdr x))
2829 (not (tramp-file-name-p (cdr x))))
2830 (tramp-make-tramp-file-name method user host (cdr x))
2831 (cdr x))))
2832 (symbol-value 'tramp-backup-directory-alist))
2833 (symbol-value 'backup-directory-alist))))
2834
2835 (bkup-backup-directory-info
2836 ;; XEmacs case.
2837 (when (boundp 'bkup-backup-directory-info)
2838 (if (symbol-value 'tramp-bkup-backup-directory-info)
2839 (mapcar
2840 (lambda (x)
2841 (nconc
2842 (list (car x))
2843 (list
2844 (if (and (stringp (car (cdr x)))
2845 (file-name-absolute-p (car (cdr x)))
2846 (not (tramp-file-name-p (car (cdr x)))))
2847 (tramp-make-tramp-file-name
2848 method user host (car (cdr x)))
2849 (car (cdr x))))
2850 (cdr (cdr x))))
2851 (symbol-value 'tramp-bkup-backup-directory-info))
2852 (symbol-value 'bkup-backup-directory-info)))))
2853
2854 (tramp-run-real-handler 'find-backup-file-name (list filename)))))
2855
2856 (defun tramp-handle-insert-file-contents
2857 (filename &optional visit beg end replace)
2858 "Like `insert-file-contents' for Tramp files."
2859 (barf-if-buffer-read-only)
2860 (setq filename (expand-file-name filename))
2861 (let (result local-copy remote-copy)
2862 (with-parsed-tramp-file-name filename nil
2863 (tramp-with-progress-reporter
2864 v 3 (format "Inserting `%s'" filename)
2865 (unwind-protect
2866 (if (not (file-exists-p filename))
2867 ;; We don't raise a Tramp error, because it might be
2868 ;; suppressed, like in `find-file-noselect-1'.
2869 (signal 'file-error
2870 (list "File not found on remote host" filename))
2871
2872 (if (and (tramp-local-host-p v)
2873 (let (file-name-handler-alist)
2874 (file-readable-p localname)))
2875 ;; Short track: if we are on the local host, we can
2876 ;; run directly.
2877 (setq result
2878 (tramp-run-real-handler
2879 'insert-file-contents
2880 (list localname visit beg end replace)))
2881
2882 ;; When we shall insert only a part of the file, we
2883 ;; copy this part.
2884 (when (or beg end)
2885 (setq remote-copy (tramp-make-tramp-temp-file v))
2886 ;; This is defined in tramp-sh.el. Let's assume
2887 ;; this is loaded already.
2888 (tramp-compat-funcall
2889 'tramp-send-command
2890 v
2891 (cond
2892 ((and beg end)
2893 (format "dd bs=1 skip=%d if=%s count=%d of=%s"
2894 beg (tramp-shell-quote-argument localname)
2895 (- end beg) remote-copy))
2896 (beg
2897 (format "dd bs=1 skip=%d if=%s of=%s"
2898 beg (tramp-shell-quote-argument localname)
2899 remote-copy))
2900 (end
2901 (format "dd bs=1 count=%d if=%s of=%s"
2902 end (tramp-shell-quote-argument localname)
2903 remote-copy)))))
2904
2905 ;; `insert-file-contents-literally' takes care to
2906 ;; avoid calling jka-compr. By let-binding
2907 ;; `inhibit-file-name-operation', we propagate that
2908 ;; care to the `file-local-copy' operation.
2909 (setq local-copy
2910 (let ((inhibit-file-name-operation
2911 (when (eq inhibit-file-name-operation
2912 'insert-file-contents)
2913 'file-local-copy)))
2914 (cond
2915 ((stringp remote-copy)
2916 (file-local-copy
2917 (tramp-make-tramp-file-name
2918 method user host remote-copy)))
2919 ((stringp tramp-temp-buffer-file-name)
2920 (copy-file filename tramp-temp-buffer-file-name 'ok)
2921 tramp-temp-buffer-file-name)
2922 (t (file-local-copy filename)))))
2923
2924 ;; When the file is not readable for the owner, it
2925 ;; cannot be inserted, even if it is readable for the
2926 ;; group or for everybody.
2927 (set-file-modes
2928 local-copy (tramp-compat-octal-to-decimal "0600"))
2929
2930 (when (and (null remote-copy)
2931 (tramp-get-method-parameter
2932 method 'tramp-copy-keep-tmpfile))
2933 ;; We keep the local file for performance reasons,
2934 ;; useful for "rsync".
2935 (setq tramp-temp-buffer-file-name local-copy))
2936
2937 ;; We must ensure that `file-coding-system-alist'
2938 ;; matches `local-copy'.
2939 (let ((file-coding-system-alist
2940 (tramp-find-file-name-coding-system-alist
2941 filename local-copy)))
2942 (setq result
2943 (insert-file-contents
2944 local-copy nil nil nil replace)))))
2945
2946 ;; Save exit.
2947 (progn
2948 (when visit
2949 (setq buffer-file-name filename)
2950 (setq buffer-read-only (not (file-writable-p filename)))
2951 (set-visited-file-modtime)
2952 (set-buffer-modified-p nil))
2953 (when (and (stringp local-copy)
2954 (or remote-copy (null tramp-temp-buffer-file-name)))
2955 (delete-file local-copy))
2956 (when (stringp remote-copy)
2957 (delete-file
2958 (tramp-make-tramp-file-name method user host remote-copy)))))))
2959
2960 ;; Result.
2961 (list (expand-file-name filename)
2962 (cadr result))))
2963
2964 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
2965 "Like `load' for Tramp files."
2966 (with-parsed-tramp-file-name (expand-file-name file) nil
2967 (unless nosuffix
2968 (cond ((file-exists-p (concat file ".elc"))
2969 (setq file (concat file ".elc")))
2970 ((file-exists-p (concat file ".el"))
2971 (setq file (concat file ".el")))))
2972 (when must-suffix
2973 ;; The first condition is always true for absolute file names.
2974 ;; Included for safety's sake.
2975 (unless (or (file-name-directory file)
2976 (string-match "\\.elc?\\'" file))
2977 (tramp-error
2978 v 'file-error
2979 "File `%s' does not include a `.el' or `.elc' suffix" file)))
2980 (unless noerror
2981 (when (not (file-exists-p file))
2982 (tramp-error v 'file-error "Cannot load nonexistent file `%s'" file)))
2983 (if (not (file-exists-p file))
2984 nil
2985 (let ((tramp-message-show-message (not nomessage)))
2986 (tramp-with-progress-reporter v 0 (format "Loading %s" file)
2987 (let ((local-copy (file-local-copy file)))
2988 ;; MUST-SUFFIX doesn't exist on XEmacs, so let it default to nil.
2989 (unwind-protect
2990 (load local-copy noerror t t)
2991 (delete-file local-copy)))))
2992 t)))
2993
2994 (defun tramp-handle-shell-command
2995 (command &optional output-buffer error-buffer)
2996 "Like `shell-command' for Tramp files."
2997 (let* ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
2998 ;; We cannot use `shell-file-name' and `shell-command-switch',
2999 ;; they are variables of the local host.
3000 (args (append
3001 (cons
3002 (tramp-get-method-parameter
3003 (tramp-file-name-method
3004 (tramp-dissect-file-name default-directory))
3005 'tramp-remote-shell)
3006 (tramp-get-method-parameter
3007 (tramp-file-name-method
3008 (tramp-dissect-file-name default-directory))
3009 'tramp-remote-shell-args))
3010 (list (substring command 0 asynchronous))))
3011 current-buffer-p
3012 (output-buffer
3013 (cond
3014 ((bufferp output-buffer) output-buffer)
3015 ((stringp output-buffer) (get-buffer-create output-buffer))
3016 (output-buffer
3017 (setq current-buffer-p t)
3018 (current-buffer))
3019 (t (get-buffer-create
3020 (if asynchronous
3021 "*Async Shell Command*"
3022 "*Shell Command Output*")))))
3023 (error-buffer
3024 (cond
3025 ((bufferp error-buffer) error-buffer)
3026 ((stringp error-buffer) (get-buffer-create error-buffer))))
3027 (buffer
3028 (if (and (not asynchronous) error-buffer)
3029 (with-parsed-tramp-file-name default-directory nil
3030 (list output-buffer (tramp-make-tramp-temp-file v)))
3031 output-buffer))
3032 (p (get-buffer-process output-buffer)))
3033
3034 ;; Check whether there is another process running. Tramp does not
3035 ;; support 2 (asynchronous) processes in parallel.
3036 (when p
3037 (if (yes-or-no-p "A command is running. Kill it? ")
3038 (ignore-errors (kill-process p))
3039 (error "Shell command in progress")))
3040
3041 (if current-buffer-p
3042 (progn
3043 (barf-if-buffer-read-only)
3044 (push-mark nil t))
3045 (with-current-buffer output-buffer
3046 (setq buffer-read-only nil)
3047 (erase-buffer)))
3048
3049 (if (and (not current-buffer-p) (integerp asynchronous))
3050 (prog1
3051 ;; Run the process.
3052 (setq p (apply 'start-file-process "*Async Shell*" buffer args))
3053 ;; Display output.
3054 (pop-to-buffer output-buffer)
3055 (setq mode-line-process '(":%s"))
3056 (shell-mode)
3057 (set-process-sentinel p 'shell-command-sentinel)
3058 (set-process-filter p 'comint-output-filter))
3059
3060 (prog1
3061 ;; Run the process.
3062 (apply 'process-file (car args) nil buffer nil (cdr args))
3063 ;; Insert error messages if they were separated.
3064 (when (listp buffer)
3065 (with-current-buffer error-buffer
3066 (insert-file-contents (cadr buffer)))
3067 (delete-file (cadr buffer)))
3068 (if current-buffer-p
3069 ;; This is like exchange-point-and-mark, but doesn't
3070 ;; activate the mark. It is cleaner to avoid activation,
3071 ;; even though the command loop would deactivate the mark
3072 ;; because we inserted text.
3073 (goto-char (prog1 (mark t)
3074 (set-marker (mark-marker) (point)
3075 (current-buffer))))
3076 ;; There's some output, display it.
3077 (when (with-current-buffer output-buffer (> (point-max) (point-min)))
3078 (if (functionp 'display-message-or-buffer)
3079 (tramp-compat-funcall 'display-message-or-buffer output-buffer)
3080 (pop-to-buffer output-buffer))))))))
3081
3082 (defun tramp-handle-substitute-in-file-name (filename)
3083 "Like `substitute-in-file-name' for Tramp files.
3084 \"//\" and \"/~\" substitute only in the local filename part.
3085 If the URL Tramp syntax is chosen, \"//\" as method delimiter and \"/~\" at
3086 beginning of local filename are not substituted."
3087 ;; First, we must replace environment variables.
3088 (setq filename (tramp-replace-environment-variables filename))
3089 (with-parsed-tramp-file-name filename nil
3090 (if (equal tramp-syntax 'url)
3091 ;; We need to check localname only. The other parts cannot contain
3092 ;; "//" or "/~".
3093 (if (and (> (length localname) 1)
3094 (or (string-match "//" localname)
3095 (string-match "/~" localname 1)))
3096 (tramp-run-real-handler 'substitute-in-file-name (list filename))
3097 (tramp-make-tramp-file-name
3098 (when method (substitute-in-file-name method))
3099 (when user (substitute-in-file-name user))
3100 (when host (substitute-in-file-name host))
3101 (when localname
3102 (tramp-run-real-handler
3103 'substitute-in-file-name (list localname)))))
3104 ;; Ignore in LOCALNAME everything before "//" or "/~".
3105 (when (and (stringp localname) (string-match ".+?/\\(/\\|~\\)" localname))
3106 (setq filename
3107 (concat (file-remote-p filename)
3108 (replace-match "\\1" nil nil localname)))
3109 ;; "/m:h:~" does not work for completion. We use "/m:h:~/".
3110 (when (string-match "~$" filename)
3111 (setq filename (concat filename "/"))))
3112 (tramp-run-real-handler 'substitute-in-file-name (list filename)))))
3113
3114 (defun tramp-handle-unhandled-file-name-directory (filename)
3115 "Like `unhandled-file-name-directory' for Tramp files."
3116 ;; With Emacs 23, we could simply return `nil'. But we must keep it
3117 ;; for backward compatibility.
3118 (expand-file-name "~/"))
3119
3120 ;;; Functions for establishing connection:
3121
3122 ;; The following functions are actions to be taken when seeing certain
3123 ;; prompts from the remote host. See the variable
3124 ;; `tramp-actions-before-shell' for usage of these functions.
3125
3126 (defun tramp-action-login (proc vec)
3127 "Send the login name."
3128 (when (not (stringp tramp-current-user))
3129 (setq tramp-current-user
3130 (with-connection-property vec "login-as"
3131 (save-window-excursion
3132 (let ((enable-recursive-minibuffers t))
3133 (pop-to-buffer (tramp-get-connection-buffer vec))
3134 (read-string (match-string 0)))))))
3135 (with-current-buffer (tramp-get-connection-buffer vec)
3136 (tramp-message vec 6 "\n%s" (buffer-string)))
3137 (tramp-message vec 3 "Sending login name `%s'" tramp-current-user)
3138 (tramp-send-string vec (concat tramp-current-user tramp-local-end-of-line)))
3139
3140 (defun tramp-action-password (proc vec)
3141 "Query the user for a password."
3142 (with-current-buffer (process-buffer proc)
3143 (let ((enable-recursive-minibuffers t))
3144 (tramp-check-for-regexp proc tramp-password-prompt-regexp)
3145 (tramp-message vec 3 "Sending %s" (match-string 1))
3146 ;; We don't call `tramp-send-string' in order to hide the
3147 ;; password from the debug buffer.
3148 (process-send-string
3149 proc (concat (tramp-read-passwd proc) tramp-local-end-of-line))
3150 ;; Hide password prompt.
3151 (narrow-to-region (point-max) (point-max)))))
3152
3153 (defun tramp-action-succeed (proc vec)
3154 "Signal success in finding shell prompt."
3155 (throw 'tramp-action 'ok))
3156
3157 (defun tramp-action-permission-denied (proc vec)
3158 "Signal permission denied."
3159 (kill-process proc)
3160 (throw 'tramp-action 'permission-denied))
3161
3162 (defun tramp-action-yesno (proc vec)
3163 "Ask the user for confirmation using `yes-or-no-p'.
3164 Send \"yes\" to remote process on confirmation, abort otherwise.
3165 See also `tramp-action-yn'."
3166 (save-window-excursion
3167 (let ((enable-recursive-minibuffers t))
3168 (save-match-data (pop-to-buffer (tramp-get-connection-buffer vec)))
3169 (unless (yes-or-no-p (match-string 0))
3170 (kill-process proc)
3171 (throw 'tramp-action 'permission-denied))
3172 (with-current-buffer (tramp-get-connection-buffer vec)
3173 (tramp-message vec 6 "\n%s" (buffer-string)))
3174 (tramp-send-string vec (concat "yes" tramp-local-end-of-line)))))
3175
3176 (defun tramp-action-yn (proc vec)
3177 "Ask the user for confirmation using `y-or-n-p'.
3178 Send \"y\" to remote process on confirmation, abort otherwise.
3179 See also `tramp-action-yesno'."
3180 (save-window-excursion
3181 (let ((enable-recursive-minibuffers t))
3182 (save-match-data (pop-to-buffer (tramp-get-connection-buffer vec)))
3183 (unless (y-or-n-p (match-string 0))
3184 (kill-process proc)
3185 (throw 'tramp-action 'permission-denied))
3186 (with-current-buffer (tramp-get-connection-buffer vec)
3187 (tramp-message vec 6 "\n%s" (buffer-string)))
3188 (tramp-send-string vec (concat "y" tramp-local-end-of-line)))))
3189
3190 (defun tramp-action-terminal (proc vec)
3191 "Tell the remote host which terminal type to use.
3192 The terminal type can be configured with `tramp-terminal-type'."
3193 (tramp-message vec 5 "Setting `%s' as terminal type." tramp-terminal-type)
3194 (with-current-buffer (tramp-get-connection-buffer vec)
3195 (tramp-message vec 6 "\n%s" (buffer-string)))
3196 (tramp-send-string vec (concat tramp-terminal-type tramp-local-end-of-line)))
3197
3198 (defun tramp-action-process-alive (proc vec)
3199 "Check, whether a process has finished."
3200 (unless (memq (process-status proc) '(run open))
3201 (throw 'tramp-action 'process-died)))
3202
3203 (defun tramp-action-out-of-band (proc vec)
3204 "Check, whether an out-of-band copy has finished."
3205 (cond ((and (memq (process-status proc) '(stop exit))
3206 (zerop (process-exit-status proc)))
3207 (tramp-message vec 3 "Process has finished.")
3208 (throw 'tramp-action 'ok))
3209 ((or (and (memq (process-status proc) '(stop exit))
3210 (not (zerop (process-exit-status proc))))
3211 (memq (process-status proc) '(signal)))
3212 ;; `scp' could have copied correctly, but set modes could have failed.
3213 ;; This can be ignored.
3214 (with-current-buffer (process-buffer proc)
3215 (goto-char (point-min))
3216 (if (re-search-forward tramp-operation-not-permitted-regexp nil t)
3217 (progn
3218 (tramp-message vec 5 "'set mode' error ignored.")
3219 (tramp-message vec 3 "Process has finished.")
3220 (throw 'tramp-action 'ok))
3221 (tramp-message vec 3 "Process has died.")
3222 (throw 'tramp-action 'process-died))))
3223 (t nil)))
3224
3225 ;;; Functions for processing the actions:
3226
3227 (defun tramp-process-one-action (proc vec actions)
3228 "Wait for output from the shell and perform one action."
3229 (let (found todo item pattern action)
3230 (while (not found)
3231 ;; Reread output once all actions have been performed.
3232 ;; Obviously, the output was not complete.
3233 (tramp-accept-process-output proc 1)
3234 (setq todo actions)
3235 (while todo
3236 (setq item (pop todo))
3237 (setq pattern (format "\\(%s\\)\\'" (symbol-value (nth 0 item))))
3238 (setq action (nth 1 item))
3239 (tramp-message
3240 vec 5 "Looking for regexp \"%s\" from remote shell" pattern)
3241 (when (tramp-check-for-regexp proc pattern)
3242 (tramp-message vec 5 "Call `%s'" (symbol-name action))
3243 (setq found (funcall action proc vec)))))
3244 found))
3245
3246 (defun tramp-process-actions (proc vec pos actions &optional timeout)
3247 "Perform ACTIONS until success or TIMEOUT.
3248 PROC and VEC indicate the remote connection to be used. POS, if
3249 set, is the starting point of the region to be deleted in the
3250 connection buffer."
3251 ;; Preserve message for `progress-reporter'.
3252 (tramp-compat-with-temp-message ""
3253 ;; Enable `auth-source' and `password-cache'. We must use
3254 ;; tramp-current-* variables in case we have several hops.
3255 (tramp-set-connection-property
3256 (tramp-dissect-file-name
3257 (tramp-make-tramp-file-name
3258 tramp-current-method tramp-current-user tramp-current-host ""))
3259 "first-password-request" t)
3260 (save-restriction
3261 (let (exit)
3262 (while (not exit)
3263 (tramp-message proc 3 "Waiting for prompts from remote shell")
3264 (setq exit
3265 (catch 'tramp-action
3266 (if timeout
3267 (with-timeout (timeout)
3268 (tramp-process-one-action proc vec actions))
3269 (tramp-process-one-action proc vec actions)))))
3270 (with-current-buffer (tramp-get-connection-buffer vec)
3271 (widen)
3272 (tramp-message vec 6 "\n%s" (buffer-string)))
3273 (unless (eq exit 'ok)
3274 (tramp-clear-passwd vec)
3275 (tramp-error-with-buffer
3276 nil vec 'file-error
3277 (cond
3278 ((eq exit 'permission-denied) "Permission denied")
3279 ((eq exit 'process-died) "Process died")
3280 (t "Login failed"))))
3281 (when (numberp pos)
3282 (with-current-buffer (tramp-get-connection-buffer vec)
3283 (let (buffer-read-only) (delete-region pos (point)))))))))
3284
3285 :;; Utility functions:
3286
3287 (defun tramp-accept-process-output (&optional proc timeout timeout-msecs)
3288 "Like `accept-process-output' for Tramp processes.
3289 This is needed in order to hide `last-coding-system-used', which is set
3290 for process communication also."
3291 (with-current-buffer (process-buffer proc)
3292 (tramp-message proc 10 "%s %s" proc (process-status proc))
3293 (let (buffer-read-only last-coding-system-used)
3294 ;; Under Windows XP, accept-process-output doesn't return
3295 ;; sometimes. So we add an additional timeout.
3296 (with-timeout ((or timeout 1))
3297 (if (featurep 'xemacs)
3298 (accept-process-output proc timeout timeout-msecs)
3299 (accept-process-output proc timeout timeout-msecs (and proc t)))))
3300 (tramp-message proc 10 "\n%s" (buffer-string))))
3301
3302 (defun tramp-check-for-regexp (proc regexp)
3303 "Check, whether REGEXP is contained in process buffer of PROC.
3304 Erase echoed commands if exists."
3305 (with-current-buffer (process-buffer proc)
3306 (goto-char (point-min))
3307
3308 ;; Check whether we need to remove echo output.
3309 (when (and (tramp-get-connection-property proc "check-remote-echo" nil)
3310 (re-search-forward tramp-echoed-echo-mark-regexp nil t))
3311 (let ((begin (match-beginning 0)))
3312 (when (re-search-forward tramp-echoed-echo-mark-regexp nil t)
3313 ;; Discard echo from remote output.
3314 (tramp-set-connection-property proc "check-remote-echo" nil)
3315 (tramp-message proc 5 "echo-mark found")
3316 (forward-line 1)
3317 (delete-region begin (point))
3318 (goto-char (point-min)))))
3319
3320 (when (or (not (tramp-get-connection-property proc "check-remote-echo" nil))
3321 ;; Sometimes, the echo string is suppressed on the remote side.
3322 (not (string-equal
3323 (tramp-compat-funcall
3324 'substring-no-properties tramp-echo-mark-marker
3325 0 (min tramp-echo-mark-marker-length (1- (point-max))))
3326 (tramp-compat-funcall
3327 'buffer-substring-no-properties
3328 1 (min (1+ tramp-echo-mark-marker-length) (point-max))))))
3329 ;; No echo to be handled, now we can look for the regexp.
3330 ;; Sometimes, lines are much to long, and we run into a "Stack
3331 ;; overflow in regexp matcher". For example, //DIRED// lines of
3332 ;; directory listings with some thousand files. Therefore, we
3333 ;; look from the end.
3334 (goto-char (point-max))
3335 (ignore-errors (re-search-backward regexp nil t)))))
3336
3337 (defun tramp-wait-for-regexp (proc timeout regexp)
3338 "Wait for a REGEXP to appear from process PROC within TIMEOUT seconds.
3339 Expects the output of PROC to be sent to the current buffer. Returns
3340 the string that matched, or nil. Waits indefinitely if TIMEOUT is
3341 nil."
3342 (with-current-buffer (process-buffer proc)
3343 (let ((found (tramp-check-for-regexp proc regexp))
3344 (start-time (current-time)))
3345 (cond (timeout
3346 ;; Work around a bug in XEmacs 21, where the timeout
3347 ;; expires faster than it should. This degenerates
3348 ;; to polling for buggy XEmacsen, but oh, well.
3349 (while (and (not found)
3350 (< (tramp-time-diff (current-time) start-time)
3351 timeout))
3352 (with-timeout (timeout)
3353 (while (not found)
3354 (tramp-accept-process-output proc 1)
3355 (unless (memq (process-status proc) '(run open))
3356 (tramp-error-with-buffer
3357 nil proc 'file-error "Process has died"))
3358 (setq found (tramp-check-for-regexp proc regexp))))))
3359 (t
3360 (while (not found)
3361 (tramp-accept-process-output proc 1)
3362 (unless (memq (process-status proc) '(run open))
3363 (tramp-error-with-buffer
3364 nil proc 'file-error "Process has died"))
3365 (setq found (tramp-check-for-regexp proc regexp)))))
3366 (tramp-message proc 6 "\n%s" (buffer-string))
3367 (when (not found)
3368 (if timeout
3369 (tramp-error
3370 proc 'file-error "[[Regexp `%s' not found in %d secs]]"
3371 regexp timeout)
3372 (tramp-error proc 'file-error "[[Regexp `%s' not found]]" regexp)))
3373 found)))
3374
3375 ;; It seems that Tru64 Unix does not like it if long strings are sent
3376 ;; to it in one go. (This happens when sending the Perl
3377 ;; `file-attributes' implementation, for instance.) Therefore, we
3378 ;; have this function which sends the string in chunks.
3379 (defun tramp-send-string (vec string)
3380 "Send the STRING via connection VEC.
3381
3382 The STRING is expected to use Unix line-endings, but the lines sent to
3383 the remote host use line-endings as defined in the variable
3384 `tramp-rsh-end-of-line'. The communication buffer is erased before sending."
3385 (let* ((p (tramp-get-connection-process vec))
3386 (chunksize (tramp-get-connection-property p "chunksize" nil)))
3387 (unless p
3388 (tramp-error
3389 vec 'file-error "Can't send string to remote host -- not logged in"))
3390 (tramp-set-connection-property p "last-cmd-time" (current-time))
3391 (tramp-message vec 10 "%s" string)
3392 (with-current-buffer (tramp-get-connection-buffer vec)
3393 ;; Clean up the buffer. We cannot call `erase-buffer' because
3394 ;; narrowing might be in effect.
3395 (let (buffer-read-only) (delete-region (point-min) (point-max)))
3396 ;; Replace "\n" by `tramp-rsh-end-of-line'.
3397 (setq string
3398 (mapconcat 'identity
3399 (tramp-compat-split-string string "\n")
3400 tramp-rsh-end-of-line))
3401 (unless (or (string= string "")
3402 (string-equal (substring string -1) tramp-rsh-end-of-line))
3403 (setq string (concat string tramp-rsh-end-of-line)))
3404 ;; Send the string.
3405 (if (and chunksize (not (zerop chunksize)))
3406 (let ((pos 0)
3407 (end (length string)))
3408 (while (< pos end)
3409 (tramp-message
3410 vec 10 "Sending chunk from %s to %s"
3411 pos (min (+ pos chunksize) end))
3412 (process-send-string
3413 p (substring string pos (min (+ pos chunksize) end)))
3414 (setq pos (+ pos chunksize))))
3415 (process-send-string p string)))))
3416
3417 (defun tramp-get-inode (vec)
3418 "Returns the virtual inode number.
3419 If it doesn't exist, generate a new one."
3420 (with-file-property vec (tramp-file-name-localname vec) "inode"
3421 (setq tramp-inodes (1+ tramp-inodes))))
3422
3423 (defun tramp-get-device (vec)
3424 "Returns the virtual device number.
3425 If it doesn't exist, generate a new one."
3426 (with-connection-property (tramp-get-connection-process vec) "device"
3427 (cons -1 (setq tramp-devices (1+ tramp-devices)))))
3428
3429 (defun tramp-equal-remote (file1 file2)
3430 "Check, whether the remote parts of FILE1 and FILE2 are identical.
3431 The check depends on method, user and host name of the files. If
3432 one of the components is missing, the default values are used.
3433 The local file name parts of FILE1 and FILE2 are not taken into
3434 account.
3435
3436 Example:
3437
3438 (tramp-equal-remote \"/ssh::/etc\" \"/<your host name>:/home\")
3439
3440 would yield `t'. On the other hand, the following check results in nil:
3441
3442 (tramp-equal-remote \"/sudo::/etc\" \"/su::/etc\")"
3443 (and (stringp (file-remote-p file1))
3444 (stringp (file-remote-p file2))
3445 (string-equal (file-remote-p file1) (file-remote-p file2))))
3446
3447 ;;;###tramp-autoload
3448 (defun tramp-mode-string-to-int (mode-string)
3449 "Converts a ten-letter `drwxrwxrwx'-style mode string into mode bits."
3450 (let* (case-fold-search
3451 (mode-chars (string-to-vector mode-string))
3452 (owner-read (aref mode-chars 1))
3453 (owner-write (aref mode-chars 2))
3454 (owner-execute-or-setid (aref mode-chars 3))
3455 (group-read (aref mode-chars 4))
3456 (group-write (aref mode-chars 5))
3457 (group-execute-or-setid (aref mode-chars 6))
3458 (other-read (aref mode-chars 7))
3459 (other-write (aref mode-chars 8))
3460 (other-execute-or-sticky (aref mode-chars 9)))
3461 (save-match-data
3462 (logior
3463 (cond
3464 ((char-equal owner-read ?r) (tramp-compat-octal-to-decimal "00400"))
3465 ((char-equal owner-read ?-) 0)
3466 (t (error "Second char `%c' must be one of `r-'" owner-read)))
3467 (cond
3468 ((char-equal owner-write ?w) (tramp-compat-octal-to-decimal "00200"))
3469 ((char-equal owner-write ?-) 0)
3470 (t (error "Third char `%c' must be one of `w-'" owner-write)))
3471 (cond
3472 ((char-equal owner-execute-or-setid ?x)
3473 (tramp-compat-octal-to-decimal "00100"))
3474 ((char-equal owner-execute-or-setid ?S)
3475 (tramp-compat-octal-to-decimal "04000"))
3476 ((char-equal owner-execute-or-setid ?s)
3477 (tramp-compat-octal-to-decimal "04100"))
3478 ((char-equal owner-execute-or-setid ?-) 0)
3479 (t (error "Fourth char `%c' must be one of `xsS-'"
3480 owner-execute-or-setid)))
3481 (cond
3482 ((char-equal group-read ?r) (tramp-compat-octal-to-decimal "00040"))
3483 ((char-equal group-read ?-) 0)
3484 (t (error "Fifth char `%c' must be one of `r-'" group-read)))
3485 (cond
3486 ((char-equal group-write ?w) (tramp-compat-octal-to-decimal "00020"))
3487 ((char-equal group-write ?-) 0)
3488 (t (error "Sixth char `%c' must be one of `w-'" group-write)))
3489 (cond
3490 ((char-equal group-execute-or-setid ?x)
3491 (tramp-compat-octal-to-decimal "00010"))
3492 ((char-equal group-execute-or-setid ?S)
3493 (tramp-compat-octal-to-decimal "02000"))
3494 ((char-equal group-execute-or-setid ?s)
3495 (tramp-compat-octal-to-decimal "02010"))
3496 ((char-equal group-execute-or-setid ?-) 0)
3497 (t (error "Seventh char `%c' must be one of `xsS-'"
3498 group-execute-or-setid)))
3499 (cond
3500 ((char-equal other-read ?r)
3501 (tramp-compat-octal-to-decimal "00004"))
3502 ((char-equal other-read ?-) 0)
3503 (t (error "Eighth char `%c' must be one of `r-'" other-read)))
3504 (cond
3505 ((char-equal other-write ?w) (tramp-compat-octal-to-decimal "00002"))
3506 ((char-equal other-write ?-) 0)
3507 (t (error "Ninth char `%c' must be one of `w-'" other-write)))
3508 (cond
3509 ((char-equal other-execute-or-sticky ?x)
3510 (tramp-compat-octal-to-decimal "00001"))
3511 ((char-equal other-execute-or-sticky ?T)
3512 (tramp-compat-octal-to-decimal "01000"))
3513 ((char-equal other-execute-or-sticky ?t)
3514 (tramp-compat-octal-to-decimal "01001"))
3515 ((char-equal other-execute-or-sticky ?-) 0)
3516 (t (error "Tenth char `%c' must be one of `xtT-'"
3517 other-execute-or-sticky)))))))
3518
3519 ;;;###tramp-autoload
3520 (defun tramp-local-host-p (vec)
3521 "Return t if this points to the local host, nil otherwise."
3522 ;; We cannot use `tramp-file-name-real-host'. A port is an
3523 ;; indication for an ssh tunnel or alike.
3524 (let ((host (tramp-file-name-host vec)))
3525 (and
3526 (stringp host)
3527 (string-match tramp-local-host-regexp host)
3528 ;; The method shall be applied to one of the shell file name
3529 ;; handler. `tramp-local-host-p' is also called for "smb" and
3530 ;; alike, where it must fail.
3531 (tramp-get-method-parameter
3532 (tramp-file-name-method vec) 'tramp-login-program)
3533 ;; The local temp directory must be writable for the other user.
3534 (file-writable-p
3535 (tramp-make-tramp-file-name
3536 (tramp-file-name-method vec)
3537 (tramp-file-name-user vec)
3538 host
3539 (tramp-compat-temporary-file-directory)))
3540 ;; On some systems, chown runs only for root.
3541 (or (zerop (user-uid))
3542 ;; This is defined in tramp-sh.el. Let's assume this is
3543 ;; loaded already.
3544 (zerop (tramp-compat-funcall 'tramp-get-remote-uid vec 'integer))))))
3545
3546 (defun tramp-get-remote-tmpdir (vec)
3547 "Return directory for temporary files on the remote host identified by VEC."
3548 (with-connection-property vec "tmpdir"
3549 (let ((dir (tramp-make-tramp-file-name
3550 (tramp-file-name-method vec)
3551 (tramp-file-name-user vec)
3552 (tramp-file-name-host vec)
3553 (or
3554 (tramp-get-method-parameter
3555 (tramp-file-name-method vec) 'tramp-tmpdir)
3556 "/tmp"))))
3557 (if (and (file-directory-p dir) (file-writable-p dir))
3558 dir
3559 (tramp-error vec 'file-error "Directory %s not accessible" dir)))))
3560
3561 ;;;###tramp-autoload
3562 (defun tramp-make-tramp-temp-file (vec)
3563 "Create a temporary file on the remote host identified by VEC.
3564 Return the local name of the temporary file."
3565 (let ((prefix (expand-file-name
3566 tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))
3567 result)
3568 (while (not result)
3569 ;; `make-temp-file' would be the natural choice for
3570 ;; implementation. But it calls `write-region' internally,
3571 ;; which also needs a temporary file - we would end in an
3572 ;; infinite loop.
3573 (setq result (make-temp-name prefix))
3574 (if (file-exists-p result)
3575 (setq result nil)
3576 ;; This creates the file by side effect.
3577 (set-file-times result)
3578 (set-file-modes result (tramp-compat-octal-to-decimal "0700"))))
3579
3580 ;; Return the local part.
3581 (with-parsed-tramp-file-name result nil localname)))
3582
3583 (defun tramp-delete-temp-file-function ()
3584 "Remove temporary files related to current buffer."
3585 (when (stringp tramp-temp-buffer-file-name)
3586 (ignore-errors (delete-file tramp-temp-buffer-file-name))))
3587
3588 (add-hook 'kill-buffer-hook 'tramp-delete-temp-file-function)
3589 (add-hook 'tramp-unload-hook
3590 (lambda ()
3591 (remove-hook 'kill-buffer-hook
3592 'tramp-delete-temp-file-function)))
3593
3594 ;;; Auto saving to a special directory:
3595
3596 (unless (tramp-exists-file-name-handler 'make-auto-save-file-name)
3597 (defadvice make-auto-save-file-name
3598 (around tramp-advice-make-auto-save-file-name () activate)
3599 "Invoke `tramp-*-handle-make-auto-save-file-name' for Tramp files."
3600 (if (tramp-tramp-file-p (buffer-file-name))
3601 ;; We cannot call `tramp-handle-make-auto-save-file-name'
3602 ;; directly, because this would bypass the locking mechanism.
3603 (setq ad-return-value
3604 (tramp-file-name-handler 'make-auto-save-file-name))
3605 ad-do-it))
3606 (add-hook
3607 'tramp-unload-hook
3608 (lambda ()
3609 (ad-remove-advice
3610 'make-auto-save-file-name
3611 'around 'tramp-advice-make-auto-save-file-name)
3612 (ad-activate 'make-auto-save-file-name))))
3613
3614 ;; In XEmacs < 21.5, autosaved remote files have permission 0666 minus
3615 ;; umask. This is a security threat.
3616
3617 (defun tramp-set-auto-save-file-modes ()
3618 "Set permissions of autosaved remote files to the original permissions."
3619 (let ((bfn (buffer-file-name)))
3620 (when (and (tramp-tramp-file-p bfn)
3621 (buffer-modified-p)
3622 (stringp buffer-auto-save-file-name)
3623 (not (equal bfn buffer-auto-save-file-name)))
3624 (unless (file-exists-p buffer-auto-save-file-name)
3625 (write-region "" nil buffer-auto-save-file-name))
3626 ;; Permissions should be set always, because there might be an old
3627 ;; auto-saved file belonging to another original file. This could
3628 ;; be a security threat.
3629 (set-file-modes
3630 buffer-auto-save-file-name
3631 (or (file-modes bfn) (tramp-compat-octal-to-decimal "0600"))))))
3632
3633 (unless (and (featurep 'xemacs)
3634 (= emacs-major-version 21)
3635 (> emacs-minor-version 4))
3636 (add-hook 'auto-save-hook 'tramp-set-auto-save-file-modes)
3637 (add-hook 'tramp-unload-hook
3638 (lambda ()
3639 (remove-hook 'auto-save-hook 'tramp-set-auto-save-file-modes))))
3640
3641 (defun tramp-subst-strs-in-string (alist string)
3642 "Replace all occurrences of the string FROM with TO in STRING.
3643 ALIST is of the form ((FROM . TO) ...)."
3644 (save-match-data
3645 (while alist
3646 (let* ((pr (car alist))
3647 (from (car pr))
3648 (to (cdr pr)))
3649 (while (string-match (regexp-quote from) string)
3650 (setq string (replace-match to t t string)))
3651 (setq alist (cdr alist))))
3652 string))
3653
3654 ;;; Compatibility functions section:
3655
3656 ;;;###tramp-autoload
3657 (defun tramp-read-passwd (proc &optional prompt)
3658 "Read a password from user (compat function).
3659 Consults the auth-source package.
3660 Invokes `password-read' if available, `read-passwd' else."
3661 (let* ((key (tramp-make-tramp-file-name
3662 tramp-current-method tramp-current-user
3663 tramp-current-host ""))
3664 (pw-prompt
3665 (or prompt
3666 (with-current-buffer (process-buffer proc)
3667 (tramp-check-for-regexp proc tramp-password-prompt-regexp)
3668 (format "%s for %s " (capitalize (match-string 1)) key))))
3669 auth-info auth-passwd)
3670 (with-parsed-tramp-file-name key nil
3671 (prog1
3672 (or
3673 ;; See if auth-sources contains something useful, if it's
3674 ;; bound. `auth-source-user-or-password' is an obsoleted
3675 ;; function, it has been replaced by `auth-source-search'.
3676 (and (boundp 'auth-sources)
3677 (tramp-get-connection-property v "first-password-request" nil)
3678 ;; Try with Tramp's current method.
3679 (if (fboundp 'auth-source-search)
3680 (setq auth-info
3681 (tramp-compat-funcall
3682 'auth-source-search
3683 :max 1
3684 :user (or tramp-current-user t)
3685 :host tramp-current-host
3686 :port tramp-current-method)
3687 auth-passwd (plist-get (nth 0 auth-info) :secret)
3688 auth-passwd (if (functionp auth-passwd)
3689 (funcall auth-passwd)
3690 auth-passwd))
3691 (tramp-compat-funcall
3692 'auth-source-user-or-password
3693 "password" tramp-current-host tramp-current-method)))
3694 ;; Try the password cache.
3695 (when (functionp 'password-read)
3696 (unless (tramp-get-connection-property
3697 v "first-password-request" nil)
3698 (tramp-compat-funcall 'password-cache-remove key))
3699 (let ((password
3700 (tramp-compat-funcall 'password-read pw-prompt key)))
3701 (tramp-compat-funcall 'password-cache-add key password)
3702 password))
3703 ;; Else, get the password interactively.
3704 (read-passwd pw-prompt))
3705 (tramp-set-connection-property v "first-password-request" nil)))))
3706
3707 ;;;###tramp-autoload
3708 (defun tramp-clear-passwd (vec)
3709 "Clear password cache for connection related to VEC."
3710 (tramp-compat-funcall
3711 'password-cache-remove
3712 (tramp-make-tramp-file-name
3713 (tramp-file-name-method vec)
3714 (tramp-file-name-user vec)
3715 (tramp-file-name-host vec)
3716 "")))
3717
3718 ;; Snarfed code from time-date.el and parse-time.el
3719
3720 (defconst tramp-half-a-year '(241 17024)
3721 "Evaluated by \"(days-to-time 183)\".")
3722
3723 (defconst tramp-parse-time-months
3724 '(("jan" . 1) ("feb" . 2) ("mar" . 3)
3725 ("apr" . 4) ("may" . 5) ("jun" . 6)
3726 ("jul" . 7) ("aug" . 8) ("sep" . 9)
3727 ("oct" . 10) ("nov" . 11) ("dec" . 12))
3728 "Alist mapping month names to integers.")
3729
3730 ;;;###tramp-autoload
3731 (defun tramp-time-less-p (t1 t2)
3732 "Say whether time value T1 is less than time value T2."
3733 (unless t1 (setq t1 '(0 0)))
3734 (unless t2 (setq t2 '(0 0)))
3735 (or (< (car t1) (car t2))
3736 (and (= (car t1) (car t2))
3737 (< (nth 1 t1) (nth 1 t2)))))
3738
3739 (defun tramp-time-subtract (t1 t2)
3740 "Subtract two time values.
3741 Return the difference in the format of a time value."
3742 (unless t1 (setq t1 '(0 0)))
3743 (unless t2 (setq t2 '(0 0)))
3744 (let ((borrow (< (cadr t1) (cadr t2))))
3745 (list (- (car t1) (car t2) (if borrow 1 0))
3746 (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2)))))
3747
3748 ;;;###tramp-autoload
3749 (defun tramp-time-diff (t1 t2)
3750 "Return the difference between the two times, in seconds.
3751 T1 and T2 are time values (as returned by `current-time' for example)."
3752 (cond ((and (fboundp 'subtract-time)
3753 (fboundp 'float-time))
3754 (tramp-compat-funcall
3755 'float-time (tramp-compat-funcall 'subtract-time t1 t2)))
3756 ((and (fboundp 'subtract-time)
3757 (fboundp 'time-to-seconds))
3758 (tramp-compat-funcall
3759 'time-to-seconds (tramp-compat-funcall 'subtract-time t1 t2)))
3760 ((fboundp 'itimer-time-difference)
3761 (tramp-compat-funcall
3762 'itimer-time-difference
3763 (if (< (length t1) 3) (append t1 '(0)) t1)
3764 (if (< (length t2) 3) (append t2 '(0)) t2)))
3765 (t
3766 (let ((time (tramp-time-subtract t1 t2)))
3767 (+ (* (car time) 65536.0)
3768 (cadr time)
3769 (/ (or (nth 2 time) 0) 1000000.0))))))
3770
3771 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
3772 ;; does not deal well with newline characters. Newline is replaced by
3773 ;; backslash newline. But if, say, the string `a backslash newline b'
3774 ;; is passed to a shell, the shell will expand this into "ab",
3775 ;; completely omitting the newline. This is not what was intended.
3776 ;; It does not appear to be possible to make the function
3777 ;; `shell-quote-argument' work with newlines without making it
3778 ;; dependent on the shell used. But within this package, we know that
3779 ;; we will always use a Bourne-like shell, so we use an approach which
3780 ;; groks newlines.
3781 ;;
3782 ;; The approach is simple: we call `shell-quote-argument', then
3783 ;; massage the newline part of the result.
3784 ;;
3785 ;; This function should produce a string which is grokked by a Unix
3786 ;; shell, even if the Emacs is running on Windows. Since this is the
3787 ;; kludges section, we bind `system-type' in such a way that
3788 ;; `shell-quote-arguments' behaves as if on Unix.
3789 ;;
3790 ;; Thanks to Mario DeWeerd for the hint that it is sufficient for this
3791 ;; function to work with Bourne-like shells.
3792 ;;
3793 ;; CCC: This function should be rewritten so that
3794 ;; `shell-quote-argument' is not used. This way, we are safe from
3795 ;; changes in `shell-quote-argument'.
3796 ;;;###tramp-autoload
3797 (defun tramp-shell-quote-argument (s)
3798 "Similar to `shell-quote-argument', but groks newlines.
3799 Only works for Bourne-like shells."
3800 (let ((system-type 'not-windows))
3801 (save-match-data
3802 (let ((result (shell-quote-argument s))
3803 (nl (regexp-quote (format "\\%s" tramp-rsh-end-of-line))))
3804 (when (and (>= (length result) 2)
3805 (string= (substring result 0 2) "\\~"))
3806 (setq result (substring result 1)))
3807 (while (string-match nl result)
3808 (setq result (replace-match (format "'%s'" tramp-rsh-end-of-line)
3809 t t result)))
3810 result))))
3811
3812 ;; Checklist for `tramp-unload-hook'
3813 ;; - Unload all `tramp-*' packages
3814 ;; - Reset `file-name-handler-alist'
3815 ;; - Cleanup hooks where Tramp functions are in
3816 ;; - Cleanup advised functions
3817 ;; - Cleanup autoloads
3818 ;;;###autoload
3819 (defun tramp-unload-tramp ()
3820 "Discard Tramp from loading remote files."
3821 (interactive)
3822 ;; ange-ftp settings must be enabled.
3823 (tramp-compat-funcall 'tramp-ftp-enable-ange-ftp)
3824 ;; Maybe it's not loaded yet.
3825 (ignore-errors (unload-feature 'tramp 'force)))
3826
3827 (provide 'tramp)
3828
3829 ;;; TODO:
3830
3831 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
3832 ;; `shell-quote-argument'.
3833 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
3834 ;; by the files in that directory. Add this here.
3835 ;; * Avoid screen blanking when hitting `g' in dired. (Eli Tziperman)
3836 ;; * Make ffap.el grok Tramp filenames. (Eli Tziperman)
3837 ;; * abbreviate-file-name
3838 ;; * Better error checking. At least whenever we see something
3839 ;; strange when doing zerop, we should kill the process and start
3840 ;; again. (Greg Stark)
3841 ;; * Username and hostname completion.
3842 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'.
3843 ;; * Make `tramp-default-user' obsolete.
3844 ;; * Implement a general server-local-variable mechanism, as there are
3845 ;; probably other variables that need different values for different
3846 ;; servers too. The user could then configure a variable (such as
3847 ;; tramp-server-local-variable-alist) to define any such variables
3848 ;; that they need to, which would then be let bound as appropriate
3849 ;; in tramp functions. (Jason Rumney)
3850 ;; * IMHO, it's a drawback that currently Tramp doesn't support
3851 ;; Unicode in Dired file names by default. Is it possible to
3852 ;; improve Tramp to set LC_ALL to "C" only for commands where Tramp
3853 ;; expects English? Or just to set LC_MESSAGES to "C" if Tramp
3854 ;; expects only English messages? (Juri Linkov)
3855 ;; * Make shadowfile.el grok Tramp filenames. (Bug#4526, Bug#4846)
3856 ;; * I was wondering if it would be possible to use tramp even if I'm
3857 ;; actually using sshfs. But when I launch a command I would like
3858 ;; to get it executed on the remote machine where the files really
3859 ;; are. (Andrea Crotti)
3860 ;; * Run emerge on two remote files. Bug is described here:
3861 ;; <http://www.mail-archive.com/tramp-devel@nongnu.org/msg01041.html>.
3862 ;; (Bug#6850)
3863
3864 ;;; tramp.el ends here
3865
3866 ;; Local Variables:
3867 ;; mode: Emacs-Lisp
3868 ;; coding: utf-8
3869 ;; End: