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