Change release version from 21.4 to 22.1 throughout.
[bpt/emacs.git] / lisp / net / tramp.el
index 864fe35..583b5fa 100644 (file)
@@ -1,8 +1,9 @@
-;;; tramp.el --- Transparent Remote Access, Multiple Protocol -*- coding: iso-8859-1; -*-
+;;; -*- mode: Emacs-Lisp; coding: iso-2022-7bit; -*-
+;;; tramp.el --- Transparent Remote Access, Multiple Protocol
 
-;; Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
-;; Author: Kai.Grossjohann@CS.Uni-Dortmund.DE 
+;; Author: kai.grossjohann@gmx.net
 ;; Keywords: comm, processes
 
 ;; This file is part of GNU Emacs.
 ;; the local and the remote host, whereas tramp.el uses a combination
 ;; of rsh and rcp or other work-alike programs, such as ssh/scp.
 ;;
-;; For more detailed instructions, please see the info file, which is
-;; included in the file `tramp.tar.gz' mentioned below.
+;; For more detailed instructions, please see the info file.
 ;;
 ;; Notes:
 ;; -----
-;; 
+;;
 ;; This package only works for Emacs 20 and higher, and for XEmacs 21
 ;; and higher.  (XEmacs 20 is missing the `with-timeout' macro.  Emacs
 ;; 19 is reported to have other problems.  For XEmacs 21, you need the
 ;;
 ;; Also see the todo list at the bottom of this file.
 ;;
-;; The current version of tramp.el can be retrieved from the following
-;; URL:  ftp://ls6-ftp.cs.uni-dortmund.de/pub/src/emacs/tramp.tar.gz
-;; For your convenience, the *.el file is available separately from
-;; the same directory.
+;; The current version of Tramp can be retrieved from the following URL:
+;;            http://savannah.nongnu.org/download/tramp/
 ;;
 ;; There's a mailing list for this, as well.  Its name is:
-;;                tramp-devel@mail.freesoftware.fsf.org
+;;            tramp-devel@mail.freesoftware.fsf.org
 ;; Send a mail with `help' in the subject (!) to the administration
 ;; address for instructions on joining the list.  The administration
 ;; address is:
 
 ;;; Code:
 
-;; In the Tramp CVS repository, the version numer is auto-frobbed from
-;; the Makefile, so you should edit the top-level Makefile to change
-;; the version number.
-(defconst tramp-version "2.0.28"
-  "This version of tramp.")
-
-(defconst tramp-bug-report-address "tramp-devel@mail.freesoftware.fsf.org"
-  "Email address to send bug reports to.")
+;; The Tramp version number and bug report address, as prepared by configure.
+(require 'trampver)
 
 (require 'timer)
 (require 'format-spec)                  ;from Gnus 5.8, also in tar ball
+;; As long as password.el is not part of (X)Emacs, it shouldn't
+;; be mandatory
+(if (featurep 'xemacs)
+    (load "password" 'noerror)
+  (require 'password nil 'noerror))     ;from No Gnus, also in tar ball
+
 ;; The explicit check is not necessary in Emacs, which provides the
 ;; feature even if implemented in C, but it appears to be necessary
 ;; in XEmacs.
 (unless (fboundp 'uudecode-decode-region)
   (autoload 'uudecode-decode-region "uudecode"))
 
-;; ;; It does not work to load EFS after loading TRAMP.  
-;; (when (fboundp 'efs-file-handler-function)
-;;   (require 'efs))
+;; XEmacs is distributed with few Lisp packages.  Further packages are
+;; installed using EFS.  If we use a unified filename format, then
+;; Tramp is required in addition to EFS.  (But why can't Tramp just
+;; disable EFS when Tramp is loaded?  Then XEmacs can ship with EFS
+;; just like before.)  Another reason for using a separate filename
+;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
+;; Tramp only knows how to deal with `file-name-handler-alist', not
+;; the other places.
+;;;###autoload
+(defvar tramp-unified-filenames (not (featurep 'xemacs))
+  "Non-nil means to use unified Ange-FTP/Tramp filename syntax.
+Nil means to use a separate filename syntax for Tramp.")
 
 ;; Load foreign methods.  Because they do require Tramp internally, this
 ;; must be done with the `eval-after-load' trick.
 (unless (featurep 'xemacs)
   (eval-after-load "tramp"
     '(require 'tramp-ftp)))
+(when (and tramp-unified-filenames (featurep 'xemacs))
+  (eval-after-load "tramp"
+    '(require 'tramp-efs)))
 
 ;; tramp-smb uses "smbclient" from Samba.
 ;; Not available under Cygwin and Windows, because they don't offer
 ;; "smbclient".  And even not necessary there, because Emacs supports
-;; UNC file names like "//host/share/path".
+;; UNC file names like "//host/share/localname".
 (unless (memq system-type '(cygwin windows-nt))
   (eval-after-load "tramp"
     '(require 'tramp-smb)))
 (unless (boundp 'custom-print-functions)
   (defvar custom-print-functions nil)) ; not autoloaded before Emacs 20.4
 
-;; XEmacs is distributed with few Lisp packages.  Further packages are
-;; installed using EFS.  If we use a unified filename format, then
-;; Tramp is required in addition to EFS.  (But why can't Tramp just
-;; disable EFS when Tramp is loaded?  Then XEmacs can ship with EFS
-;; just like before.)  Another reason for using a separate filename
-;; syntax on XEmacs is that EFS hooks into XEmacs in many places, but
-;; Tramp only knows how to deal with `file-name-handler-alist', not
-;; the other places.
-;;;###autoload
-(defvar tramp-unified-filenames (not (featurep 'xemacs))
-  "Non-nil means to use unified Ange-FTP/Tramp filename syntax.
-Nil means to use a separate filename syntax for Tramp.")
+;; Avoid byte-compiler warnings if the byte-compiler supports this.
+;; Currently, XEmacs supports this.
+(eval-when-compile
+  (when (fboundp 'byte-compiler-options)
+    (let (unused-vars) ; Pacify Emacs byte-compiler
+      (defalias 'warnings 'identity) ; Pacify Emacs byte-compiler
+      (byte-compiler-options (warnings (- unused-vars))))))
+
+;; `directory-sep-char' is an obsolete variable in Emacs.  But it is
+;; used in XEmacs, so we set it here and there.  The following is needed
+;; to pacify Emacs byte-compiler.
+(eval-when-compile
+  (when (boundp 'byte-compile-not-obsolete-var)
+    (setq byte-compile-not-obsolete-var 'directory-sep-char)))
+
+;; XEmacs byte-compiler raises warning abouts `last-coding-system-used'.
+(eval-when-compile
+  (unless (boundp 'last-coding-system-used)
+    (defvar last-coding-system-used nil)))
 
 ;;; User Customizable Internal Variables:
 
 (defgroup tramp nil
   "Edit remote files with a combination of rsh and rcp or similar programs."
-  :group 'files)
+  :group 'files
+  :version "22.1")
 
 (defcustom tramp-verbose 9
   "*Verbosity level for tramp.el.  0 means be silent, 10 is most verbose."
@@ -154,6 +172,49 @@ Nil means to use a separate filename syntax for Tramp.")
   :group 'tramp
   :type 'boolean)
 
+;; Emacs case
+(eval-and-compile
+  (when (boundp 'backup-directory-alist)
+    (defcustom tramp-backup-directory-alist nil
+      "Alist of filename patterns and backup directory names.
+Each element looks like (REGEXP . DIRECTORY), with the same meaning like
+in `backup-directory-alist'.  If a Tramp file is backed up, and DIRECTORY
+is a local file name, the backup directory is prepended with Tramp file
+name prefix \(multi-method, method, user, host\) of file.
+
+\(setq tramp-backup-directory-alist backup-directory-alist\)
+
+gives the same backup policy for Tramp files on their hosts like the
+policy for local files."
+      :group 'tramp
+      :type '(repeat (cons (regexp :tag "Regexp matching filename")
+                          (directory :tag "Backup directory name"))))))
+
+;; XEmacs case.  We cannot check for `bkup-backup-directory-info', because
+;; the package "backup-dir" might not be loaded yet.
+(eval-and-compile
+  (when (featurep 'xemacs)
+    (defcustom tramp-bkup-backup-directory-info nil
+      "*Alist of (FILE-REGEXP BACKUP-DIR OPTIONS ...))
+It has the same meaning like `bkup-backup-directory-info' from package
+`backup-dir'.  If a Tramp file is backed up, and BACKUP-DIR is a local
+file name, the backup directory is prepended with Tramp file name prefix
+\(multi-method, method, user, host\) of file.
+
+\(setq tramp-bkup-backup-directory-info bkup-backup-directory-info\)
+
+gives the same backup policy for Tramp files on their hosts like the
+policy for local files."
+      :type '(repeat
+             (list (regexp :tag "File regexp")
+                   (string :tag "Backup Dir")
+                   (set :inline t
+                        (const ok-create)
+                        (const full-path)
+                        (const prepend-name)
+                        (const search-upward))))
+      :group 'tramp)))
+
 (defcustom tramp-auto-save-directory nil
   "*Put auto-save files in this directory, if set.
 The idea is to use a local directory so that auto-saving is faster."
@@ -236,265 +297,224 @@ This variable defaults to the value of `tramp-encoding-shell'."
 
 (defcustom tramp-methods
   '( ("rcp"   (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "rsh")
-              (tramp-rcp-program          "rcp")
+              (tramp-login-program        "rsh")
+              (tramp-copy-program         "rcp")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             nil)
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           nil)
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("scp"   (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          "scp")
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         "scp")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("scp1"  (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          "scp")
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         "scp")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-1" "-e" "none"))
-              (tramp-rcp-args             ("-1"))
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-1" "-e" "none"))
+              (tramp-copy-args            ("-1"))
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("scp2"  (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          "scp")
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         "scp")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-2" "-e" "none"))
-              (tramp-rcp-args             ("-2"))
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-2" "-e" "none"))
+              (tramp-copy-args            ("-2"))
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("scp1_old"
               (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh1")
-              (tramp-rcp-program          "scp1")
+              (tramp-login-program        "ssh1")
+              (tramp-copy-program         "scp1")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("scp2_old"
               (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh2")
-              (tramp-rcp-program          "scp2")
+              (tramp-login-program        "ssh2")
+              (tramp-copy-program         "scp2")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("rsync" (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          "rsync")
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         "rsync")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             ("-e" "ssh"))
-              (tramp-rcp-keep-date-arg    "-t")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            ("-e" "ssh"))
+              (tramp-copy-keep-date-arg   "-t")
+             (tramp-password-end-of-line nil))
+     ("remcp" (tramp-connection-function  tramp-open-connection-rsh)
+              (tramp-login-program        "remsh")
+              (tramp-copy-program         "rcp")
+              (tramp-remote-sh            "/bin/sh")
+              (tramp-login-args           nil)
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("rsh"   (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "rsh")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "rsh")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             nil)
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           nil)
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("ssh"   (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("ssh1"  (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-1" "-e" "none"))
-              (tramp-rcp-args             ("-1"))
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-1" "-e" "none"))
+              (tramp-copy-args            ("-1"))
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("ssh2"  (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-2" "-e" "none"))
-              (tramp-rcp-args             ("-2"))
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-2" "-e" "none"))
+              (tramp-copy-args            ("-2"))
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("ssh1_old"
               (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh1")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "ssh1")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("ssh2_old"
               (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh2")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "ssh2")
+              (tramp-copy-program         nil)
+              (tramp-remote-sh            "/bin/sh")
+              (tramp-login-args           ("-e" "none"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
+     ("remsh" (tramp-connection-function  tramp-open-connection-rsh)
+              (tramp-login-program        "remsh")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           nil)
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("telnet"
               (tramp-connection-function  tramp-open-connection-telnet)
-              (tramp-rsh-program          nil)
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "telnet")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             nil)
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       "telnet")
-              (tramp-telnet-args          nil))
+              (tramp-login-args           nil)
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("su"    (tramp-connection-function  tramp-open-connection-su)
-              (tramp-rsh-program          nil)
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "su")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             nil)
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           "su")
-              (tramp-su-args              ("-" "%u"))
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-" "%u"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("sudo"  (tramp-connection-function  tramp-open-connection-su)
-              (tramp-rsh-program          nil)
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "sudo")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             nil)
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           "sudo")
-              (tramp-su-args              ("-u" "%u" "-s"))
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-u" "%u" "-s"
+                                          "-p" "Password:"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("multi" (tramp-connection-function  tramp-open-connection-multi)
-              (tramp-rsh-program          nil)
-              (tramp-rcp-program          nil)
+              (tramp-login-program        nil)
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             nil)
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           nil)
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("scpx"  (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          "scp")
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         "scp")
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none" "-t" "-t" "/bin/sh"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none" "-t" "-t" "/bin/sh"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      ("sshx"  (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "ssh")
-              (tramp-rcp-program          nil)
+              (tramp-login-program        "ssh")
+              (tramp-copy-program         nil)
               (tramp-remote-sh            "/bin/sh")
-              (tramp-rsh-args             ("-e" "none" "-t" "-t" "/bin/sh"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    nil)
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("-e" "none" "-t" "-t" "/bin/sh"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("krlogin"
               (tramp-connection-function  tramp-open-connection-rsh)
-             (tramp-rsh-program          "krlogin")
-             (tramp-rcp-program          nil)
+             (tramp-login-program        "krlogin")
+             (tramp-copy-program         nil)
              (tramp-remote-sh            "/bin/sh")
-             (tramp-rsh-args             ("-x"))
-             (tramp-rcp-args             nil)
-             (tramp-rcp-keep-date-arg    nil)
-             (tramp-su-program           nil)
-             (tramp-su-args              nil)
-             (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+             (tramp-login-args           ("-x"))
+             (tramp-copy-args            nil)
+             (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line nil))
      ("plink"
               (tramp-connection-function  tramp-open-connection-rsh)
-             (tramp-rsh-program          "plink")
-             (tramp-rcp-program          nil)
+             (tramp-login-program        "plink")
+             (tramp-copy-program         nil)
+             (tramp-remote-sh            "/bin/sh")
+             (tramp-login-args           ("-ssh")) ;optionally add "-v"
+             (tramp-copy-args            nil)
+             (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line "xy")) ;see docstring for "xy"
+     ("plink1"
+              (tramp-connection-function  tramp-open-connection-rsh)
+             (tramp-login-program        "plink")
+             (tramp-copy-program         nil)
              (tramp-remote-sh            "/bin/sh")
-             (tramp-rsh-args             ("-ssh")) ;optionally add "-v"
-             (tramp-rcp-args             nil)
-             (tramp-rcp-keep-date-arg    nil)
-             (tramp-su-program           nil)
-             (tramp-su-args              nil)
-             (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+             (tramp-login-args           ("-1" "-ssh")) ;optionally add "-v"
+             (tramp-copy-args            nil)
+             (tramp-copy-keep-date-arg   nil)
+             (tramp-password-end-of-line "xy")) ;see docstring for "xy"
      ("pscp"
               (tramp-connection-function  tramp-open-connection-rsh)
-             (tramp-rsh-program          "plink")
-             (tramp-rcp-program          "pscp")
+             (tramp-login-program        "plink")
+             (tramp-copy-program         "pscp")
              (tramp-remote-sh            "/bin/sh")
-             (tramp-rsh-args             ("-ssh"))
-             (tramp-rcp-args             nil)
-             (tramp-rcp-keep-date-arg    "-p")
-             (tramp-su-program           nil)
-             (tramp-su-args              nil)
-             (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
-     ("fcp"   
+             (tramp-login-args           ("-ssh"))
+             (tramp-copy-args            nil)
+             (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line "xy")) ;see docstring for "xy"
+     ("fcp"
              (tramp-connection-function  tramp-open-connection-rsh)
-              (tramp-rsh-program          "fsh")
-              (tramp-rcp-program          "fcp")
+              (tramp-login-program        "fsh")
+              (tramp-copy-program         "fcp")
               (tramp-remote-sh            "/bin/sh -i")
-              (tramp-rsh-args             ("sh" "-i"))
-              (tramp-rcp-args             nil)
-              (tramp-rcp-keep-date-arg    "-p")
-              (tramp-su-program           nil)
-              (tramp-su-args              nil)
-              (tramp-telnet-program       nil)
-              (tramp-telnet-args          nil))
+              (tramp-login-args           ("sh" "-i"))
+              (tramp-copy-args            nil)
+              (tramp-copy-keep-date-arg   "-p")
+             (tramp-password-end-of-line nil))
      )
   "*Alist of methods for remote files.
 This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
@@ -512,57 +532,61 @@ pair of the form (KEY VALUE).  The following KEYs are defined:
     which groks tilde expansion, but it can search for it.  Also note
     that \"/bin/sh\" exists on all Unixen, this might not be true for
     the value that you decide to use.  You Have Been Warned.
-  * `tramp-rsh-program'
-    This specifies the name of the program to use for rsh; this might be
-    the full path to rsh or the name of a workalike program.
-  * `tramp-rsh-args'
+  * `tramp-login-program'
+    This specifies the name of the program to use for logging in to the
+    remote host.  Depending on `tramp-connection-function', this may be
+    the name of rsh or a workalike program (when
+    `tramp-connection-function' is `tramp-open-connection-rsh'), or the
+    name of telnet or a workalike (for `tramp-open-connection-telnet'),
+    or the name of su or a workalike (for `tramp-open-connection-su').
+  * `tramp-login-args'
     This specifies the list of arguments to pass to the above
     mentioned program.  Please note that this is a list of arguments,
     that is, normally you don't want to put \"-a -b\" or \"-f foo\"
     here.  Instead, you want two list elements, one for \"-a\" and one
     for \"-b\", or one for \"-f\" and one for \"foo\".
-  * `tramp-rcp-program'
-    This specifies the name of the program to use for rcp; this might be
-    the full path to rcp or the name of a workalike program.
-  * `tramp-rcp-args'
+    If `tramp-connection-function' is `tramp-open-connection-su', then
+    \"%u\" in this list is replaced by the user name, and \"%%\" can
+    be used to obtain a literal percent character.
+  * `tramp-copy-program'
+    This specifies the name of the program to use for remotely copying
+    the file; this might be the absolute filename of rcp or the name of
+    a workalike program.
+  * `tramp-copy-args'
     This specifies the list of parameters to pass to the above mentioned
-    program, the hints for `tramp-rsh-args' also apply here.
-  * `tramp-rcp-keep-date-arg'
-    This specifies the parameter to use for `rcp' when the timestamp
-    of the original file should be kept.  For `rcp', use `-p', for
+    program, the hints for `tramp-login-args' also apply here.
+  * `tramp-copy-keep-date-arg'
+    This specifies the parameter to use for the copying program when the
+    timestamp of the original file should be kept.  For `rcp', use `-p', for
     `rsync', use `-t'.
-  * `tramp-su-program'
-    This specifies the name of the program to use for `su'.
-  * `tramp-su-args'
-    This specifies the list of arguments to pass to `su'.
-    \"%u\" is replaced by the user name, use \"%%\" for a literal
-    percent character.
-  * `tramp-telnet-program'
-    Specifies the telnet program to use when using
-    `tramp-open-connection-telnet' to log in.
-  * `tramp-telnet-args'
-    Specifies list of arguments to pass to `telnet'.  The hints for
-    `tramp-rsh-args' also apply here.
-
-What does all this mean?  Well, you should specify `tramp-rsh-program',
-`tramp-telnet-program' or `tramp-su-program' for all methods; this program
-is used to log in to the remote site.  Then, there are two ways to
-actually transfer the files between the local and the remote side.
-One way is using an additional rcp-like program.  If you want to do
-this, set `tramp-rcp-program' in the method.
+  * `tramp-password-end-of-line'
+    This specifies the string to use for terminating the line after
+    submitting the password.  If this method parameter is nil, then the
+    value of the normal variable `tramp-default-password-end-of-line'
+    is used.  This parameter is necessary because the \"plink\" program
+    requires any two characters after sending the password.  These do
+    not have to be newline or carriage return characters.  Other login
+    programs are happy with just one character, the newline character.
+    We use \"xy\" as the value for methods using \"plink\".
+
+What does all this mean?  Well, you should specify `tramp-login-program'
+for all methods; this program is used to log in to the remote site.  Then,
+there are two ways to actually transfer the files between the local and the
+remote side.  One way is using an additional rcp-like program.  If you want
+to do this, set `tramp-copy-program' in the method.
 
 Another possibility for file transfer is inline transfer, i.e. the
-file is passed through the same buffer used by `tramp-rsh-program'.  In
+file is passed through the same buffer used by `tramp-login-program'.  In
 this case, the file contents need to be protected since the
-`tramp-rsh-program' might use escape codes or the connection might not
+`tramp-login-program' might use escape codes or the connection might not
 be eight-bit clean.  Therefore, file contents are encoded for transit.
 See the variable `tramp-coding-commands' for details.
 
 So, to summarize: if the method is an out-of-band method, then you
-must specify `tramp-rcp-program' and `tramp-rcp-args'.  If it is an
+must specify `tramp-copy-program' and `tramp-copy-args'.  If it is an
 inline method, then these two parameters should be nil.  Every method,
 inline or out of band, must specify `tramp-connection-function' plus
-the associated arguments (for example, the telnet program if you chose
+the associated arguments (for example, the login program if you chose
 `tramp-open-connection-telnet').
 
 Notes:
@@ -576,19 +600,16 @@ host other than `localhost' or the name of the local host."
   :type '(repeat
           (cons string
                 (set (list (const tramp-connection-function) function)
-                     (list (const tramp-rsh-program)
+                     (list (const tramp-login-program)
                           (choice (const nil) string))
-                     (list (const tramp-rcp-program)
+                     (list (const tramp-copy-program)
                           (choice (const nil) string))
                      (list (const tramp-remote-sh)
                           (choice (const nil) string))
-                     (list (const tramp-rsh-args) (repeat string))
-                     (list (const tramp-rcp-args) (repeat string))
-                     (list (const tramp-rcp-keep-date-arg)
-                          (choice (const nil) string))
-                     (list (const tramp-su-program)
+                     (list (const tramp-login-args) (repeat string))
+                     (list (const tramp-copy-args) (repeat string))
+                     (list (const tramp-copy-keep-date-arg)
                           (choice (const nil) string))
-                     (list (const tramp-su-args) (repeat string))
                      (list (const tramp-encoding-command)
                           (choice (const nil) string))
                      (list (const tramp-decoding-command)
@@ -597,9 +618,8 @@ host other than `localhost' or the name of the local host."
                           (choice (const nil) function))
                      (list (const tramp-decoding-function)
                           (choice (const nil) function))
-                     (list (const tramp-telnet-program)
-                          (choice (const nil) string))
-                     (list (const tramp-telnet-args) (repeat string))))))
+                    (list (const tramp-password-end-of-line)
+                          (choice (const nil) string))))))
 
 (defcustom tramp-multi-methods '("multi" "multiu")
   "*List of multi-hop methods.
@@ -611,9 +631,11 @@ variable `tramp-methods'."
 (defcustom tramp-multi-connection-function-alist
   '(("telnet" tramp-multi-connect-telnet "telnet %h%n")
     ("rsh"    tramp-multi-connect-rlogin "rsh %h -l %u%n")
+    ("remsh"  tramp-multi-connect-rlogin "remsh %h -l %u%n")
     ("ssh"    tramp-multi-connect-rlogin "ssh %h -l %u%n")
+    ("ssht"   tramp-multi-connect-rlogin "ssh %h -e none -t -t -l %u%n")
     ("su"     tramp-multi-connect-su     "su - %u%n")
-    ("sudo"   tramp-multi-connect-su     "sudo -u %u -s%n"))
+    ("sudo"   tramp-multi-connect-su     "sudo -u %u -s -p Password:%n"))
   "*List of connection functions for multi-hop methods.
 Each list item is a list of three items (METHOD FUNCTION COMMAND),
 where METHOD is the name as used in the file name, FUNCTION is the
@@ -631,7 +653,11 @@ various functions for details."
   :group 'tramp
   :type '(repeat (list string function string)))
 
-(defcustom tramp-default-method "ssh"
+(defcustom tramp-default-method
+  (if (and (fboundp 'executable-find)
+          (executable-find "plink"))
+      "plink"
+    "ssh")
   "*Default method to use for transferring files.
 See `tramp-methods' for possibilities.
 Also see `tramp-default-method-alist'."
@@ -661,89 +687,126 @@ See `tramp-methods' for a list of possibilities for METHOD."
   (unless (memq system-type '(windows-nt))
     '((tramp-parse-rhosts "/etc/hosts.equiv")
       (tramp-parse-rhosts "~/.rhosts")))
-  "Default list of (FUNCTION FILE) pairs to be examined for rsh methods."
-)
+  "Default list of (FUNCTION FILE) pairs to be examined for rsh methods.")
 
 ;; Default values for non-Unices seeked
 (defconst tramp-completion-function-alist-ssh
   (unless (memq system-type '(windows-nt))
-    '((tramp-parse-rhosts "/etc/hosts.equiv")
-      (tramp-parse-rhosts "/etc/shosts.equiv")
-      (tramp-parse-shosts "/etc/ssh_known_hosts")
-      (tramp-parse-rhosts "~/.rhosts")
-      (tramp-parse-rhosts "~/.shosts")
-      (tramp-parse-shosts "~/.ssh/known_hosts")))
-  "Default list of (FUNCTION FILE) pairs to be examined for ssh methods."
-)
+    '((tramp-parse-rhosts      "/etc/hosts.equiv")
+      (tramp-parse-rhosts      "/etc/shosts.equiv")
+      (tramp-parse-shosts      "/etc/ssh_known_hosts")
+      (tramp-parse-sconfig     "/etc/ssh_config")
+      (tramp-parse-shostkeys   "/etc/ssh2/hostkeys")
+      (tramp-parse-sknownhosts "/etc/ssh2/knownhosts")
+      (tramp-parse-rhosts      "~/.rhosts")
+      (tramp-parse-rhosts      "~/.shosts")
+      (tramp-parse-shosts      "~/.ssh/known_hosts")
+      (tramp-parse-sconfig     "~/.ssh/config")
+      (tramp-parse-shostkeys   "~/.ssh2/hostkeys")
+      (tramp-parse-sknownhosts "~/.ssh2/knownhosts")))
+  "Default list of (FUNCTION FILE) pairs to be examined for ssh methods.")
 
 ;; Default values for non-Unices seeked
 (defconst tramp-completion-function-alist-telnet
   (unless (memq system-type '(windows-nt))
     '((tramp-parse-hosts "/etc/hosts")))
-  "Default list of (FUNCTION FILE) pairs to be examined for telnet methods."
-)
+  "Default list of (FUNCTION FILE) pairs to be examined for telnet methods.")
 
 ;; Default values for non-Unices seeked
 (defconst tramp-completion-function-alist-su
   (unless (memq system-type '(windows-nt))
     '((tramp-parse-passwd "/etc/passwd")))
-  "Default list of (FUNCTION FILE) pairs to be examined for su methods."
-)
+  "Default list of (FUNCTION FILE) pairs to be examined for su methods.")
 
-(defcustom tramp-completion-function-alist
-  (list (cons "rcp"      tramp-completion-function-alist-rsh)
-       (cons "scp"      tramp-completion-function-alist-ssh)
-       (cons "scp1"     tramp-completion-function-alist-ssh)
-       (cons "scp2"     tramp-completion-function-alist-ssh)
-       (cons "scp1_old" tramp-completion-function-alist-ssh)
-       (cons "scp2_old" tramp-completion-function-alist-ssh)
-       (cons "rsync"    tramp-completion-function-alist-rsh)
-       (cons "rsh"      tramp-completion-function-alist-rsh)
-       (cons "ssh"      tramp-completion-function-alist-ssh)
-       (cons "ssh1"     tramp-completion-function-alist-ssh)
-       (cons "ssh2"     tramp-completion-function-alist-ssh)
-       (cons "ssh1_old" tramp-completion-function-alist-ssh)
-       (cons "ssh2_old" tramp-completion-function-alist-ssh)
-       (cons "telnet"   tramp-completion-function-alist-telnet)
-       (cons "su"       tramp-completion-function-alist-su)
-       (cons "sudo"     tramp-completion-function-alist-su)
-       (cons "multi"    nil)
-       (cons "scpx"     tramp-completion-function-alist-ssh)
-       (cons "sshx"     tramp-completion-function-alist-ssh)
-       (cons "krlogin"  tramp-completion-function-alist-rsh)
-       (cons "plink"    tramp-completion-function-alist-ssh)
-       (cons "pscp"     tramp-completion-function-alist-ssh)
-       (cons "fcp"      tramp-completion-function-alist-ssh)
-     )
+(defvar tramp-completion-function-alist nil
   "*Alist of methods for remote files.
 This is a list of entries of the form (NAME PAIR1 PAIR2 ...).
 Each NAME stands for a remote access method.  Each PAIR is of the form
 \(FUNCTION FILE).  FUNCTION is responsible to extract user names and host
 names from FILE for completion.  The following predefined FUNCTIONs exists:
 
- * `tramp-parse-rhosts' for \".rhosts\" like files,
- * `tramp-parse-shosts' for \"ssh_known_hosts\" like files,
- * `tramp-parse-hosts'  for \"/etc/hosts\" like files, and
- * `tramp-parse-passwd' for \"/etc/passwd\" like files.
- * `tramp-parse-netrc'  for \".netrc\" like files.
-
-FUNCTION can also see a customer defined function.  For more details see
-the info pages."
-  :group 'tramp
-  :type '(repeat
-          (cons string
-                (choice (const nil) (repeat (list function file))))))
+ * `tramp-parse-rhosts'      for \"~/.rhosts\" like files,
+ * `tramp-parse-shosts'      for \"~/.ssh/known_hosts\" like files,
+ * `tramp-parse-sconfig'     for \"~/.ssh/config\" like files,
+ * `tramp-parse-shostkeys'   for \"~/.ssh2/hostkeys/*\" like files,
+ * `tramp-parse-sknownhosts' for \"~/.ssh2/knownhosts/*\" like files,
+ * `tramp-parse-hosts'       for \"/etc/hosts\" like files,
+ * `tramp-parse-passwd'      for \"/etc/passwd\" like files.
+ * `tramp-parse-netrc'       for \"~/.netrc\" like files.
+
+FUNCTION can also be a customer defined function.  For more details see
+the info pages.")
+
+(eval-after-load "tramp"
+  '(progn
+     (tramp-set-completion-function
+      "rcp" tramp-completion-function-alist-rsh)
+     (tramp-set-completion-function
+      "scp" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "scp1" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "scp2" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "scp1_old" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "scp2_old" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "rsync" tramp-completion-function-alist-rsh)
+     (tramp-set-completion-function
+      "remcp" tramp-completion-function-alist-rsh)
+     (tramp-set-completion-function
+      "rsh" tramp-completion-function-alist-rsh)
+     (tramp-set-completion-function
+      "ssh" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "ssh1" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "ssh2" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "ssh1_old" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "ssh2_old" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "remsh" tramp-completion-function-alist-rsh)
+     (tramp-set-completion-function
+      "telnet" tramp-completion-function-alist-telnet)
+     (tramp-set-completion-function
+      "su" tramp-completion-function-alist-su)
+     (tramp-set-completion-function
+      "sudo" tramp-completion-function-alist-su)
+     (tramp-set-completion-function
+      "multi" nil)
+     (tramp-set-completion-function
+      "scpx" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "sshx" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "krlogin" tramp-completion-function-alist-rsh)
+     (tramp-set-completion-function
+      "plink" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "plink1" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "pscp" tramp-completion-function-alist-ssh)
+     (tramp-set-completion-function
+      "fcp" tramp-completion-function-alist-ssh)))
 
 (defcustom tramp-rsh-end-of-line "\n"
   "*String used for end of line in rsh connections.
 I don't think this ever needs to be changed, so please tell me about it
 if you need to change this.
-Also see `tramp-password-end-of-line'."
+Also see the method parameter `tramp-password-end-of-line' and the normal
+variable `tramp-default-password-end-of-line'."
   :group 'tramp
   :type 'string)
 
-(defcustom tramp-password-end-of-line tramp-rsh-end-of-line
+(defcustom tramp-default-password-end-of-line
+  tramp-rsh-end-of-line
   "*String used for end of line after sending a password.
+This variable provides the default value for the method parameter
+`tramp-password-end-of-line', see `tramp-methods' for more details.
+
 It seems that people using plink under Windows need to send
 \"\\r\\n\" (carriage-return, then newline) after a password, but just
 \"\\n\" after all other lines.  This variable can be used for the
@@ -773,14 +836,14 @@ The regexp should match at end of buffer."
   :type 'regexp)
 
 (defcustom tramp-shell-prompt-pattern
-  "^[^#$%>\n]*[#$%>] *"
+  "^[^#$%>\n]*[#$%>] *\\(\e\\[[0-9;]*[a-zA-Z] *\\)*"
   "Regexp to match prompts from remote shell.
 Normally, Tramp expects you to configure `shell-prompt-pattern'
 correctly, but sometimes it happens that you are connecting to a
 remote host which sends a different kind of shell prompt.  Therefore,
 Tramp recognizes things matched by `shell-prompt-pattern' as prompt,
 and also things matched by this variable.  The default value of this
-variable is the same as the default value of `shell-prompt-pattern',
+variable is similar to the default value of `shell-prompt-pattern',
 which should work well in many cases."
   :group 'tramp
   :type 'regexp)
@@ -849,6 +912,25 @@ The answer will be provided by `tramp-action-terminal', which see."
   :group 'tramp
   :type 'regexp)
 
+(defcustom tramp-operation-not-permitted-regexp
+  (concat "\\(" "preserving times.*" "\\|" "set mode" "\\)" ":\\s-*"
+         (regexp-opt '("Operation not permitted") t))
+  "Regular expression matching keep-date problems in (s)cp operations.
+Copying has been performed successfully already, so this message can
+be ignored safely."
+  :group 'tramp
+  :type 'regexp)
+
+(defcustom tramp-process-alive-regexp
+  ""
+  "Regular expression indicating a process has finished.
+In fact this expression is empty by intention, it will be used only to
+check regularly the status of the associated process.
+The answer will be provided by `tramp-action-process-alive',
+`tramp-multi-action-process-alive' and`tramp-action-out-of-band', which see."
+  :group 'tramp
+  :type 'regexp)
+
 (defcustom tramp-temp-name-prefix "tramp."
   "*Prefix to use for temporary files.
 If this is a relative file name (such as \"tramp.\"), it is considered
@@ -875,7 +957,11 @@ This variable is only used when Tramp needs to start up another shell
 for tilde expansion.  The extra arguments should typically prevent the
 shell from reading its init file."
   :group 'tramp
-  :type '(alist :key-type string :value-type string))
+  ;; This might be the wrong way to test whether the widget type
+  ;; `alist' is available.  Who knows the right way to test it?
+  :type (if (get 'alist 'widget-type)
+           '(alist :key-type string :value-type string)
+         '(repeat (cons string string))))
 
 (defcustom tramp-prefix-format
   (if tramp-unified-filenames "/" "/[")
@@ -933,7 +1019,7 @@ Derived from `tramp-postfix-multi-method-format'."
 
 (defcustom tramp-postfix-multi-hop-format
   (if tramp-unified-filenames ":" "/")
-  "*String matching delimeter between path and next method.
+  "*String matching delimeter between host and next method.
 Applicable for multi-hop methods.
 Used in `tramp-make-tramp-multi-file-name'."
   :group 'tramp
@@ -941,7 +1027,7 @@ Used in `tramp-make-tramp-multi-file-name'."
 
 (defcustom tramp-postfix-multi-hop-regexp
   (regexp-quote tramp-postfix-multi-hop-format)
-  "*Regexp matching delimeter between path and next method.
+  "*Regexp matching delimeter between host and next method.
 Applicable for multi-hop methods.
 Derived from `tramp-postfix-multi-hop-format'."
   :group 'tramp
@@ -981,21 +1067,21 @@ Derived from `tramp-postfix-user-format'."
 
 (defcustom tramp-postfix-host-format
   (if tramp-unified-filenames ":" "]")
-  "*String matching delimeter between host names and paths.
+  "*String matching delimeter between host names and localnames.
 Used in `tramp-make-tramp-file-name' and `tramp-make-tramp-multi-file-name'."
   :group 'tramp
   :type 'string)
 
 (defcustom tramp-postfix-host-regexp
   (regexp-quote tramp-postfix-host-format)
-  "*Regexp matching delimeter between host names and paths.
+  "*Regexp matching delimeter between host names and localnames.
 Derived from `tramp-postfix-host-format'."
   :group 'tramp
   :type 'regexp)
 
-(defcustom tramp-path-regexp
+(defcustom tramp-localname-regexp
   ".*$"
-  "*Regexp matching paths."
+  "*Regexp matching localnames."
   :group 'tramp
   :type 'regexp)
 
@@ -1008,7 +1094,7 @@ Derived from `tramp-postfix-host-format'."
     "\\(" "\\(" tramp-method-regexp "\\)" tramp-postfix-single-method-regexp "\\)?"
     "\\(" "\\(" tramp-user-regexp "\\)" tramp-postfix-user-regexp   "\\)?"
           "\\(" tramp-host-with-port-regexp "\\)" tramp-postfix-host-regexp
-         "\\(" tramp-path-regexp "\\)")
+         "\\(" tramp-localname-regexp "\\)")
    2 4 5 6)
 
   "*List of five elements (REGEXP METHOD USER HOST FILE), detailing \
@@ -1071,7 +1157,7 @@ Also see `tramp-file-name-structure'."
 
 ;;;###autoload
 (defconst tramp-completion-file-name-regexp-unified
-  "^/[^/]*$"
+  "^/$\\|^/[^/:][^/]*$"
   "Value for `tramp-completion-file-name-regexp' for unified remoting.
 Emacs (not XEmacs) uses a unified filename syntax for Ange-FTP and
 Tramp.  See `tramp-file-name-structure-unified' for more explanations.")
@@ -1106,11 +1192,11 @@ Also see `tramp-file-name-structure'."
     tramp-prefix-regexp
     "\\(" "\\(" tramp-method-regexp "\\)" "\\)?"
     "\\(" "\\(" tramp-postfix-multi-hop-regexp "%s" "\\)+" "\\)?"
-    tramp-postfix-host-regexp "\\(" tramp-path-regexp "\\)")
+    tramp-postfix-host-regexp "\\(" tramp-localname-regexp "\\)")
    2 3 -1)
   "*Describes the file name structure of `multi' files.
 Multi files allow you to contact a remote host in several hops.
-This is a list of four elements (REGEXP METHOD HOP PATH).
+This is a list of four elements (REGEXP METHOD HOP LOCALNAME).
 
 The first element, REGEXP, gives a regular expression to match against
 the file name.  In this regular expression, `%s' is replaced with the
@@ -1121,10 +1207,10 @@ of parentheses is used for the HOP element, see below.)
 
 All remaining elements are numbers.  METHOD gives the number of the
 paren pair which matches the method name.  HOP gives the number of the
-paren pair which matches the hop sequence.  PATH gives the number of
-the paren pair which matches the path name on the remote host.
+paren pair which matches the hop sequence.  LOCALNAME gives the number of
+the paren pair which matches the localname (pathname) on the remote host.
 
-PATH can also be negative, which means to count from the end.  Ie, a
+LOCALNAME can also be negative, which means to count from the end.  Ie, a
 value of -1 means the last paren pair.
 
 I think it would be good if the regexp matches the whole of the
@@ -1133,7 +1219,7 @@ string, but I haven't actually tried what happens if it doesn't..."
   :type '(list (regexp :tag "File name regexp")
                (integer :tag "Paren pair for method name")
                (integer :tag "Paren pair for hops")
-               (integer :tag "Paren pair to match path")))
+               (integer :tag "Paren pair to match localname")))
 
 (defcustom tramp-multi-file-name-hop-structure
   (list
@@ -1164,25 +1250,25 @@ This regular expression should match exactly all of one hop."
     "%h")
    (concat tramp-postfix-host-format "%p"))
   "*Describes how to construct a `multi' file name.
-This is a list of three elements PREFIX, HOP and PATH.
+This is a list of three elements PREFIX, HOP and LOCALNAME.
 
 The first element PREFIX says how to construct the prefix, the second
 element HOP specifies what each hop looks like, and the final element
-PATH says how to construct the path name.
+LOCALNAME says how to construct the localname (pathname).
 
 In PREFIX, `%%' means `%' and `%m' means the method name.
 
 In HOP, `%%' means `%' and `%m', `%u', `%h' mean the hop method, hop
 user and hop host, respectively.
 
-In PATH, `%%' means `%' and `%p' means the path name.
+In LOCALNAME, `%%' means `%' and `%p' means the localname.
 
 The resulting file name always contains one copy of PREFIX and one
-copy of PATH, but there is one copy of HOP for each hop in the file
+copy of LOCALNAME, but there is one copy of HOP for each hop in the file
 name.
 
 Note: the current implementation requires the prefix to contain the
-method name, followed by all the hops, and the path name must come
+method name, followed by all the hops, and the localname must come
 last."
   :group 'tramp
   :type '(list string string string))
@@ -1213,7 +1299,8 @@ but it might be slow on large directories."
     (tramp-wrong-passwd-regexp tramp-action-permission-denied)
     (tramp-yesno-prompt-regexp tramp-action-yesno)
     (tramp-yn-prompt-regexp tramp-action-yn)
-    (tramp-terminal-prompt-regexp tramp-action-terminal))
+    (tramp-terminal-prompt-regexp tramp-action-terminal)
+    (tramp-process-alive-regexp tramp-action-process-alive))
   "List of pattern/action pairs.
 Whenever a pattern matches, the corresponding action is performed.
 Each item looks like (PATTERN ACTION).
@@ -1228,18 +1315,95 @@ corresponding PATTERN matches, the ACTION function is called."
   :group 'tramp
   :type '(repeat (list variable function)))
 
+(defcustom tramp-actions-copy-out-of-band
+  '((tramp-password-prompt-regexp tramp-action-password)
+    (tramp-wrong-passwd-regexp tramp-action-permission-denied)
+    (tramp-process-alive-regexp tramp-action-out-of-band))
+  "List of pattern/action pairs.
+This list is used for copying/renaming with out-of-band methods.
+See `tramp-actions-before-shell' for more info."
+  :group 'tramp
+  :type '(repeat (list variable function)))
+
 (defcustom tramp-multi-actions
   '((tramp-password-prompt-regexp tramp-multi-action-password)
     (tramp-login-prompt-regexp tramp-multi-action-login)
     (shell-prompt-pattern tramp-multi-action-succeed)
     (tramp-shell-prompt-pattern tramp-multi-action-succeed)
-    (tramp-wrong-passwd-regexp tramp-multi-action-permission-denied))
+    (tramp-wrong-passwd-regexp tramp-multi-action-permission-denied)
+    (tramp-process-alive-regexp tramp-multi-action-process-alive))
   "List of pattern/action pairs.
 This list is used for each hop in multi-hop connections.
 See `tramp-actions-before-shell' for more info."
   :group 'tramp
   :type '(repeat (list variable function)))
 
+(defcustom tramp-initial-commands
+  '("unset HISTORY"
+    "unset correct"
+    "unset autocorrect")
+  "List of commands to send to the first remote shell that we see.
+These commands will be sent to any shell, and thus they should be
+designed to work in such circumstances.  Also, restrict the commands
+to the bare necessity for getting the remote shell into a state
+where it is possible to execute the Bourne-ish shell.
+
+At the moment, the command to execute the Bourne-ish shell uses strange
+quoting which `tcsh' tries to correct, so we send the command \"unset
+autocorrect\" to the remote host."
+  :group 'tramp
+  :type '(repeat string))
+
+;; Chunked sending kluge.  We set this to 500 for black-listed constellations
+;; known to have a bug in `process-send-string'; some ssh connections appear
+;; to drop bytes when data is sent too quickly.
+(defcustom tramp-chunksize
+  (when (and (not (featurep 'xemacs))
+            (memq system-type '(hpux)))
+    500)
+  "*If non-nil, chunksize for sending input to local process.
+It is necessary only on systems which have a buggy `process-send-string'
+implementation.  The necessity, whether this variable must be set, can be
+checked via the following code:
+
+  (with-temp-buffer
+    (let ((bytes 1000)
+      (proc (start-process (buffer-name) (current-buffer) \"wc\" \"-c\")))
+      (process-send-string proc (make-string bytes ?x))
+      (process-send-eof proc)
+      (process-send-eof proc)
+      (accept-process-output proc 1)
+      (goto-char (point-min))
+      (re-search-forward \"\\\\w+\")
+      (message \"Bytes sent: %s\\tBytes received: %s\" bytes (match-string 0))))
+
+In the Emacs normally running Tramp, evaluate the above code.
+You can do this, for example, by pasting it into the `*scratch*'
+buffer and then hitting C-j with the cursor after the last
+closing parenthesis.
+
+If your Emacs is buggy, the sent and received numbers will be
+different.  In that case, you'll want to set this variable to
+some number.  For those people who have needed it, the value 500
+seems to have worked well.  There is no way to predict what value
+you need; maybe you could just experiment a bit.
+
+Please raise a bug report via \"M-x tramp-bug\" if your system needs
+this variable to be set as well."
+  :group 'tramp
+  :type '(choice (const nil) integer))
+
+;; Logging in to a remote host normally requires obtaining a pty.  But
+;; Emacs on MacOS X has process-connection-type set to nil by default,
+;; so on those systems Tramp doesn't obtain a pty.  Here, we allow
+;; for an override of the system default.
+(defcustom tramp-process-connection-type t
+  "Overrides `process-connection-type' for connections from Tramp.
+Tramp binds process-connection-type to the value given here before
+opening a connection to a remote host."
+  :group 'tramp
+  :type '(choice (const nil) (const t) (const pty)))
+
 ;;; Internal Variables:
 
 (defvar tramp-buffer-file-attributes nil
@@ -1250,8 +1414,10 @@ the visited file modtime.")
 (make-variable-buffer-local 'tramp-buffer-file-attributes)
 
 (defvar tramp-md5-function
-  (cond ((fboundp 'md5) 'md5)
-       ((and (require 'md5) (fboundp 'md5-encode)) 'md5-encode)
+  (cond ((and (require 'md5) (fboundp 'md5)) 'md5)
+       ((fboundp 'md5-encode)
+        (lambda (x) (base64-encode-string
+                     (funcall (symbol-function 'md5-encode) x))))
        (t (error "Coulnd't find an `md5' function")))
   "Function to call for running the MD5 algorithm.")
 
@@ -1285,27 +1451,27 @@ method parameter, as specified in `tramp-methods' (which see).")
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
 
-(defvar tramp-rsh-program nil
+(defvar tramp-login-program nil
   "This internal variable holds a parameter for `tramp-methods'.
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
 
-(defvar tramp-rsh-args nil
+(defvar tramp-login-args nil
   "This internal variable holds a parameter for `tramp-methods'.
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
 
-(defvar tramp-rcp-program nil
+(defvar tramp-copy-program nil
   "This internal variable holds a parameter for `tramp-methods'.
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
 
-(defvar tramp-rcp-args nil
+(defvar tramp-copy-args nil
   "This internal variable holds a parameter for `tramp-methods'.
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
 
-(defvar tramp-rcp-keep-date-arg nil
+(defvar tramp-copy-keep-date-arg nil
   "This internal variable holds a parameter for `tramp-methods'.
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
@@ -1330,17 +1496,7 @@ method parameter, as specified in `tramp-methods' (which see).")
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
 
-(defvar tramp-telnet-program nil
-  "This internal variable holds a parameter for `tramp-methods'.
-In the connection buffer, this variable has the value of the like-named
-method parameter, as specified in `tramp-methods' (which see).")
-
-(defvar tramp-telnet-args nil
-  "This internal variable holds a parameter for `tramp-methods'.
-In the connection buffer, this variable has the value of the like-named
-method parameter, as specified in `tramp-methods' (which see).")
-
-(defvar tramp-su-program nil
+(defvar tramp-password-end-of-line nil
   "This internal variable holds a parameter for `tramp-methods'.
 In the connection buffer, this variable has the value of the like-named
 method parameter, as specified in `tramp-methods' (which see).")
@@ -1389,26 +1545,103 @@ cat /tmp/tramp.$$
 rm -f /tmp/tramp.$$
 }"
   "Shell function to implement `uudecode' to standard output.
-Many systems support `uudecode -o -' for this or `uudecode -p', but
-some systems don't, and for them we have this shell function.")
+Many systems support `uudecode -o /dev/stdout' or `uudecode -o -'
+for this or `uudecode -p', but some systems don't, and for them
+we have this shell function.")
 
 ;; Perl script to implement `file-attributes' in a Lisp `read'able
 ;; output.  If you are hacking on this, note that you get *no* output
 ;; unless this spits out a complete line, including the '\n' at the
 ;; end.
+;; The device number is returned as "-1", because there will be a virtual
+;; device number set in `tramp-handle-file-attributes'
 (defconst tramp-perl-file-attributes "\
-$f = $ARGV[0];
-@s = lstat($f);
-if (($s[2] & 0170000) == 0120000) { $l = readlink($f); $l = \"\\\"$l\\\"\"; }
-elsif (($s[2] & 0170000) == 040000) { $l = \"t\"; }
-else { $l = \"nil\" };
-printf(\"(%s %u %d %d (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) (%u %u))\\n\",
-$l, $s[3], $s[4], $s[5], $s[8] >> 16 & 0xffff, $s[8] & 0xffff,
-$s[9] >> 16 & 0xffff, $s[9] & 0xffff, $s[10] >> 16 & 0xffff, $s[10] & 0xffff,
-$s[7], $s[2], $s[1] >> 16 & 0xffff, $s[1] & 0xffff, $s[0] >> 16 & 0xffff, $s[0] & 0xffff);"
+@stat = lstat($ARGV[0]);
+if (($stat[2] & 0170000) == 0120000)
+{
+    $type = readlink($ARGV[0]);
+    $type = \"\\\"$type\\\"\";
+}
+elsif (($stat[2] & 0170000) == 040000)
+{
+    $type = \"t\";
+}
+else
+{
+    $type = \"nil\"
+};
+$uid = ($ARGV[1] eq \"integer\") ? $stat[4] : \"\\\"\" . getpwuid($stat[4]) . \"\\\"\";
+$gid = ($ARGV[1] eq \"integer\") ? $stat[5] : \"\\\"\" . getgrgid($stat[5]) . \"\\\"\";
+printf(
+    \"(%s %u %s %s (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) -1)\\n\",
+    $type,
+    $stat[3],
+    $uid,
+    $gid,
+    $stat[8] >> 16 & 0xffff,
+    $stat[8] & 0xffff,
+    $stat[9] >> 16 & 0xffff,
+    $stat[9] & 0xffff,
+    $stat[10] >> 16 & 0xffff,
+    $stat[10] & 0xffff,
+    $stat[7],
+    $stat[2],
+    $stat[1] >> 16 & 0xffff,
+    $stat[1] & 0xffff
+);"
   "Perl script to produce output suitable for use with `file-attributes'
 on the remote file system.")
 
+(defconst tramp-perl-directory-files-and-attributes "\
+chdir($ARGV[0]);
+opendir(DIR,\".\");
+@list = readdir(DIR);
+closedir(DIR);
+$n = scalar(@list);
+printf(\"(\\n\");
+for($i = 0; $i < $n; $i++)
+{
+    $filename = $list[$i];
+    @stat = lstat($filename);
+    if (($stat[2] & 0170000) == 0120000)
+    {
+        $type = readlink($filename);
+        $type = \"\\\"$type\\\"\";
+    }
+    elsif (($stat[2] & 0170000) == 040000)
+    {
+        $type = \"t\";
+    }
+    else
+    {
+        $type = \"nil\"
+    };
+    $uid = ($ARGV[1] eq \"integer\") ? $stat[4] : \"\\\"\" . getpwuid($stat[4]) . \"\\\"\";
+    $gid = ($ARGV[1] eq \"integer\") ? $stat[5] : \"\\\"\" . getgrgid($stat[5]) . \"\\\"\";
+    printf(
+        \"(\\\"%s\\\" %s %u %s %s (%u %u) (%u %u) (%u %u) %u %u t (%u . %u) (%u %u))\\n\",
+        $filename,
+        $type,
+        $stat[3],
+        $uid,
+        $gid,
+        $stat[8] >> 16 & 0xffff,
+        $stat[8] & 0xffff,
+        $stat[9] >> 16 & 0xffff,
+        $stat[9] & 0xffff,
+        $stat[10] >> 16 & 0xffff,
+        $stat[10] & 0xffff,
+        $stat[7],
+        $stat[2],
+        $stat[1] >> 16 & 0xffff,
+        $stat[1] & 0xffff,
+        $stat[0] >> 16 & 0xffff,
+        $stat[0] & 0xffff);
+}
+printf(\")\\n\");"
+  "Perl script implementing `directory-files-attributes' as Lisp `read'able
+output.")
+
 ;; ;; These two use uu encoding.
 ;; (defvar tramp-perl-encode "%s -e'\
 ;; print qq(begin 644 xxx\n);
@@ -1518,6 +1751,7 @@ while (my $data = <STDIN>) {
 
     my $len = length($pending);
     my $chunk = substr($pending, 0, $len & ~3);
+    $pending = substr($pending, $len & ~3 + 1);
 
     # Easy method: translate from chars to (pregenerated) six-bit packets, join,
     # split in 8-bit chunks and convert back to char.
@@ -1559,6 +1793,14 @@ This is used to map a mode number to a permission string.")
     'undecided-dos)
   "Some Emacsen know the `dos' coding system, others need `undecided-dos'.")
 
+(defvar tramp-last-cmd nil
+  "Internal Tramp variable recording the last command sent.
+This variable is buffer-local in every buffer.")
+(make-variable-buffer-local 'tramp-last-cmd)
+
+(defvar tramp-process-echoes nil
+  "Whether to process echoes from the remote shell.")
+
 (defvar tramp-last-cmd-time nil
   "Internal Tramp variable recording the time when the last cmd was sent.
 This variable is buffer-local in every buffer.")
@@ -1569,7 +1811,8 @@ This variable is buffer-local in every buffer.")
 (defvar tramp-feature-write-region-fix
   (when (fboundp 'find-operation-coding-system)
     (let ((file-coding-system-alist '(("test" emacs-mule))))
-      (find-operation-coding-system 'write-region 0 0 "" nil "test")))
+      (funcall (symbol-function 'find-operation-coding-system)
+              'write-region 0 0 "" nil "test")))
     "Internal variable to say if `write-region' chooses the right coding.
 Older versions of Emacs chose the coding system for `write-region' based
 on the FILENAME argument, even if VISIT was a string.")
@@ -1597,8 +1840,8 @@ on the FILENAME argument, even if VISIT was a string.")
     (file-newer-than-file-p . tramp-handle-file-newer-than-file-p)
     (file-attributes . tramp-handle-file-attributes)
     (file-modes . tramp-handle-file-modes)
-    (file-directory-files . tramp-handle-file-directory-files)
     (directory-files . tramp-handle-directory-files)
+    (directory-files-and-attributes . tramp-handle-directory-files-and-attributes)
     (file-name-all-completions . tramp-handle-file-name-all-completions)
     (file-name-completion . tramp-handle-file-name-completion)
     (add-name-to-file . tramp-handle-add-name-to-file)
@@ -1610,12 +1853,16 @@ on the FILENAME argument, even if VISIT was a string.")
     (delete-file . tramp-handle-delete-file)
     (directory-file-name . tramp-handle-directory-file-name)
     (shell-command . tramp-handle-shell-command)
+    (process-file . tramp-handle-process-file)
     (insert-directory . tramp-handle-insert-directory)
     (expand-file-name . tramp-handle-expand-file-name)
     (file-local-copy . tramp-handle-file-local-copy)
+    (file-remote-p . tramp-handle-file-remote-p)
     (insert-file-contents . tramp-handle-insert-file-contents)
     (write-region . tramp-handle-write-region)
+    (find-backup-file-name . tramp-handle-find-backup-file-name)
     (unhandled-file-name-directory . tramp-handle-unhandled-file-name-directory)
+    (dired-compress-file . tramp-handle-dired-compress-file)
     (dired-call-process . tramp-handle-dired-call-process)
     (dired-recursive-delete-directory
      . tramp-handle-dired-recursive-delete-directory)
@@ -1641,7 +1888,10 @@ mentioned here will be handled by `tramp-file-name-handler-alist' or the
 normal Emacs functions.")
 
 ;; Handlers for foreign methods, like FTP or SMB, shall be plugged here.
-(defvar tramp-foreign-file-name-handler-alist nil
+(defvar tramp-foreign-file-name-handler-alist
+  ;; (identity . tramp-sh-file-name-handler) should always be the last
+  ;; entry, since `identity' always matches.
+  '((identity . tramp-sh-file-name-handler))
   "Alist of elements (FUNCTION . HANDLER) for foreign methods handled specially.
 If (FUNCTION FILENAME) returns non-nil, then all I/O on that file is done by
 calling HANDLER.")
@@ -1683,8 +1933,8 @@ remaining args passed to `tramp-message'."
 Calls `line-end-position' or `point-at-eol' if defined, else
 own implementation."
   (cond
-   ((fboundp 'line-end-position) (funcall 'line-end-position))
-   ((fboundp 'point-at-eol)     (funcall 'point-at-eol))
+   ((fboundp 'line-end-position) (funcall (symbol-function 'line-end-position)))
+   ((fboundp 'point-at-eol)     (funcall (symbol-function 'point-at-eol)))
    (t (save-excursion (end-of-line) (point)))))
 
 (defmacro with-parsed-tramp-file-name (filename var &rest body)
@@ -1696,13 +1946,13 @@ the filename structure.  It is also used as a prefix for the variables
 holding the components.  For example, if VAR is the symbol `foo', then
 `foo' will be bound to the whole structure, `foo-multi-method' will
 be bound to the multi-method component, and so on for `foo-method',
-`foo-user', `foo-host', `foo-path'.
+`foo-user', `foo-host', `foo-localname'.
 
 Remaining args are Lisp expressions to be evaluated (inside an implicit
 `progn').
 
 If VAR is nil, then we bind `v' to the structure and `multi-method',
-`method', `user', `host', `path' to the components."
+`method', `user', `host', `localname' to the components."
   `(let* ((,(or var 'v) (tramp-dissect-file-name ,filename))
          (,(if var (intern (concat (symbol-name var) "-multi-method")) 'multi-method)
           (tramp-file-name-multi-method ,(or var 'v)))
@@ -1712,11 +1962,26 @@ If VAR is nil, then we bind `v' to the structure and `multi-method',
           (tramp-file-name-user ,(or var 'v)))
          (,(if var (intern (concat (symbol-name var) "-host")) 'host)
           (tramp-file-name-host ,(or var 'v)))
-         (,(if var (intern (concat (symbol-name var) "-path")) 'path)
-          (tramp-file-name-path ,(or var 'v))))
+         (,(if var (intern (concat (symbol-name var) "-localname")) 'localname)
+          (tramp-file-name-localname ,(or var 'v))))
      ,@body))
 
 (put 'with-parsed-tramp-file-name 'lisp-indent-function 2)
+;; To be activated for debugging containing this macro
+;; It works only when VAR is nil.  Otherwise, it can be deactivated by
+;; (put 'with-parsed-tramp-file-name 'edebug-form-spec 0)
+;; I'm too stupid to write a precise SPEC for it.
+(put 'with-parsed-tramp-file-name 'edebug-form-spec t)
+
+(defmacro tramp-let-maybe (variable value &rest body)
+  "Let-bind VARIABLE to VALUE in BODY, but only if VARIABLE is not obsolete.
+BODY is executed whether or not the variable is obsolete.
+The intent is to protect against `obsolete variable' warnings."
+  `(if (get ',variable 'byte-obsolete-variable)
+       (progn ,@body)
+     (let ((,variable ,value))
+       ,@body)))
+(put 'tramp-let-maybe 'lisp-indent-function 2)
 
 ;;; Config Manipulation Functions:
 
@@ -1726,23 +1991,40 @@ FUNCTION-LIST is a list of entries of the form (FUNCTION FILE).
 The FUNCTION is intended to parse FILE according its syntax.
 It might be a predefined FUNCTION, or a user defined FUNCTION.
 Predefined FUNCTIONs are `tramp-parse-rhosts', `tramp-parse-shosts',
-`tramp-parse-hosts', and `tramp-parse-passwd'.
+`tramp-parse-sconfig',`tramp-parse-hosts', `tramp-parse-passwd',
+and `tramp-parse-netrc'.
+
 Example:
 
     (tramp-set-completion-function
      \"ssh\"
-     '((tramp-parse-shosts \"/etc/ssh_known_hosts\")
-       (tramp-parse-shosts \"~/.ssh/known_hosts\")))"
+     '((tramp-parse-sconfig \"/etc/ssh_config\")
+       (tramp-parse-sconfig \"~/.ssh/config\")))"
 
-  (let ((v (cdr (assoc method tramp-completion-function-alist))))
-    (if v (setcdr v function-list)
+  (let ((r function-list)
+       (v function-list))
+    (setq tramp-completion-function-alist
+         (delete (assoc method tramp-completion-function-alist)
+                 tramp-completion-function-alist))
+
+    (while v
+      ;; Remove double entries
+      (when (member (car v) (cdr v))
+       (setcdr v (delete (car v) (cdr v))))
+      ;; Check for function and file
+      (unless (and (functionp (nth 0 (car v)))
+                  (file-exists-p (nth 1 (car v))))
+       (setq r (delete (car v) r)))
+      (setq v (cdr v)))
+
+    (when r
       (add-to-list 'tramp-completion-function-alist
-                  (cons method function-list)))))
+                  (cons method r)))))
 
 (defun tramp-get-completion-function (method)
   "Returns list of completion functions for METHOD.
 For definition of that list see `tramp-set-completion-function'."
- (cdr (assoc method tramp-completion-function-alist)))
 (cdr (assoc method tramp-completion-function-alist)))
 
 ;;; File Name Handler Functions:
 
@@ -1750,16 +2032,16 @@ For definition of that list see `tramp-set-completion-function'."
   (filename linkname &optional ok-if-already-exists)
   "Like `make-symbolic-link' for tramp files.
 If LINKNAME is a non-Tramp file, it is used verbatim as the target of
-the symlink.  If LINKNAME is a Tramp file, only the path component is
+the symlink.  If LINKNAME is a Tramp file, only the localname component is
 used as the target of the symlink.
 
-If LINKNAME is a Tramp file and the path component is relative, then
-it is expanded first, before the path component is taken.  Note that
+If LINKNAME is a Tramp file and the localname component is relative, then
+it is expanded first, before the localname component is taken.  Note that
 this can give surprising results if the user/host for the source and
 target of the symlink differ."
   (with-parsed-tramp-file-name linkname l
     (let ((ln (tramp-get-remote-ln l-multi-method l-method l-user l-host))
-         (cwd (file-name-directory l-path)))
+         (cwd (file-name-directory l-localname)))
       (unless ln
        (signal 'file-error
                (list "Making a symbolic link."
@@ -1773,16 +2055,16 @@ target of the symlink differ."
                     (not (yes-or-no-p
                           (format
                            "File %s already exists; make it a link anyway? "
-                           l-path)))))
-           (signal 'file-already-exists (list "File already exists" l-path))
+                           l-localname)))))
+           (signal 'file-already-exists (list "File already exists" l-localname))
          (delete-file linkname)))
 
-      ;; If FILENAME is a Tramp name, use just the path component.
+      ;; If FILENAME is a Tramp name, use just the localname component.
       (when (tramp-tramp-file-p filename)
-       (setq filename (tramp-file-name-path
+       (setq filename (tramp-file-name-localname
                        (tramp-dissect-file-name
                         (expand-file-name filename)))))
-    
+
       ;; Right, they are on the same host, regardless of user, method, etc.
       ;; We now make the link on the remote machine. This will occur as the user
       ;; that FILENAME belongs to.
@@ -1791,15 +2073,15 @@ target of the symlink differ."
        l-multi-method l-method l-user l-host
        (format "cd %s && %s -sf %s %s"
                cwd ln
-               filename 
-               l-path)
+               filename
+               l-localname)
        t)))))
 
 
 (defun tramp-handle-load (file &optional noerror nomessage nosuffix must-suffix)
   "Like `load' for tramp files.  Not implemented!"
   (unless (file-name-absolute-p file)
-    (error "Tramp cannot `load' files without absolute path name"))
+    (error "Tramp cannot `load' files without absolute file name"))
   (with-parsed-tramp-file-name file nil
     (unless nosuffix
       (cond ((file-exists-p (concat file ".elc"))
@@ -1828,44 +2110,44 @@ target of the symlink differ."
        (message "Loading %s...done" file))
       t)))
 
-;; Path manipulation functions that grok TRAMP paths...
+;; Localname manipulation functions that grok TRAMP localnames...
 (defun tramp-handle-file-name-directory (file)
   "Like `file-name-directory' but aware of TRAMP files."
   ;; everything except the last filename thing is the directory
   (with-parsed-tramp-file-name file nil
     ;; For the following condition, two possibilities should be tried:
-    ;; (1) (string= path "")
-    ;; (2) (or (string= path "") (string= path "/"))
+    ;; (1) (string= localname "")
+    ;; (2) (or (string= localname "") (string= localname "/"))
     ;; The second variant fails when completing a "/" directory on
     ;; the remote host, that is a filename which looks like
     ;; "/user@host:/".  But maybe wildcards fail with the first variant.
     ;; We should do some investigation.
-    (if (string= path "")
+    (if (string= localname "")
        ;; For a filename like "/[foo]", we return "/".  The `else'
        ;; case would return "/[foo]" unchanged.  But if we do that,
        ;; then `file-expand-wildcards' ceases to work.  It's not
        ;; quite clear to me what's the intuition that tells that this
        ;; behavior is the right behavior, but oh, well.
        "/"
-      ;; run the command on the path portion only
+      ;; run the command on the localname portion only
       ;; CCC: This should take into account the remote machine type, no?
       ;;  --daniel <daniel@danann.net>
       (tramp-make-tramp-file-name multi-method method user host
                                  ;; This will not recurse...
-                                 (or (file-name-directory path) "")))))
+                                 (or (file-name-directory localname) "")))))
 
 (defun tramp-handle-file-name-nondirectory (file)
   "Like `file-name-nondirectory' but aware of TRAMP files."
   (with-parsed-tramp-file-name file nil
-    (file-name-nondirectory path)))
+    (file-name-nondirectory localname)))
 
 (defun tramp-handle-file-truename (filename &optional counter prev-dirs)
   "Like `file-truename' for tramp files."
-  (with-parsed-tramp-file-name filename nil
-    (let* ((steps        (tramp-split-string path "/"))
-          (pathdir (let ((directory-sep-char ?/))
-                     (file-name-as-directory path)))
-          (is-dir (string= path pathdir))
+  (with-parsed-tramp-file-name (expand-file-name filename) nil
+    (let* ((steps        (tramp-split-string localname "/"))
+          (localnamedir (tramp-let-maybe directory-sep-char ?/ ;for XEmacs
+                          (file-name-as-directory localname)))
+          (is-dir (string= localname localnamedir))
           (thisstep nil)
           (numchase 0)
           ;; Don't make the following value larger than necessary.
@@ -1887,7 +2169,7 @@ target of the symlink differ."
                    (append '("") (reverse result) (list thisstep))
                    "/"))
        (setq symlink-target
-             (nth 0 (tramp-handle-file-attributes
+             (nth 0 (file-attributes
                      (tramp-make-tramp-file-name
                       multi-method method user host
                       (mapconcat 'identity
@@ -1910,6 +2192,17 @@ target of the symlink differ."
               (setq numchase (1+ numchase))
               (when (file-name-absolute-p symlink-target)
                 (setq result nil))
+              ;; If the symlink was absolute, we'll get a string like
+              ;; "/user@host:/some/target"; extract the
+              ;; "/some/target" part from it.
+              (when (tramp-tramp-file-p symlink-target)
+                (with-parsed-tramp-file-name symlink-target sym
+                  (unless (equal (list multi-method method user host)
+                                 (list sym-multi-method sym-method
+                                       sym-user sym-host))
+                    (error "Symlink target `%s' on wrong host"
+                           symlink-target))
+                  (setq symlink-target localname)))
               (setq steps
                     (append (tramp-split-string symlink-target "/") steps)))
              (t
@@ -1942,32 +2235,36 @@ target of the symlink differ."
              multi-method method user host
              (format
               (tramp-get-file-exists-command multi-method method user host)
-              (tramp-shell-quote-argument path)))))))
+              (tramp-shell-quote-argument localname)))))))
+
+;; Devices must distinguish physical file systems.  The device numbers
+;; provided by "lstat" aren't unique, because we operate on different hosts.
+;; So we use virtual device numbers, generated by Tramp.  Both Ange-FTP and
+;; EFS use device number "-1".  In order to be different, we use device number
+;; (-1 x), whereby "x" is unique for a given (multi-method method user host).
+(defvar tramp-devices nil
+  "Keeps virtual device numbers.")
 
 ;; CCC: This should check for an error condition and signal failure
 ;;      when something goes wrong.
 ;; Daniel Pittman <daniel@danann.net>
-(defun tramp-handle-file-attributes (filename &optional nonnumeric)
-  "Like `file-attributes' for tramp files.
-Optional argument NONNUMERIC means return user and group name
-rather than as numbers."
-  (let (result)
+(defun tramp-handle-file-attributes (filename &optional id-format)
+  "Like `file-attributes' for tramp files."
+  (when (file-exists-p filename)
+    ;; file exists, find out stuff
+    (unless id-format (setq id-format 'integer))
     (with-parsed-tramp-file-name filename nil
-      (when (tramp-handle-file-exists-p filename)
-       ;; file exists, find out stuff
-       (save-excursion
-         (if (tramp-get-remote-perl multi-method method user host)
-             (setq result
-                   (tramp-handle-file-attributes-with-perl
-                    multi-method method user host path nonnumeric))
-           (setq result
-                 (tramp-handle-file-attributes-with-ls
-                  multi-method method user host path nonnumeric))))))
-    result))
-
+      (save-excursion
+        (tramp-convert-file-attributes
+         multi-method method user host
+         (if (tramp-get-remote-perl multi-method method user host)
+             (tramp-handle-file-attributes-with-perl multi-method method user host
+                                                     localname id-format)
+           (tramp-handle-file-attributes-with-ls multi-method method user host
+                                                 localname id-format)))))))
 
 (defun tramp-handle-file-attributes-with-ls
-  (multi-method method user host path &optional nonnumeric)
+  (multi-method method user host localname &optional id-format)
   "Implement `file-attributes' for tramp files using the ls(1) command."
   (let (symlinkp dirp
                 res-inode res-filemodes res-numlinks
@@ -1975,13 +2272,13 @@ rather than as numbers."
     (tramp-message-for-buffer multi-method method user host 10
                              "file attributes with ls: %s"
                              (tramp-make-tramp-file-name
-                              multi-method method user host path))
+                              multi-method method user host localname))
     (tramp-send-command
      multi-method method user host
      (format "%s %s %s"
             (tramp-get-ls-command multi-method method user host)
-            (if nonnumeric "-ild" "-ildn")
-            (tramp-shell-quote-argument path)))
+            (if (eq id-format 'integer) "-ildn" "-ild")
+            (tramp-shell-quote-argument localname)))
     (tramp-wait-for-output)
     ;; parse `ls -l' output ...
     ;; ... inode
@@ -2007,7 +2304,7 @@ rather than as numbers."
     ;; ... uid and gid
     (setq res-uid (read (current-buffer)))
     (setq res-gid (read (current-buffer)))
-    (unless nonnumeric
+    (when (eq id-format 'integer)
       (unless (numberp res-uid) (setq res-uid -1))
       (unless (numberp res-gid) (setq res-gid -1)))
     ;; ... size
@@ -2047,94 +2344,109 @@ rather than as numbers."
      nil                               ;hm?
      ;; 10. inode number.
      res-inode
-     ;; 11. Device number.
-     -1                                        ;hm?
+     ;; 11. Device number.  Will be replaced by a virtual device number.
+     -1
      )))
 
 (defun tramp-handle-file-attributes-with-perl
-  (multi-method method user host path &optional nonnumeric)
-  "Implement `file-attributes' for tramp files using a Perl script.
-
-The Perl command is sent to the remote machine when the connection
-is initially created and is kept cached by the remote shell."
+  (multi-method method user host localname &optional id-format)
+  "Implement `file-attributes' for tramp files using a Perl script."
   (tramp-message-for-buffer multi-method method user host 10
                            "file attributes with perl: %s"
                            (tramp-make-tramp-file-name
-                            multi-method method user host path))
-  (tramp-send-command
-   multi-method method user host
-   (format "tramp_file_attributes %s" 
-          (tramp-shell-quote-argument path)))
+                            multi-method method user host localname))
+  (tramp-maybe-send-perl-script multi-method method user host
+                               tramp-perl-file-attributes
+                                "tramp_file_attributes")
+  (tramp-send-command multi-method method user host
+                      (format "tramp_file_attributes %s %s"
+                              (tramp-shell-quote-argument localname) id-format))
   (tramp-wait-for-output)
-  (let ((result (read (current-buffer))))
-    (setcar (nthcdr 8 result)
-           (tramp-file-mode-from-int (nth 8 result)))
-    result))
+  (read (current-buffer)))
 
 (defun tramp-handle-set-visited-file-modtime (&optional time-list)
   "Like `set-visited-file-modtime' for tramp files."
   (unless (buffer-file-name)
     (error "Can't set-visited-file-modtime: buffer `%s' not visiting a file"
           (buffer-name)))
-  (when time-list
-    (tramp-run-real-handler 'set-visited-file-modtime (list time-list)))
-  (let ((f (buffer-file-name))
-       (coding-system-used nil))
-    (with-parsed-tramp-file-name f nil
-      (let* ((attr (file-attributes f))
-            (modtime (nth 5 attr)))
-       ;; We use '(0 0) as a don't-know value.  See also
-       ;; `tramp-handle-file-attributes-with-ls'.
-       (when (boundp 'last-coding-system-used)
-         (setq coding-system-used last-coding-system-used))
-       (if (not (equal modtime '(0 0)))
-           (tramp-run-real-handler 'set-visited-file-modtime (list modtime))
-         (save-excursion
-           (tramp-send-command
-            multi-method method user host
-            (format "%s -ild %s"
-                    (tramp-get-ls-command multi-method method user host)
-                    (tramp-shell-quote-argument path)))
-           (tramp-wait-for-output)
-           (setq attr (buffer-substring (point)
-                                        (progn (end-of-line) (point)))))
-         (setq tramp-buffer-file-attributes attr))
-       (when (boundp 'last-coding-system-used)
-         (setq last-coding-system-used coding-system-used))
-       nil))))
+  (if time-list
+      (tramp-run-real-handler 'set-visited-file-modtime (list time-list))
+    (let ((f (buffer-file-name))
+         (coding-system-used nil))
+      (with-parsed-tramp-file-name f nil
+       (let* ((attr (file-attributes f))
+              ;; '(-1 65535) means file doesn't exists yet.
+              (modtime (or (nth 5 attr) '(-1 65535))))
+         ;; We use '(0 0) as a don't-know value.  See also
+         ;; `tramp-handle-file-attributes-with-ls'.
+         (when (boundp 'last-coding-system-used)
+           (setq coding-system-used last-coding-system-used))
+         (if (not (equal modtime '(0 0)))
+             (tramp-run-real-handler 'set-visited-file-modtime (list modtime))
+           (save-excursion
+             (tramp-send-command
+              multi-method method user host
+              (format "%s -ild %s"
+                      (tramp-get-ls-command multi-method method user host)
+                      (tramp-shell-quote-argument localname)))
+             (tramp-wait-for-output)
+             (setq attr (buffer-substring (point)
+                                          (progn (end-of-line) (point)))))
+           (setq tramp-buffer-file-attributes attr))
+         (when (boundp 'last-coding-system-used)
+           (setq last-coding-system-used coding-system-used))
+       nil)))))
 
 ;; CCC continue here
 
 ;; This function makes the same assumption as
 ;; `tramp-handle-set-visited-file-modtime'.
 (defun tramp-handle-verify-visited-file-modtime (buf)
-  "Like `verify-visited-file-modtime' for tramp files."
+  "Like `verify-visited-file-modtime' for tramp files.
+At the time `verify-visited-file-modtime' calls this function, we
+already know that the buffer is visiting a file and that
+`visited-file-modtime' does not return 0.  Do not call this
+function directly, unless those two cases are already taken care
+of."
   (with-current-buffer buf
-    (let ((f (buffer-file-name)))
-      (with-parsed-tramp-file-name f nil
-       (let* ((attr (file-attributes f))
-              (modtime (nth 5 attr)))
-         (cond ((and attr (not (equal modtime '(0 0))))
-                ;; Why does `file-attributes' return a list (HIGH
-                ;; LOW), but `visited-file-modtime' returns a cons
-                ;; (HIGH . LOW)?
-                (let ((mt (visited-file-modtime)))
-                  (< (abs (tramp-time-diff
-                           modtime (list (car mt) (cdr mt)))) 2)))
-               (attr
-                (save-excursion
-                  (tramp-send-command
-                   multi-method method user host
-                   (format "%s -ild %s"
-                           (tramp-get-ls-command multi-method method
-                                                 user host)
-                           (tramp-shell-quote-argument path)))
-                  (tramp-wait-for-output)
-                  (setq attr (buffer-substring
-                              (point) (progn (end-of-line) (point)))))
-                (equal tramp-buffer-file-attributes attr))
-               ;; If file does not exist, say it is not modified.
-               (t nil)))))))
+    ;; There is no file visiting the buffer, or the buffer has no
+    ;; recorded last modification time.
+    (if (or (not (buffer-file-name))
+           (eq (visited-file-modtime) 0))
+      t
+      (let ((f (buffer-file-name)))
+       (with-parsed-tramp-file-name f nil
+         (let* ((attr (file-attributes f))
+                (modtime (nth 5 attr))
+                (mt (visited-file-modtime)))
+
+           (cond
+            ;; file exists, and has a known modtime.
+            ((and attr (not (equal modtime '(0 0))))
+             (< (abs (tramp-time-diff
+                      modtime
+                      ;; For compatibility, deal with both the old
+                      ;; (HIGH . LOW) and the new (HIGH LOW)
+                      ;; return values of `visited-file-modtime'.
+                      (if (atom (cdr mt))
+                          (list (car mt) (cdr mt))
+                        mt)))
+                2))
+            ;; modtime has the don't know value.
+            (attr
+             (save-excursion
+               (tramp-send-command
+                multi-method method user host
+                (format "%s -ild %s"
+                        (tramp-get-ls-command multi-method method user host)
+                        (tramp-shell-quote-argument localname)))
+               (tramp-wait-for-output)
+               (setq attr (buffer-substring
+                           (point) (progn (end-of-line) (point)))))
+             (equal tramp-buffer-file-attributes attr))
+            ;; If file does not exist, say it is not modified
+            ;; if and only if that agrees with the buffer's record.
+            (t (equal mt '(-1 65535))))))))))
 
 (defadvice clear-visited-file-modtime (after tramp activate)
   "Set `tramp-buffer-file-attributes' back to nil.
@@ -2150,7 +2462,7 @@ if the remote host can't provide the modtime."
                      multi-method method user host
                      (format "chmod %s %s"
                              (tramp-decimal-to-octal mode)
-                             (tramp-shell-quote-argument path))))
+                             (tramp-shell-quote-argument localname))))
        (signal 'file-error
                (list "Doing chmod"
                      ;; FIXME: extract the proper text from chmod's stderr.
@@ -2197,7 +2509,7 @@ if the remote host can't provide the modtime."
                 (fa2 (file-attributes file2)))
             (if (and (not (equal (nth 5 fa1) '(0 0)))
                      (not (equal (nth 5 fa2) '(0 0))))
-                (> 0 (car (tramp-time-diff (nth 5 fa1) (nth 5 fa2))))
+                (> 0 (tramp-time-diff (nth 5 fa2) (nth 5 fa1)))
               ;; If one of them is the dont-know value, then we can
               ;; still try to run a shell command on the remote host.
               ;; However, this only works if both files are Tramp
@@ -2255,43 +2567,49 @@ if the remote host can't provide the modtime."
        (tramp-send-command-and-check
        multi-method method user host
        (format "test -d %s"
-               (tramp-shell-quote-argument path))
+               (tramp-shell-quote-argument localname))
        t)))))                          ;run command in subshell
 
 (defun tramp-handle-file-regular-p (filename)
   "Like `file-regular-p' for tramp files."
   (with-parsed-tramp-file-name filename nil
-    (and (tramp-handle-file-exists-p filename)
-        (eq ?- (aref (nth 8 (tramp-handle-file-attributes filename)) 0)))))
+    (and (file-exists-p filename)
+        (eq ?- (aref (nth 8 (file-attributes filename)) 0)))))
 
 (defun tramp-handle-file-symlink-p (filename)
   "Like `file-symlink-p' for tramp files."
   (with-parsed-tramp-file-name filename nil
-    (let ((x (car (tramp-handle-file-attributes filename))))
-      (when (stringp x) x))))
+    (let ((x (car (file-attributes filename))))
+      (when (stringp x)
+       ;; When Tramp is running on VMS, then `file-name-absolute-p'
+       ;; might do weird things.
+       (if (file-name-absolute-p x)
+           (tramp-make-tramp-file-name
+            multi-method method user host x)
+         x)))))
 
 (defun tramp-handle-file-writable-p (filename)
   "Like `file-writable-p' for tramp files."
   (with-parsed-tramp-file-name filename nil
-    (if (tramp-handle-file-exists-p filename)
+    (if (file-exists-p filename)
        ;; Existing files must be writable.
        (zerop (tramp-run-test "-w" filename))
       ;; If file doesn't exist, check if directory is writable.
       (and (zerop (tramp-run-test
-                  "-d" (tramp-handle-file-name-directory filename)))
+                  "-d" (file-name-directory filename)))
           (zerop (tramp-run-test
-                  "-w" (tramp-handle-file-name-directory filename)))))))
+                  "-w" (file-name-directory filename)))))))
 
 (defun tramp-handle-file-ownership-preserved-p (filename)
   "Like `file-ownership-preserved-p' for tramp files."
   (with-parsed-tramp-file-name filename nil
-    (or (not (tramp-handle-file-exists-p filename))
+    (or (not (file-exists-p filename))
        ;; Existing files must be writable.
        (zerop (tramp-run-test "-O" filename)))))
 
 ;; Other file name ops.
 
-;; ;; Matthias Köppe <mkoeppe@mail.math.uni-magdeburg.de>
+;; ;; Matthias K\e,Av\e(Bppe <mkoeppe@mail.math.uni-magdeburg.de>
 ;; (defun tramp-handle-directory-file-name (directory)
 ;;   "Like `directory-file-name' for tramp files."
 ;;   (if (and (eq (aref directory (- (length directory) 1)) ?/)
@@ -2299,17 +2617,30 @@ if the remote host can't provide the modtime."
 ;;       (substring directory 0 (- (length directory) 1))
 ;;     directory))
 
-;; Philippe Troin <phil@fifi.org>
+;; ;; Philippe Troin <phil@fifi.org>
+;; (defun tramp-handle-directory-file-name (directory)
+;;   "Like `directory-file-name' for tramp files."
+;;   (with-parsed-tramp-file-name directory nil
+;;     (let ((directory-length-1 (1- (length directory))))
+;;       (save-match-data
+;;     (if (and (eq (aref directory directory-length-1) ?/)
+;;              (eq (string-match tramp-file-name-regexp directory) 0)
+;;              (/= (match-end 0) directory-length-1))
+;;         (substring directory 0 directory-length-1)
+;;       directory)))))
+
 (defun tramp-handle-directory-file-name (directory)
   "Like `directory-file-name' for tramp files."
+  ;; If localname component of filename is "/", leave it unchanged.
+  ;; Otherwise, remove any trailing slash from localname component.
+  ;; Method, host, etc, are unchanged.  Does it make sense to try
+  ;; to avoid parsing the filename?
   (with-parsed-tramp-file-name directory nil
-    (let ((directory-length-1 (1- (length directory))))
-      (save-match-data
-       (if (and (eq (aref directory directory-length-1) ?/)
-                (eq (string-match tramp-file-name-regexp directory) 0)
-                (/= (match-end 0) directory-length-1))
-           (substring directory 0 directory-length-1)
-         directory)))))
+    (if (and (not (zerop (length localname)))
+            (eq (aref localname (1- (length localname))) ?/)
+            (not (string= localname "/")))
+       (substring directory 0 -1)
+      directory)))
 
 ;; Directory listings.
 
@@ -2321,11 +2652,11 @@ if the remote host can't provide the modtime."
       (save-excursion
        (tramp-barf-unless-okay
         multi-method method user host
-        (concat "cd " (tramp-shell-quote-argument path))
+        (concat "cd " (tramp-shell-quote-argument localname))
         nil
         'file-error
         "tramp-handle-directory-files: couldn't `cd %s'"
-        (tramp-shell-quote-argument path))
+        (tramp-shell-quote-argument localname))
        (tramp-send-command
         multi-method method user host
         (concat (tramp-get-ls-command multi-method method user host)
@@ -2364,6 +2695,38 @@ if the remote host can't provide the modtime."
                  (push item result)))))))
       result)))
 
+(defun tramp-handle-directory-files-and-attributes
+  (directory &optional full match nosort id-format)
+  "Like `directory-files-and-attributes' for tramp files."
+  (when (tramp-handle-file-exists-p directory)
+    (save-excursion
+      (setq directory (tramp-handle-expand-file-name directory))
+      (with-parsed-tramp-file-name directory nil
+        (tramp-maybe-send-perl-script multi-method method user host
+                                     tramp-perl-directory-files-and-attributes
+                                      "tramp_directory_files_and_attributes")
+        (tramp-send-command multi-method method user host
+                            (format "tramp_directory_files_and_attributes %s %s"
+                                    (tramp-shell-quote-argument localname)
+                                    (or id-format 'integer)))
+        (tramp-wait-for-output)
+        (let* ((root (cons nil (read (current-buffer))))
+               (cell root))
+          (while (cdr cell)
+            (if (and match (not (string-match match (caadr cell))))
+                ;; Remove from list
+                (setcdr cell (cddr cell))
+              ;; Include in list
+              (setq cell (cdr cell))
+              (let ((l (car cell)))
+                (tramp-convert-file-attributes multi-method method user host
+                                               (cdr l))
+                ;; If FULL, make file name absolute
+                (when full (setcar l (concat directory "/" (car l)))))))
+          (if nosort
+              (cdr root)
+            (sort (cdr root) (lambda (x y) (string< (car x) (car y))))))))))
+
 ;; This function should return "foo/" for directories and "bar" for
 ;; files.  We use `ls -ad' to get a list of files (including
 ;; directories), and `find . -type d \! -name . -prune' to get a list
@@ -2377,10 +2740,10 @@ if the remote host can't provide the modtime."
        (save-excursion
          (tramp-barf-unless-okay
           multi-method method user host
-          (format "cd %s" (tramp-shell-quote-argument path))
+          (format "cd %s" (tramp-shell-quote-argument localname))
           nil 'file-error
           "tramp-handle-file-name-all-completions: Couldn't `cd %s'"
-          (tramp-shell-quote-argument path))
+          (tramp-shell-quote-argument localname))
 
          ;; Get a list of directories and files, including reliably
          ;; tagging the directories with a trailing '/'.  Because I
@@ -2403,7 +2766,7 @@ if the remote host can't provide the modtime."
            (push (buffer-substring (point)
                                    (tramp-line-end-position))
                  result))
-       
+
          (tramp-send-command multi-method method user host "cd")
          (tramp-wait-for-output)
 
@@ -2452,8 +2815,8 @@ if the remote host can't provide the modtime."
          (error "add-name-to-file: file %s already exists" newname))
        (tramp-barf-unless-okay
         v1-multi-method v1-method v1-user v1-host
-        (format "%s %s %s" ln (tramp-shell-quote-argument v1-path)
-                (tramp-shell-quote-argument v2-path))
+        (format "%s %s %s" ln (tramp-shell-quote-argument v1-localname)
+                (tramp-shell-quote-argument v2-localname))
         nil 'file-error
         "error with add-name-to-file, see buffer `%s' for details"
         (buffer-name))))))
@@ -2509,73 +2872,127 @@ and `rename'.  FILENAME and NEWNAME must be absolute file names."
       (signal 'file-already-exists
               (list newname))))
   (let ((t1 (tramp-tramp-file-p filename))
-       (t2 (tramp-tramp-file-p newname)))
+       (t2 (tramp-tramp-file-p newname))
+       v1-multi-method v1-method v1-user v1-host v1-localname
+       v2-multi-method v2-method v2-user v2-host v2-localname)
+
     ;; Check which ones of source and target are Tramp files.
+    ;; We cannot invoke `with-parsed-tramp-file-name';
+    ;; it fails if the file isn't a Tramp file name.
+    (if t1
+       (with-parsed-tramp-file-name filename l
+         (setq v1-multi-method l-multi-method
+               v1-method l-method
+               v1-user l-user
+               v1-host l-host
+               v1-localname l-localname))
+      (setq v1-localname filename))
+    (if t2
+       (with-parsed-tramp-file-name newname l
+         (setq v2-multi-method l-multi-method
+               v2-method l-method
+               v2-user l-user
+               v2-host l-host
+               v2-localname l-localname))
+      (setq v2-localname newname))
+
     (cond
+     ;; Both are Tramp files.
      ((and t1 t2)
-      ;; Both are Tramp files.
-      (with-parsed-tramp-file-name filename v1
-       (with-parsed-tramp-file-name newname v2
-         ;; Check if we can use a shortcut.
-         (if (and (equal v1-multi-method v2-multi-method)
-                  (equal v1-method v2-method)
-                  (equal v1-host v2-host)
-                  (equal v1-user v2-user))
-             ;; Shortcut: if method, host, user are the same for both
-             ;; files, we invoke `cp' or `mv' on the remote host
-             ;; directly.
-             (tramp-do-copy-or-rename-file-directly
-              op v1-multi-method v1-method v1-user v1-host
-              v1-path v2-path keep-date)
-           ;; The shortcut was not possible.  So we copy the
-           ;; file first.  If the operation was `rename', we go
-           ;; back and delete the original file (if the copy was
-           ;; successful).  The approach is simple-minded: we
-           ;; create a new buffer, insert the contents of the
-           ;; source file into it, then write out the buffer to
-           ;; the target file.  The advantage is that it doesn't
-           ;; matter which filename handlers are used for the
-           ;; source and target file.
-
-           ;; CCC: If both source and target are Tramp files,
-           ;; and both are using the same rcp-program, then we
-           ;; can invoke rcp directly.  Note that
-           ;; default-directory should point to a local
-           ;; directory if we want to invoke rcp.
-           (tramp-do-copy-or-rename-via-buffer
-            op filename newname keep-date)))))
-         ((or t1 t2)
-          ;; Use the generic method via a Tramp buffer.
-          (tramp-do-copy-or-rename-via-buffer op filename newname keep-date))
-         (t
-          ;; One of them must be a Tramp file.
-          (error "Tramp implementation says this cannot happen")))))
-
-(defun tramp-do-copy-or-rename-via-buffer (op filename newname keep-date)
+      (cond
+       ;; Shortcut: if method, host, user are the same for both
+       ;; files, we invoke `cp' or `mv' on the remote host
+       ;; directly.
+       ((and (equal v1-multi-method v2-multi-method)
+            (equal v1-method v2-method)
+            (equal v1-user v2-user)
+            (equal v1-host v2-host))
+       (tramp-do-copy-or-rename-file-directly
+        op v1-multi-method v1-method v1-user v1-host
+        v1-localname v2-localname keep-date))
+       ;; If both source and target are Tramp files,
+       ;; both are using the same copy-program, then we
+       ;; can invoke rcp directly.  Note that
+       ;; default-directory should point to a local
+       ;; directory if we want to invoke rcp.
+       ((and (not v1-multi-method)
+            (not v2-multi-method)
+            (equal v1-method v2-method)
+            (tramp-method-out-of-band-p
+             v1-multi-method v1-method v1-user v1-host)
+            (not (string-match "\\([^#]*\\)#\\(.*\\)" v1-host))
+            (not (string-match "\\([^#]*\\)#\\(.*\\)" v2-host)))
+       (tramp-do-copy-or-rename-file-out-of-band
+        op filename newname keep-date))
+       ;; No shortcut was possible.  So we copy the
+       ;; file first.  If the operation was `rename', we go
+       ;; back and delete the original file (if the copy was
+       ;; successful).  The approach is simple-minded: we
+       ;; create a new buffer, insert the contents of the
+       ;; source file into it, then write out the buffer to
+       ;; the target file.  The advantage is that it doesn't
+       ;; matter which filename handlers are used for the
+       ;; source and target file.
+       (t
+       (tramp-do-copy-or-rename-file-via-buffer
+        op filename newname keep-date))))
+
+     ;; One file is a Tramp file, the other one is local.
+     ((or t1 t2)
+      ;; If the Tramp file has an out-of-band method, the corresponding
+      ;; copy-program can be invoked.
+      (if (and (not v1-multi-method)
+              (not v2-multi-method)
+              (or (tramp-method-out-of-band-p
+                   v1-multi-method v1-method v1-user v1-host)
+                  (tramp-method-out-of-band-p
+                   v2-multi-method v2-method v2-user v2-host)))
+         (tramp-do-copy-or-rename-file-out-of-band
+          op filename newname keep-date)
+       ;; Use the generic method via a Tramp buffer.
+       (tramp-do-copy-or-rename-file-via-buffer
+        op filename newname keep-date)))
+
+     (t
+      ;; One of them must be a Tramp file.
+      (error "Tramp implementation says this cannot happen")))))
+
+(defun tramp-do-copy-or-rename-file-via-buffer (op filename newname keep-date)
   "Use an Emacs buffer to copy or rename a file.
 First arg OP is either `copy' or `rename' and indicates the operation.
 FILENAME is the source file, NEWNAME the target file.
 KEEP-DATE is non-nil if NEWNAME should have the same timestamp as FILENAME."
-  (let ((trampbuf (get-buffer-create "*tramp output*")))
-    (when keep-date
+  (let ((trampbuf (get-buffer-create "*tramp output*"))
+       (modtime (nth 5 (file-attributes filename))))
+    (when (and keep-date (or (null modtime) (equal modtime '(0 0))))
       (tramp-message
        1 (concat "Warning: cannot preserve file time stamp"
                 " with inline copying across machines")))
     (save-excursion
       (set-buffer trampbuf) (erase-buffer)
       (insert-file-contents-literally filename)
-      (let ((coding-system-for-write 'no-conversion))
-       (write-region (point-min) (point-max) newname)))
+      ;; We don't want the target file to be compressed, so we let-bind
+      ;; `jka-compr-inhibit' to t.
+      (let ((coding-system-for-write 'binary)
+           (jka-compr-inhibit t))
+       (write-region (point-min) (point-max) newname))
+      ;; KEEP-DATE handling.
+      (when keep-date
+       (when (and (not (null modtime))
+                  (not (equal modtime '(0 0))))
+         (tramp-touch newname modtime)))
+      ;; Set the mode.
+      (set-file-modes newname (file-modes filename)))
     ;; If the operation was `rename', delete the original file.
     (unless (eq op 'copy)
       (delete-file filename))))
 
 (defun tramp-do-copy-or-rename-file-directly
-  (op multi-method method user host path1 path2 keep-date)
+  (op multi-method method user host localname1 localname2 keep-date)
   "Invokes `cp' or `mv' on the remote system.
 OP must be one of `copy' or `rename', indicating `cp' or `mv',
 respectively.  METHOD, USER, and HOST specify the connection.
-PATH1 and PATH2 specify the two arguments of `cp' or `mv'.
+LOCALNAME1 and LOCALNAME2 specify the two arguments of `cp' or `mv'.
 If KEEP-DATE is non-nil, preserve the time stamp when copying."
   ;; CCC: What happens to the timestamp when renaming?
   (let ((cmd (cond ((and (eq op 'copy) keep-date) "cp -f -p")
@@ -2585,15 +3002,162 @@ If KEEP-DATE is non-nil, preserve the time stamp when copying."
                        "Unknown operation `%s', must be `copy' or `rename'"
                        op)))))
     (save-excursion
-      (tramp-barf-unless-okay
+      (tramp-send-command
        multi-method method user host
        (format "%s %s %s"
                cmd
-               (tramp-shell-quote-argument path1)
-               (tramp-shell-quote-argument path2))
-       nil 'file-error
-       "Copying directly failed, see buffer `%s' for details."
-       (buffer-name)))))
+               (tramp-shell-quote-argument localname1)
+               (tramp-shell-quote-argument localname2)))
+      (tramp-wait-for-output)
+      (goto-char (point-min))
+      (unless
+         (or
+          (and (eq op 'copy) keep-date
+               ;; Mask cp -f error.
+               (re-search-forward tramp-operation-not-permitted-regexp nil t))
+          (zerop (tramp-send-command-and-check
+                  multi-method method user host nil nil)))
+       (pop-to-buffer (current-buffer))
+       (signal 'file-error
+               (format "Copying directly failed, see buffer `%s' for details."
+                       (buffer-name)))))
+    ;; Set the mode.
+    ;; CCC: Maybe `chmod --reference=localname1 localname2' could be used
+    ;;      where available?
+    (unless (or (eq op 'rename) keep-date)
+      (set-file-modes
+       (tramp-make-tramp-file-name multi-method method user host localname2)
+       (file-modes
+       (tramp-make-tramp-file-name
+        multi-method method user host localname1))))))
+
+(defun tramp-do-copy-or-rename-file-out-of-band (op filename newname keep-date)
+  "Invoke rcp program to copy.
+One of FILENAME and NEWNAME must be a Tramp name, the other must
+be a local filename.  The method used must be an out-of-band method."
+  (let ((t1 (tramp-tramp-file-p filename))
+       (t2 (tramp-tramp-file-p newname))
+       v1-multi-method v1-method v1-user v1-host v1-localname
+       v2-multi-method v2-method v2-user v2-host v2-localname
+       multi-method method user host copy-program copy-args
+       source target trampbuf)
+
+    ;; Check which ones of source and target are Tramp files.
+    ;; We cannot invoke `with-parsed-tramp-file-name';
+    ;; it fails if the file isn't a Tramp file name.
+    (if t1
+       (with-parsed-tramp-file-name filename l
+         (setq v1-multi-method l-multi-method
+               v1-method l-method
+               v1-user l-user
+               v1-host l-host
+               v1-localname l-localname
+               multi-method l-multi-method
+               method (tramp-find-method
+                       v1-multi-method v1-method v1-user v1-host)
+               user l-user
+               host l-host
+               copy-program (tramp-get-method-parameter
+                             v1-multi-method method
+                             v1-user v1-host 'tramp-copy-program)
+               copy-args (tramp-get-method-parameter
+                                v1-multi-method method
+                                v1-user v1-host 'tramp-copy-args)))
+      (setq v1-localname filename))
+
+    (if t2
+       (with-parsed-tramp-file-name newname l
+         (setq v2-multi-method l-multi-method
+               v2-method l-method
+               v2-user l-user
+               v2-host l-host
+               v2-localname l-localname
+               multi-method l-multi-method
+               method (tramp-find-method
+                       v2-multi-method v2-method v2-user v2-host)
+               user l-user
+               host l-host
+               copy-program (tramp-get-method-parameter
+                             v2-multi-method method
+                             v2-user v2-host 'tramp-copy-program)
+               copy-args (tramp-get-method-parameter
+                                v2-multi-method method
+                                v2-user v2-host 'tramp-copy-args)))
+      (setq v2-localname newname))
+
+    ;; The following should be changed.  We need a more general
+    ;; mechanism to parse extra host args.
+    (if (not t1)
+       (setq source v1-localname)
+      (when (string-match "\\([^#]*\\)#\\(.*\\)" v1-host)
+       (setq copy-args (cons "-P" (cons (match-string 2 v1-host) copy-args)))
+       (setq v1-host (match-string 1 v1-host)))
+      (setq source
+            (tramp-make-copy-program-file-name
+             v1-user v1-host
+             (tramp-shell-quote-argument v1-localname))))
+
+    (if (not t2)
+       (setq target v2-localname)
+      (when (string-match "\\([^#]*\\)#\\(.*\\)" v2-host)
+       (setq copy-args (cons "-P" (cons (match-string 2 v2-host) copy-args)))
+       (setq v2-host (match-string 1 v2-host)))
+      (setq target
+            (tramp-make-copy-program-file-name
+             v2-user v2-host
+             (tramp-shell-quote-argument v2-localname))))
+
+    ;; Handle keep-date argument
+    (when keep-date
+      (if t1
+         (setq copy-args
+               (cons (tramp-get-method-parameter
+                      v1-multi-method method
+                      v1-user v1-host 'tramp-copy-keep-date-arg)
+                     copy-args))
+       (setq copy-args
+             (cons (tramp-get-method-parameter
+                    v2-multi-method method
+                    v2-user v2-host 'tramp-copy-keep-date-arg)
+                   copy-args))))
+
+    (setq copy-args (append copy-args (list source target))
+         trampbuf (generate-new-buffer
+                   (tramp-buffer-name multi-method method user host)))
+
+    ;; Use an asynchronous process.  By this, password can be handled.
+    (save-excursion
+
+      ;; Check for program.
+      (when (and (fboundp 'executable-find)
+                (not (executable-find copy-program)))
+       (error "Cannot find copy program: %s" copy-program))
+
+      (set-buffer trampbuf)
+      (setq tramp-current-multi-method multi-method
+           tramp-current-method method
+           tramp-current-user user
+           tramp-current-host host)
+      (tramp-message
+       5 "Transferring %s to file %s..." filename newname)
+
+      ;; Use rcp-like program for file transfer.
+      (let ((p (apply 'start-process (buffer-name trampbuf) trampbuf
+                     copy-program copy-args)))
+       (tramp-set-process-query-on-exit-flag p nil)
+       (tramp-process-actions p multi-method method user host
+                              tramp-actions-copy-out-of-band))
+      (kill-buffer trampbuf)
+      (tramp-message
+       5 "Transferring %s to file %s...done" filename newname)
+
+      ;; Set the mode.
+      (unless keep-date
+       (set-file-modes newname (file-modes filename))))
+
+    ;; If the operation was `rename', delete the original file.
+    (unless (eq op 'copy)
+      (delete-file filename))))
 
 ;; mkdir
 (defun tramp-handle-make-directory (dir &optional parents)
@@ -2605,7 +3169,7 @@ If KEEP-DATE is non-nil, preserve the time stamp when copying."
        multi-method method user host
        (format " %s %s"
               (if parents "mkdir -p" "mkdir")
-              (tramp-shell-quote-argument path))
+              (tramp-shell-quote-argument localname))
        nil 'file-error
        "Couldn't make directory %s" dir))))
 
@@ -2618,7 +3182,7 @@ If KEEP-DATE is non-nil, preserve the time stamp when copying."
       (tramp-send-command
        multi-method method user host
        (format "rmdir %s ; echo ok"
-              (tramp-shell-quote-argument path)))
+              (tramp-shell-quote-argument localname)))
       (tramp-wait-for-output))))
 
 (defun tramp-handle-delete-file (filename)
@@ -2629,7 +3193,7 @@ If KEEP-DATE is non-nil, preserve the time stamp when copying."
       (unless (zerop (tramp-send-command-and-check
                      multi-method method user host
                      (format "rm -f %s"
-                             (tramp-shell-quote-argument path))))
+                             (tramp-shell-quote-argument localname))))
        (signal 'file-error "Couldn't delete Tramp file")))))
 
 ;; Dired.
@@ -2640,22 +3204,21 @@ If KEEP-DATE is non-nil, preserve the time stamp when copying."
   "Recursively delete the directory given.
 This is like `dired-recursive-delete-directory' for tramp files."
   (with-parsed-tramp-file-name filename nil
-    ;; run a shell command 'rm -r <path>'
+    ;; run a shell command 'rm -r <localname>'
     ;; Code shamelessly stolen for the dired implementation and, um, hacked :)
-    (or (tramp-handle-file-exists-p filename)
+    (or (file-exists-p filename)
        (signal
         'file-error
         (list "Removing old file name" "no such directory" filename)))
     ;; Which is better, -r or -R? (-r works for me <daniel@danann.net>)
-    (tramp-send-command multi-method method user host 
-                       (format "rm -r %s" (tramp-shell-quote-argument path)))
+    (tramp-send-command multi-method method user host
+                       (format "rm -r %s" (tramp-shell-quote-argument localname)))
     ;; Wait for the remote system to return to us...
     ;; This might take a while, allow it plenty of time.
     (tramp-wait-for-output 120)
     ;; Make sure that it worked...
-    (and (tramp-handle-file-exists-p filename)
-        (error "Failed to recusively delete %s" filename))))
-        
+    (and (file-exists-p filename)
+        (error "Failed to recursively delete %s" filename))))
 
 (defun tramp-handle-dired-call-process (program discard &rest arguments)
   "Like `dired-call-process' for tramp files."
@@ -2663,10 +3226,10 @@ This is like `dired-recursive-delete-directory' for tramp files."
     (save-excursion
       (tramp-barf-unless-okay
        multi-method method user host
-       (format "cd %s" (tramp-shell-quote-argument path))
+       (format "cd %s" (tramp-shell-quote-argument localname))
        nil 'file-error
        "tramp-handle-dired-call-process: Couldn't `cd %s'"
-       (tramp-shell-quote-argument path))
+       (tramp-shell-quote-argument localname))
       (tramp-send-command
        multi-method method user host
        (mapconcat #'tramp-shell-quote-argument (cons program arguments) " "))
@@ -2679,6 +3242,61 @@ This is like `dired-recursive-delete-directory' for tramp files."
        (tramp-send-command multi-method method user host "cd")
        (tramp-wait-for-output)))))
 
+(defun tramp-handle-dired-compress-file (file &rest ok-flag)
+  "Like `dired-compress-file' for tramp files."
+  ;; OK-FLAG is valid for XEmacs only, but not implemented.
+  ;; Code stolen mainly from dired-aux.el.
+  (with-parsed-tramp-file-name file nil
+    (save-excursion
+      (let ((suffixes
+            (if (not (featurep 'xemacs))
+                ;; Emacs case
+                (symbol-value 'dired-compress-file-suffixes)
+              ;; XEmacs has `dired-compression-method-alist', which is
+              ;; transformed into `dired-compress-file-suffixes' structure.
+              (mapcar
+               '(lambda (x)
+                  (list (concat (regexp-quote (nth 1 x)) "\\'")
+                        nil
+                        (mapconcat 'identity (nth 3 x) " ")))
+               (symbol-value 'dired-compression-method-alist))))
+           suffix)
+       ;; See if any suffix rule matches this file name.
+       (while suffixes
+         (let (case-fold-search)
+           (if (string-match (car (car suffixes)) localname)
+               (setq suffix (car suffixes) suffixes nil))
+           (setq suffixes (cdr suffixes))))
+
+       (cond ((file-symlink-p file)
+              nil)
+             ((and suffix (nth 2 suffix))
+              ;; We found an uncompression rule.
+              (message "Uncompressing %s..." file)
+              (when (zerop (tramp-send-command-and-check
+                            multi-method method user host
+                            (concat (nth 2 suffix) " " localname)))
+                (message "Uncompressing %s...done" file)
+                ;; `dired-remove-file' is not defined in XEmacs
+                (funcall (symbol-function 'dired-remove-file) file)
+                (string-match (car suffix) file)
+                (concat (substring file 0 (match-beginning 0)))))
+             (t
+              ;; We don't recognize the file as compressed, so compress it.
+              ;; Try gzip.
+              (message "Compressing %s..." file)
+              (when (zerop (tramp-send-command-and-check
+                            multi-method method user host
+                            (concat "gzip -f " localname)))
+                (message "Compressing %s...done" file)
+                ;; `dired-remove-file' is not defined in XEmacs
+                (funcall (symbol-function 'dired-remove-file) file)
+                (cond ((file-exists-p (concat file ".gz"))
+                       (concat file ".gz"))
+                      ((file-exists-p (concat file ".z"))
+                       (concat file ".z"))
+                      (t nil)))))))))
+
 ;; Pacify byte-compiler.  The function is needed on XEmacs only.  I'm
 ;; not sure at all that this is the right way to do it, but let's hope
 ;; it works for now, and wait for a guru to point out the Right Way to
@@ -2695,78 +3313,87 @@ This is like `dired-recursive-delete-directory' for tramp files."
 (defun tramp-handle-insert-directory
   (filename switches &optional wildcard full-directory-p)
   "Like `insert-directory' for tramp files."
-  ;; For the moment, we assume that the remote "ls" program does not
-  ;; grok "--dired".  In the future, we should detect this on
-  ;; connection setup.
-  (when (string-match "^--dired\\s-+" switches)
-    (setq switches (replace-match "" nil t switches)))
-  (setq filename (expand-file-name filename))
-  (with-parsed-tramp-file-name filename nil
-    (tramp-message-for-buffer
-     multi-method method user host 10
-     "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
-     switches filename (if wildcard "yes" "no")
-     (if full-directory-p "yes" "no"))
-    (when wildcard
-      (setq wildcard (file-name-nondirectory path))
-      (setq path (file-name-directory path)))
-    (when (listp switches)
-      (setq switches (mapconcat 'identity switches " ")))
-    (unless full-directory-p
-      (setq switches (concat "-d " switches)))
-    (when wildcard
-      (setq switches (concat switches " " wildcard)))
-    (save-excursion
-      ;; If `full-directory-p', we just say `ls -l FILENAME'.
-      ;; Else we chdir to the parent directory, then say `ls -ld BASENAME'.
-      (if full-directory-p
-         (tramp-send-command
-          multi-method method user host
-          (format "%s %s %s"
-                  (tramp-get-ls-command multi-method method user host)
-                  switches
-                  (if wildcard
-                      path
-                    (tramp-shell-quote-argument (concat path ".")))))
-       (tramp-barf-unless-okay
-        multi-method method user host
-        (format "cd %s" (tramp-shell-quote-argument
-                         (file-name-directory path)))
-        nil 'file-error
-        "Couldn't `cd %s'"
-        (tramp-shell-quote-argument (file-name-directory path)))
-       (tramp-send-command
-        multi-method method user host
-        (format "%s %s %s"
-                (tramp-get-ls-command multi-method method user host)
-                switches
-                (if full-directory-p
-                    ;; Add "/." to make sure we got complete dir
-                    ;; listing for symlinks, too.
-                    (concat (file-name-as-directory
-                             (file-name-nondirectory path)) ".")
-                  (file-name-nondirectory path)))))
-      (sit-for 1)                      ;needed for rsh but not ssh?
-      (tramp-wait-for-output))
-    (let ((old-pos (point)))
-      (insert-buffer-substring
-       (tramp-get-buffer multi-method method user host))
-      ;; On XEmacs, we want to call (exchange-point-and-mark t), but
-      ;; that doesn't exist on Emacs, so we use this workaround instead.
-      ;; Since zmacs-region-stays doesn't exist in Emacs, this ought to
-      ;; be safe.  Thanks to Daniel Pittman <daniel@danann.net>.
-      ;;     (let ((zmacs-region-stays t))
-      ;;       (exchange-point-and-mark))
+  (if (and (boundp 'ls-lisp-use-insert-directory-program)
+           (not ls-lisp-use-insert-directory-program))
+      (tramp-run-real-handler 'insert-directory
+                              (list filename switches wildcard full-directory-p))
+    ;; For the moment, we assume that the remote "ls" program does not
+    ;; grok "--dired".  In the future, we should detect this on
+    ;; connection setup.
+    (when (string-match "^--dired\\s-+" switches)
+      (setq switches (replace-match "" nil t switches)))
+    (setq filename (expand-file-name filename))
+    (with-parsed-tramp-file-name filename nil
+      (tramp-message-for-buffer
+       multi-method method user host 10
+       "Inserting directory `ls %s %s', wildcard %s, fulldir %s"
+       switches filename (if wildcard "yes" "no")
+       (if full-directory-p "yes" "no"))
+      (when wildcard
+        (setq wildcard (file-name-nondirectory localname))
+        (setq localname (file-name-directory localname)))
+      (when (listp switches)
+        (setq switches (mapconcat 'identity switches " ")))
+      (unless full-directory-p
+        (setq switches (concat "-d " switches)))
+      (when wildcard
+        (setq switches (concat switches " " wildcard)))
       (save-excursion
-       (tramp-send-command multi-method method user host "cd")
-       (tramp-wait-for-output))
-      ;; Another XEmacs specialty follows.  What's the right way to do
-      ;; it?
-      (when (and (featurep 'xemacs)
-                (eq major-mode 'dired-mode))
-       (save-excursion
-         (require 'dired)
-         (dired-insert-set-properties old-pos (point)))))))
+        ;; If `full-directory-p', we just say `ls -l FILENAME'.
+        ;; Else we chdir to the parent directory, then say `ls -ld BASENAME'.
+        (if full-directory-p
+            (tramp-send-command
+             multi-method method user host
+             (format "%s %s %s"
+                     (tramp-get-ls-command multi-method method user host)
+                     switches
+                     (if wildcard
+                         localname
+                       (tramp-shell-quote-argument (concat localname ".")))))
+          (tramp-barf-unless-okay
+           multi-method method user host
+           (format "cd %s" (tramp-shell-quote-argument
+                            (file-name-directory localname)))
+           nil 'file-error
+           "Couldn't `cd %s'"
+           (tramp-shell-quote-argument (file-name-directory localname)))
+          (tramp-send-command
+           multi-method method user host
+           (format "%s %s %s"
+                   (tramp-get-ls-command multi-method method user host)
+                   switches
+                   (if wildcard
+                       localname
+                     (tramp-shell-quote-argument
+                      (file-name-nondirectory localname))))))
+        (sit-for 1)                    ;needed for rsh but not ssh?
+        (tramp-wait-for-output))
+      ;; The following let-binding is used by code that's commented
+      ;; out.  Let's leave the let-binding in for a while to see
+      ;; that the commented-out code is really not needed.  Commenting-out
+      ;; happened on 2003-03-13.
+      (let ((old-pos (point)))
+        (insert-buffer-substring
+         (tramp-get-buffer multi-method method user host))
+        ;; On XEmacs, we want to call (exchange-point-and-mark t), but
+        ;; that doesn't exist on Emacs, so we use this workaround instead.
+        ;; Since zmacs-region-stays doesn't exist in Emacs, this ought to
+        ;; be safe.  Thanks to Daniel Pittman <daniel@danann.net>.
+        ;;     (let ((zmacs-region-stays t))
+        ;;       (exchange-point-and-mark))
+        (save-excursion
+          (tramp-send-command multi-method method user host "cd")
+          (tramp-wait-for-output))
+        ;; For the time being, the XEmacs kludge is commented out.
+        ;; Please test it on various XEmacs versions to see if it works.
+        ;;       ;; Another XEmacs specialty follows.  What's the right way to do
+        ;;       ;; it?
+        ;;       (when (and (featurep 'xemacs)
+        ;;              (eq major-mode 'dired-mode))
+        ;;     (save-excursion
+        ;;       (require 'dired)
+        ;;       (dired-insert-set-properties old-pos (point))))
+        ))))
 
 ;; Continuation of kluge to pacify byte-compiler.
 ;;(eval-when-compile
@@ -2798,7 +3425,9 @@ Doesn't do anything if the NAME does not start with a drive letter."
     name))
 
 (defun tramp-handle-expand-file-name (name &optional dir)
-  "Like `expand-file-name' for tramp files."
+  "Like `expand-file-name' for tramp files.
+If the localname part of the given filename starts with \"/../\" then
+the result will be a local, non-Tramp, filename."
   ;; If DIR is not given, use DEFAULT-DIRECTORY or "/".
   (setq dir (or dir default-directory "/"))
   ;; Unless NAME is absolute, concat DIR and NAME.
@@ -2810,16 +3439,16 @@ Doesn't do anything if the NAME does not start with a drive letter."
                               (list name nil))
     ;; Dissect NAME.
     (with-parsed-tramp-file-name name nil
-      (unless (file-name-absolute-p path)
-       (setq path (concat "~/" path)))
+      (unless (file-name-absolute-p localname)
+       (setq localname (concat "~/" localname)))
       (save-excursion
        ;; Tilde expansion if necessary.  This needs a shell which
        ;; groks tilde expansion!  The function `tramp-find-shell' is
        ;; supposed to find such a shell on the remote host.  Please
        ;; tell me about it when this doesn't work on your system.
-       (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" path)
-         (let ((uname (match-string 1 path))
-               (fname (match-string 2 path)))
+       (when (string-match "\\`\\(~[^/]*\\)\\(.*\\)\\'" localname)
+         (let ((uname (match-string 1 localname))
+               (fname (match-string 2 localname)))
            ;; CCC fanatic error checking?
            (set-buffer (tramp-get-buffer multi-method method user host))
            (erase-buffer)
@@ -2830,64 +3459,140 @@ Doesn't do anything if the NAME does not start with a drive letter."
            (tramp-wait-for-output)
            (goto-char (point-min))
            (setq uname (buffer-substring (point) (tramp-line-end-position)))
-           (setq path (concat uname fname))
+           (setq localname (concat uname fname))
            (erase-buffer)))
        ;; No tilde characters in file name, do normal
        ;; expand-file-name (this does "/./" and "/../").  We bind
-       ;; directory-sep-char here for XEmacs on Windows, which would
-       ;; otherwise use backslash.
-       (let ((directory-sep-char ?/))
+       ;; directory-sep-char here for XEmacs on Windows, which
+       ;; would otherwise use backslash.
+       (tramp-let-maybe directory-sep-char ?/
          (tramp-make-tramp-file-name
-          multi-method method user host
+          multi-method (or method (tramp-find-default-method user host))
+          user host
           (tramp-drop-volume-letter
-           (tramp-run-real-handler 'expand-file-name (list path)))))))))
+           (tramp-run-real-handler 'expand-file-name
+                                   (list localname)))))))))
+
+;; old version follows.  it uses ".." to cross file handler
+;; boundaries.
+;;     ;; Look if localname starts with "/../" construct.  If this is
+;;     ;; the case, then we return a local name instead of a remote name.
+;;     (if (string-match "^/\\.\\./" localname)
+;;         (expand-file-name (substring localname 3))
+;;       ;; No tilde characters in file name, do normal
+;;       ;; expand-file-name (this does "/./" and "/../").  We bind
+;;       ;; directory-sep-char here for XEmacs on Windows, which
+;;       ;; would otherwise use backslash.
+;;       (let ((directory-sep-char ?/))
+;;         (tramp-make-tramp-file-name
+;;          multi-method method user host
+;;          (tramp-drop-volume-letter
+;;           (tramp-run-real-handler 'expand-file-name
+;;                                   (list localname))))))))))
 
 ;; Remote commands.
 
+(defvar tramp-async-proc nil
+  "Global variable keeping asyncronous process object.
+Used in `tramp-handle-shell-command'")
+
 (defun tramp-handle-shell-command (command &optional output-buffer error-buffer)
   "Like `shell-command' for tramp files.
 This will break if COMMAND prints a newline, followed by the value of
 `tramp-end-of-output', followed by another newline."
+  ;; Asynchronous processes are far from being perfect.  But it works at least
+  ;; for `find-grep-dired' and `find-name-dired' in Emacs 22.1.
   (if (tramp-tramp-file-p default-directory)
       (with-parsed-tramp-file-name default-directory nil
-       (let (status)
-         (when (string-match "&[ \t]*\\'" command)
-           (error "Tramp doesn't grok asynchronous shell commands, yet"))
-         (when error-buffer
-           (error "Tramp doesn't grok optional third arg ERROR-BUFFER, yet"))
-         (save-excursion
-           (tramp-barf-unless-okay
-            multi-method method user host
-            (format "cd %s" (tramp-shell-quote-argument path))
-            nil 'file-error
-            "tramp-handle-shell-command: Couldn't `cd %s'"
-            (tramp-shell-quote-argument path))
-           (tramp-send-command multi-method method user host
-                               (concat command "; tramp_old_status=$?"))
-           ;; This will break if the shell command prints "/////"
-           ;; somewhere.  Let's just hope for the best...
-           (tramp-wait-for-output))
+       (let ((asynchronous (string-match "[ \t]*&[ \t]*\\'" command))
+             status)
          (unless output-buffer
-           (setq output-buffer (get-buffer-create "*Shell Command Output*"))
+           (setq output-buffer
+                 (get-buffer-create
+                  (if asynchronous
+                      "*Async Shell Command*"
+                    "*Shell Command Output*")))
            (set-buffer output-buffer)
            (erase-buffer))
          (unless (bufferp output-buffer)
            (setq output-buffer (current-buffer)))
          (set-buffer output-buffer)
-         (insert-buffer (tramp-get-buffer multi-method method user host))
+         ;; Tramp doesn't handle the asynchronous case by an asynchronous
+         ;; process.  Instead of, another asynchronous process is opened
+         ;; which gets the output of the (synchronous) Tramp process
+         ;; via process-filter.  ERROR-BUFFER is disabled.
+         (when asynchronous
+           (setq command (substring command 0 (match-beginning 0))
+                 error-buffer nil
+                 tramp-async-proc (start-process (buffer-name output-buffer)
+                                                 output-buffer "cat")))
+         (save-excursion
+           (tramp-barf-unless-okay
+            multi-method method user host
+            (format "cd %s" (tramp-shell-quote-argument localname))
+            nil 'file-error
+            "tramp-handle-shell-command: Couldn't `cd %s'"
+            (tramp-shell-quote-argument localname))
+           ;; Define the process filter
+           (when asynchronous
+             (set-process-filter
+              (get-buffer-process
+               (tramp-get-buffer multi-method method user host))
+              '(lambda (process string)
+                 ;; Write the output into the Tramp Process
+                 (save-current-buffer
+                   (set-buffer (process-buffer process))
+                   (goto-char (point-max))
+                   (insert string))
+                 ;; Hand-over output to asynchronous process.
+                 (let ((end
+                        (string-match
+                         (regexp-quote tramp-end-of-output) string)))
+                   (when end
+                     (setq string
+                           (substring string 0 (1- (match-beginning 0)))))
+                   (process-send-string tramp-async-proc string)
+                   (when end
+                     (set-process-filter process nil)
+                     (process-send-eof tramp-async-proc))))))
+           ;; Send the command
+           (tramp-send-command
+            multi-method method user host
+            (if error-buffer
+                (format "( %s ) 2>/tmp/tramp.$$.err; tramp_old_status=$?"
+                        command)
+              (format "%s; tramp_old_status=$?" command)))
+           (unless asynchronous
+             (tramp-wait-for-output)))
+         (unless asynchronous
+           (insert-buffer (tramp-get-buffer multi-method method user host)))
+         (when error-buffer
+           (save-excursion
+             (unless (bufferp error-buffer)
+               (setq error-buffer (get-buffer-create error-buffer)))
+             (tramp-send-command
+              multi-method method user host
+              "cat /tmp/tramp.$$.err")
+             (tramp-wait-for-output)
+             (set-buffer error-buffer)
+             (insert-buffer (tramp-get-buffer multi-method method user host))
+             (tramp-send-command-and-check
+              multi-method method user host "rm -f /tmp/tramp.$$.err")))
          (save-excursion
            (tramp-send-command multi-method method user host "cd")
-           (tramp-wait-for-output)
+           (unless asynchronous
+             (tramp-wait-for-output))
            (tramp-send-command
             multi-method method user host
             (concat "tramp_set_exit_status $tramp_old_status;"
                     " echo tramp_exit_status $?"))
-           (tramp-wait-for-output)
-           (goto-char (point-max))
-           (unless (search-backward "tramp_exit_status " nil t)
-             (error "Couldn't find exit status of `%s'" command))
-           (skip-chars-forward "^ ")
-           (setq status (read (current-buffer))))
+           (unless asynchronous
+             (tramp-wait-for-output)
+             (goto-char (point-max))
+             (unless (search-backward "tramp_exit_status " nil t)
+               (error "Couldn't find exit status of `%s'" command))
+             (skip-chars-forward "^ ")
+             (setq status (read (current-buffer)))))
          (unless (zerop (buffer-size))
            (display-buffer output-buffer))
          status))
@@ -2898,6 +3603,18 @@ This will break if COMMAND prints a newline, followed by the value of
     (tramp-run-real-handler 'shell-command
                            (list command output-buffer error-buffer))))
 
+(defun tramp-handle-process-file (program &optional infile buffer display &rest args)
+  "Like `process-file' for Tramp files."
+  (when infile (error "Implementation does not handle input from file"))
+  (when (and (numberp buffer) (zerop buffer))
+    (error "Implementation does not handle immediate return"))
+  (when (consp buffer) (error "Implementation does not handle error files"))
+  (shell-command
+   (mapconcat 'tramp-shell-quote-argument
+              (cons program args)
+              " ")
+   buffer))
+
 ;; File Editing.
 
 (defsubst tramp-make-temp-file ()
@@ -2908,16 +3625,7 @@ This will break if COMMAND prints a newline, followed by the value of
 (defun tramp-handle-file-local-copy (filename)
   "Like `file-local-copy' for tramp files."
   (with-parsed-tramp-file-name filename nil
-    (let ((output-buf (get-buffer-create "*tramp output*"))
-         (tramp-buf (tramp-get-buffer multi-method method user host))
-         (rcp-program (tramp-get-rcp-program
-                       multi-method
-                       (tramp-find-method multi-method method user host)
-                       user host))
-         (rcp-args (tramp-get-rcp-args
-                    multi-method
-                    (tramp-find-method multi-method method user host)
-                    user host))
+    (let ((tramp-buf (tramp-get-buffer multi-method method user host))
          ;; We used to bind the following as late as possible.
          ;; loc-enc and loc-dec were bound directly before the if
          ;; statement that checks them.  But the functions
@@ -2933,31 +3641,11 @@ This will break if COMMAND prints a newline, followed by the value of
        (error "Cannot make local copy of non-existing file `%s'"
               filename))
       (setq tmpfil (tramp-make-temp-file))
-      (cond (rcp-program
-            ;; Use rcp-like program for file transfer.
-            (tramp-message-for-buffer
-             multi-method method user host
-             5 "Fetching %s to tmp file %s..." filename tmpfil)
-            (save-excursion (set-buffer output-buf) (erase-buffer))
-            (unless (equal
-                     0
-                     (apply #'call-process
-                            rcp-program
-                            nil output-buf nil
-                            (append rcp-args
-                                    (list
-                                     (tramp-make-rcp-program-file-name
-                                      user host
-                                      (tramp-shell-quote-argument path))
-                                     tmpfil))))
-              (pop-to-buffer output-buf)
-              (error
-               (concat "tramp-handle-file-local-copy: `%s' didn't work, "
-                       "see buffer `%s' for details")
-               rcp-program output-buf))
-            (tramp-message-for-buffer
-             multi-method method user host
-             5 "Fetching %s to tmp file %s...done" filename tmpfil))
+
+      (cond ((tramp-method-out-of-band-p multi-method method user host)
+            ;; `copy-file' handles out-of-band methods
+            (copy-file filename tmpfil t t))
+
            ((and rem-enc rem-dec)
             ;; Use inline encoding for file transfer.
             (save-excursion
@@ -2967,7 +3655,7 @@ This will break if COMMAND prints a newline, followed by the value of
               (tramp-message 5 "Encoding remote file %s..." filename)
               (tramp-barf-unless-okay
                multi-method method user host
-               (concat rem-enc " < " (tramp-shell-quote-argument path))
+               (concat rem-enc " < " (tramp-shell-quote-argument localname))
                nil 'file-error
                "Encoding remote file failed, see buffer `%s' for details"
                tramp-buf)
@@ -2994,7 +3682,7 @@ This will break if COMMAND prints a newline, followed by the value of
                     ;; line from the output here.  Go to point-max,
                     ;; search backward for tramp_exit_status, delete
                     ;; between point and point-max if found.
-                    (let ((coding-system-for-write 'no-conversion))
+                    (let ((coding-system-for-write 'binary))
                       (funcall loc-dec (point-min) (point-max))
                       (write-region (point-min) (point-max) tmpfil))
                     (kill-buffer tmpbuf))
@@ -3010,11 +3698,23 @@ This will break if COMMAND prints a newline, followed by the value of
                   (delete-file tmpfil2)))
               (tramp-message-for-buffer
                multi-method method user host
-               5 "Decoding remote file %s...done" filename)))
+               5 "Decoding remote file %s...done" filename)
+              ;; Set proper permissions.
+              (set-file-modes tmpfil (file-modes filename))))
 
            (t (error "Wrong method specification for `%s'" method)))
       tmpfil)))
 
+(defun tramp-handle-file-remote-p (filename)
+  "Like `file-remote-p' for tramp files."
+  (when (tramp-tramp-file-p filename)
+    (with-parsed-tramp-file-name filename nil
+      (make-tramp-file-name
+       :multi-method multi-method
+       :method method
+       :user user
+       :host host
+       :localname ""))))
 
 (defun tramp-handle-insert-file-contents
   (filename &optional visit beg end replace)
@@ -3031,7 +3731,15 @@ This will break if COMMAND prints a newline, followed by the value of
          (signal 'file-error
                  (format "File `%s' not found on remote host" filename))
          (list (expand-file-name filename) 0))
-      (let ((local-copy (file-local-copy filename))
+      ;; `insert-file-contents-literally' takes care to avoid calling
+      ;; jka-compr.  By let-binding inhibit-file-name-operation, we
+      ;; propagate that care to the file-local-copy operation.
+      (let ((local-copy
+            (let ((inhibit-file-name-operation
+                   (when (eq inhibit-file-name-operation
+                             'insert-file-contents)
+                     'file-local-copy)))
+              (file-local-copy filename)))
            (coding-system-used nil)
            (result nil))
        (when visit
@@ -3054,6 +3762,51 @@ This will break if COMMAND prints a newline, followed by the value of
        (list (expand-file-name filename)
              (second result))))))
 
+
+(defun tramp-handle-find-backup-file-name (filename)
+  "Like `find-backup-file-name' for tramp files."
+  (with-parsed-tramp-file-name filename nil
+    ;; We set both variables. It doesn't matter whether it is
+    ;; Emacs or XEmacs
+    (let ((backup-directory-alist
+          ;; Emacs case
+          (when (boundp 'backup-directory-alist)
+            (if (boundp 'tramp-backup-directory-alist)
+                (mapcar
+                 '(lambda (x)
+                    (cons
+                     (car x)
+                     (if (and (stringp (cdr x))
+                              (file-name-absolute-p (cdr x))
+                              (not (tramp-file-name-p (cdr x))))
+                         (tramp-make-tramp-file-name
+                          multi-method method user host (cdr x))
+                       (cdr x))))
+                 (symbol-value 'tramp-backup-directory-alist))
+              (symbol-value 'backup-directory-alist))))
+
+         (bkup-backup-directory-info
+          ;; XEmacs case
+          (when (boundp 'bkup-backup-directory-info)
+            (if (boundp 'tramp-bkup-backup-directory-info)
+                (mapcar
+                 '(lambda (x)
+                    (nconc
+                     (list (car x))
+                     (list
+                      (if (and (stringp (car (cdr x)))
+                               (file-name-absolute-p (car (cdr x)))
+                               (not (tramp-file-name-p (car (cdr x)))))
+                          (tramp-make-tramp-file-name
+                           multi-method method user host (car (cdr x)))
+                        (car (cdr x))))
+                     (cdr (cdr x))))
+                 (symbol-value 'tramp-bkup-backup-directory-info))
+              (symbol-value 'bkup-backup-directory-info)))))
+
+      (tramp-run-real-handler 'find-backup-file-name (list filename)))))
+
+
 ;; CCC grok APPEND, LOCKNAME, CONFIRM
 (defun tramp-handle-write-region
   (start end filename &optional append visit lockname confirm)
@@ -3078,18 +3831,12 @@ This will break if COMMAND prints a newline, followed by the value of
       (error "File not overwritten")))
   (with-parsed-tramp-file-name filename nil
     (let ((curbuf (current-buffer))
-         (rcp-program (tramp-get-rcp-program
-                       multi-method (tramp-find-method multi-method method user host)
-                       user host))
-         (rcp-args (tramp-get-rcp-args
-                    multi-method
-                    (tramp-find-method multi-method method user host)
-                    user host))
          (rem-enc (tramp-get-remote-encoding multi-method method user host))
          (rem-dec (tramp-get-remote-decoding multi-method method user host))
          (loc-enc (tramp-get-local-encoding multi-method method user host))
          (loc-dec (tramp-get-local-decoding multi-method method user host))
          (trampbuf (get-buffer-create "*tramp output*"))
+         (modes (file-modes filename))
          ;; We use this to save the value of `last-coding-system-used'
          ;; after writing the tmp file.  At the end of the function,
          ;; we set `last-coding-system-used' to this saved value.
@@ -3102,6 +3849,9 @@ This will break if COMMAND prints a newline, followed by the value of
       ;; use an encoding function, but currently we use it always
       ;; because this makes the logic simpler.
       (setq tmpfil (tramp-make-temp-file))
+      ;; Set current buffer.  If connection wasn't open, `file-modes' has
+      ;; changed it accidently.
+      (set-buffer curbuf)
       ;; We say `no-message' here because we don't want the visited file
       ;; modtime data to be clobbered from the temp file.  We call
       ;; `set-visited-file-modtime' ourselves later on.
@@ -3110,6 +3860,11 @@ This will break if COMMAND prints a newline, followed by the value of
        (if confirm ; don't pass this arg unless defined for backward compat.
           (list start end tmpfil append 'no-message lockname confirm)
         (list start end tmpfil append 'no-message lockname)))
+      ;; The permissions of the temporary file should be set.  If
+      ;; filename does not exist (eq modes nil) it has been renamed to
+      ;; the backup file.  This case `save-buffer' handles
+      ;; permissions.
+      (when modes (set-file-modes tmpfil modes))
       ;; Now, `last-coding-system-used' has the right value.  Remember it.
       (when (boundp 'last-coding-system-used)
        (setq coding-system-used last-coding-system-used))
@@ -3119,37 +3874,10 @@ This will break if COMMAND prints a newline, followed by the value of
       ;; decoding command must be specified.  However, if the method
       ;; _also_ specifies an encoding function, then that is used for
       ;; encoding the contents of the tmp file.
-      (cond (rcp-program
-            ;; use rcp-like program for file transfer
-            (let ((argl (append rcp-args
-                                (list
-                                 tmpfil
-                                 (tramp-make-rcp-program-file-name
-                                  user host
-                                  (tramp-shell-quote-argument path))))))
-              (tramp-message-for-buffer
-               multi-method method user host
-               6 "Writing tmp file using `%s'..." rcp-program)
-              (save-excursion (set-buffer trampbuf) (erase-buffer))
-              (when tramp-debug-buffer
-                (save-excursion
-                  (set-buffer (tramp-get-debug-buffer multi-method
-                                                      method user host))
-                  (goto-char (point-max))
-                  (tramp-insert-with-face
-                   'bold (format "$ %s %s\n" rcp-program
-                                 (mapconcat 'identity argl " ")))))
-              (unless (equal 0
-                             (apply #'call-process
-                                    rcp-program nil trampbuf nil argl))
-                (pop-to-buffer trampbuf)
-                (error
-                 "Cannot write region to file `%s', command `%s' failed"
-                 filename rcp-program))
-              (tramp-message-for-buffer
-               multi-method method user host
-               6 "Transferring file using `%s'...done"
-               rcp-program)))
+      (cond ((tramp-method-out-of-band-p multi-method method user host)
+            ;; `copy-file' handles out-of-band methods
+            (copy-file tmpfil filename t t))
+
            ((and rem-enc rem-dec)
             ;; Use inline file transfer
             (let ((tmpbuf (get-buffer-create " *tramp file transfer*")))
@@ -3164,7 +3892,8 @@ This will break if COMMAND prints a newline, followed by the value of
                     (progn
                       (tramp-message-for-buffer
                        multi-method method user host
-                       6 "Encoding region using function...")
+                       6 "Encoding region using function `%s'..."
+                       (symbol-name loc-enc))
                       (insert-file-contents-literally tmpfil)
                       ;; CCC.  The following `let' is a workaround for
                       ;; the base64.el that comes with pgnus-0.84.  If
@@ -3200,13 +3929,13 @@ This will break if COMMAND prints a newline, followed by the value of
                  multi-method method user host
                  (format "%s >%s <<'EOF'"
                          rem-dec
-                         (tramp-shell-quote-argument path)))
+                         (tramp-shell-quote-argument localname)))
                 (set-buffer tmpbuf)
                 (tramp-message-for-buffer
                  multi-method method user host
                  6 "Sending data to remote host...")
-                (tramp-send-region multi-method method user host
-                                   (point-min) (point-max))
+                (tramp-send-string multi-method method user host
+                                   (buffer-string))
                 ;; wait for remote decoding to complete
                 (tramp-message-for-buffer
                  multi-method method user host
@@ -3235,8 +3964,11 @@ This will break if COMMAND prints a newline, followed by the value of
       (unless (equal curbuf (current-buffer))
        (error "Buffer has changed from `%s' to `%s'"
               curbuf (current-buffer)))
-      (when (eq visit t)
-       (set-visited-file-modtime))
+      (when (or (eq visit t) (stringp visit))
+       (set-visited-file-modtime
+        ;; We must pass modtime explicitely, because filename can be different
+        ;; from (buffer-file-name), f.e. if `file-precious-flag' is set.
+        (nth 5 (file-attributes filename))))
       ;; Make `last-coding-system-used' have the right value.
       (when (boundp 'last-coding-system-used)
        (setq last-coding-system-used coding-system-used))
@@ -3246,17 +3978,17 @@ This will break if COMMAND prints a newline, followed by the value of
        (message "Wrote %s" filename)))))
 
 ;; Call down to the real handler.
-;; Because EFS does not play nicely with TRAMP (both systems match an
-;; TRAMP path) it is needed to disable efs as well as tramp for the
+;; Because EFS does not play nicely with TRAMP (both systems match a
+;; TRAMP file name) it is needed to disable efs as well as tramp for the
 ;; operation.
 ;;
 ;; Other than that, this is the canon file-handler code that the doco
 ;; says should be used here. Which is nice.
 ;;
 ;; Under XEmacs current, EFS also hooks in as
-;; efs-sifn-handler-function to handle any path with environment
+;; efs-sifn-handler-function to handle any filename with environment
 ;; variables. This has two implications:
-;; 1) That EFS may not be completely dead (yet) for TRAMP paths
+;; 1) That EFS may not be completely dead (yet) for TRAMP filenames
 ;; 2) That TRAMP might want to do the same thing.
 ;; Details as they come in.
 ;;
@@ -3311,10 +4043,10 @@ pass to the OPERATION."
 
 ;; We handle here all file primitives.  Most of them have the file
 ;; name as first parameter; nevertheless we check for them explicitly
-;; in order to be be signalled if a new primitive appears.  This
+;; in order to be signalled if a new primitive appears.  This
 ;; scenario is needed because there isn't a way to decide by
 ;; syntactical means whether a foreign method must be called.  It would
-;; ease the live if `file-name-handler-alist' would support a decision
+;; ease the life if `file-name-handler-alist' would support a decision
 ;; function as well but regexp only.
 (defun tramp-file-name-for-operation (operation &rest args)
   "Return file name related to OPERATION file primitive.
@@ -3328,16 +4060,16 @@ ARGS are the arguments OPERATION has been called with."
                  'dired-compress-file 'dired-uncache
                  'file-accessible-directory-p 'file-attributes
                  'file-directory-p 'file-executable-p 'file-exists-p
-                 'file-local-copy 'file-modes 'file-name-as-directory
-                 'file-name-directory 'file-name-nondirectory
-                 'file-name-sans-versions 'file-ownership-preserved-p
-                 'file-readable-p 'file-regular-p 'file-symlink-p
-                 'file-truename 'file-writable-p 'find-backup-file-name
-                 'find-file-noselect 'get-file-buffer 'insert-directory
-                 'insert-file-contents 'load 'make-directory
-                 'make-directory-internal 'set-file-modes
-                 'substitute-in-file-name 'unhandled-file-name-directory
-                 'vc-registered
+                 'file-local-copy 'file-remote-p 'file-modes
+                 'file-name-as-directory 'file-name-directory
+                 'file-name-nondirectory 'file-name-sans-versions
+                 'file-ownership-preserved-p 'file-readable-p
+                 'file-regular-p 'file-symlink-p 'file-truename
+                 'file-writable-p 'find-backup-file-name 'find-file-noselect
+                 'get-file-buffer 'insert-directory 'insert-file-contents
+                 'load 'make-directory 'make-directory-internal
+                 'set-file-modes 'substitute-in-file-name
+                 'unhandled-file-name-directory 'vc-registered
                  ; XEmacs only
                  'abbreviate-file-name 'create-file-buffer
                  'dired-file-modtime 'dired-make-compressed-filename
@@ -3345,7 +4077,9 @@ ARGS are the arguments OPERATION has been called with."
                  'dired-shell-unhandle-file-name 'dired-uucode-file
                  'insert-file-contents-literally 'recover-file
                  'vm-imap-check-mail 'vm-pop-check-mail 'vm-spool-check-mail))
-    (expand-file-name (nth 0 args)))
+    (if (file-name-absolute-p (nth 0 args))
+       (nth 0 args)
+      (expand-file-name (nth 0 args))))
    ; FILE DIRECTORY resp FILE1 FILE2
    ((member operation
            (list 'add-name-to-file 'copy-file 'expand-file-name
@@ -3371,7 +4105,11 @@ ARGS are the arguments OPERATION has been called with."
      (if (bufferp (nth 0 args)) (nth 0 args) (current-buffer))))
    ; COMMAND
    ((member operation
-           (list 'dired-call-process 'shell-command
+           (list 'dired-call-process-command
+                  ; Emacs only
+                 'shell
+                  ; Post Emacs 21.3 only
+                  'process-file
                  ; XEmacs only
                  'dired-print-file 'dired-shell-call-process))
     default-directory)
@@ -3380,27 +4118,74 @@ ARGS are the arguments OPERATION has been called with."
 
 (defun tramp-find-foreign-file-name-handler (filename)
   "Return foreign file name handler if exists."
-  (let (elt res)
-    (dolist (elt tramp-foreign-file-name-handler-alist res)
-      (when (funcall (car elt) filename)
-       (setq res (cdr elt))))
-    res))
+  (when (tramp-tramp-file-p filename)
+    (let (elt
+         res
+         (handler-alist tramp-foreign-file-name-handler-alist))
+      (while handler-alist
+       (setq elt (car handler-alist)
+             handler-alist (cdr handler-alist))
+       (when (funcall (car elt) filename)
+         (setq handler-alist nil)
+         (setq res (cdr elt))))
+      res)))
 
 ;; Main function.
 ;;;###autoload
 (defun tramp-file-name-handler (operation &rest args)
-  "Invoke tramp file name handler.
+  "Invoke Tramp file name handler.
 Falls back to normal file name handler if no tramp file name handler exists."
   (save-match-data
-    (let* ((fn (assoc operation tramp-file-name-handler-alist))
-          (filename (apply 'tramp-file-name-for-operation operation args))
+    (let* ((filename (apply 'tramp-file-name-for-operation operation args))
           (foreign (tramp-find-foreign-file-name-handler filename)))
       (cond
        (foreign (apply foreign operation args))
-       (fn (apply (cdr fn) args))
        (t (tramp-run-real-handler operation args))))))
 
-(put 'tramp-file-name-handler 'file-remote-p t)        ;for file-remote-p
+
+;; In Emacs, there is some concurrency due to timers.  If a timer
+;; interrupts Tramp and wishes to use the same connection buffer as
+;; the "main" Emacs, then garbage might occur in the connection
+;; buffer.  Therefore, we need to make sure that a timer does not use
+;; the same connection buffer as the "main" Emacs.  We implement a
+;; cheap global lock, instead of locking each connection buffer
+;; separately.  The global lock is based on two variables,
+;; `tramp-locked' and `tramp-locker'.  `tramp-locked' is set to true
+;; (with setq) to indicate a lock.  But Tramp also calls itself during
+;; processing of a single file operation, so we need to allow
+;; recursive calls.  That's where the `tramp-locker' variable comes in
+;; -- it is let-bound to t during the execution of the current
+;; handler.  So if `tramp-locked' is t and `tramp-locker' is also t,
+;; then we should just proceed because we have been called
+;; recursively.  But if `tramp-locker' is nil, then we are a timer
+;; interrupting the "main" Emacs, and then we signal an error.
+
+(defvar tramp-locked nil
+  "If non-nil, then Tramp is currently busy.
+Together with `tramp-locker', this implements a locking mechanism
+preventing reentrant calls of Tramp.")
+
+(defvar tramp-locker nil
+  "If non-nil, then a caller has locked Tramp.
+Together with `tramp-locked', this implements a locking mechanism
+preventing reentrant calls of Tramp.")
+
+(defun tramp-sh-file-name-handler (operation &rest args)
+  "Invoke remote-shell Tramp file name handler.
+Fall back to normal file name handler if no Tramp handler exists."
+  (when (and tramp-locked (not tramp-locker))
+    (signal 'file-error "Forbidden reentrant call of Tramp"))
+  (let ((tl tramp-locked))
+    (unwind-protect
+       (progn
+         (setq tramp-locked t)
+         (let ((tramp-locker t))
+           (save-match-data
+             (let ((fn (assoc operation tramp-file-name-handler-alist)))
+               (if fn
+                   (apply (cdr fn) args)
+                 (tramp-run-real-handler operation args))))))
+      (setq tramp-locked tl))))
 
 ;;;###autoload
 (defun tramp-completion-file-name-handler (operation &rest args)
@@ -3415,6 +4200,9 @@ Falls back to normal file name handler if no tramp file name handler exists."
        (save-match-data (apply (cdr fn) args))
       (tramp-completion-run-real-handler operation args))))
 
+;;;###autoload
+(put 'tramp-completion-file-name-handler 'safe-magic t)
+
 ;; Register in file name handler alist
 ;;;###autoload
 (add-to-list 'file-name-handler-alist
@@ -3425,7 +4213,7 @@ Falls back to normal file name handler if no tramp file name handler exists."
 
 (defun tramp-repair-jka-compr ()
   "If jka-compr is already loaded, move it to the front of
-`file-name-handler-alist'.  On Emacs 21.4 or so this will not be
+`file-name-handler-alist'.  On Emacs 22.1 or so this will not be
 necessary anymore."
   (let ((jka (rassoc 'jka-compr-handler file-name-handler-alist)))
     (when jka
@@ -3457,15 +4245,15 @@ necessary anymore."
              ;;-                       '(?\* ?\? ?[ ?]))))
              ;;-  (tramp-send-command
              ;;-   multi-method method user host
-             ;;-   (format "echo %s" (comint-quote-filename path)))
+             ;;-   (format "echo %s" (comint-quote-filename localname)))
              ;;-  (tramp-wait-for-output))
              (tramp-send-command multi-method method user host
-                                 (format "echo %s" path))
+                                 (format "echo %s" localname))
              (tramp-wait-for-output)
              (setq bufstr (buffer-substring (point-min)
                                             (tramp-line-end-position)))
              (goto-char (point-min))
-             (if (string-equal path bufstr)
+             (if (string-equal localname bufstr)
                  nil
                (insert "(\"")
                (while (search-forward " " nil t)
@@ -3480,10 +4268,10 @@ necessary anymore."
                             (tramp-make-tramp-file-name multi-method method
                                                         user host x)))
                 (read (current-buffer))))))
-       (list (tramp-handle-expand-file-name name))))))
+       (list (expand-file-name name))))))
 
 ;; Check for complete.el and override PC-expand-many-files if appropriate.
-(eval-when-compile
+(eval-and-compile
   (defun tramp-save-PC-expand-many-files (name))); avoid compiler warning
 
 (defun tramp-setup-complete ()
@@ -3491,7 +4279,7 @@ necessary anymore."
         (symbol-function 'PC-expand-many-files))
   (defun PC-expand-many-files (name)
     (if (tramp-tramp-file-p name)
-        (tramp-handle-expand-many-files name)
+        (expand-many-files name)
       (tramp-save-PC-expand-many-files name))))
 
 ;; Why isn't eval-after-load sufficient?
@@ -3505,17 +4293,18 @@ necessary anymore."
 ;; `tramp-completion-file-name-regexp-unified' aren't different.
 ;; If nil, `tramp-completion-run-real-handler' is called (i.e. forwarding to
 ;; `tramp-file-name-handler'). Otherwise, it takes `tramp-run-real-handler'.
-;; Using `last-input-event' is a little bit risky, because completing a file 
+;; Using `last-input-event' is a little bit risky, because completing a file
 ;; might require loading other files, like "~/.netrc", and for them it
 ;; shouldn't be decided based on that variable. On the other hand, those files
 ;; shouldn't have partial tramp file name syntax. Maybe another variable should
 ;; be introduced overwriting this check in such cases. Or we change tramp
 ;; file name syntax in order to avoid ambiguities, like in XEmacs ...
-;; In case of XEmacs it can be always true (and wouldn't be necessary).
+;; In case of non unified file names it can be always true (and wouldn't be
+;; necessary, because there are different regexp).
 (defun tramp-completion-mode (file)
   "Checks whether method / user name / host name completion is active."
   (cond
-   ((featurep 'xemacs) t)
+   ((not tramp-unified-filenames) t)
    ((string-match "^/.*:.*:$" file) nil)
    ((string-match
      (concat tramp-prefix-regexp
@@ -3523,11 +4312,24 @@ necessary anymore."
      file)
     (member (match-string 1 file) (mapcar 'car tramp-methods)))
    ((or (equal last-input-event 'tab)
-       (and (not (event-modifiers last-input-event))
-            (integerp last-input-event)
+       ;; Emacs
+       (and (integerp last-input-event)
+            (not (event-modifiers last-input-event))
             (or (char-equal last-input-event ?\?)
                 (char-equal last-input-event ?\t) ; handled by 'tab already?
-                (char-equal last-input-event ?\ ))))
+                (char-equal last-input-event ?\ )))
+       ;; XEmacs
+       (and (featurep 'xemacs)
+            (not (event-modifiers last-input-event))
+            (or (char-equal
+                 (funcall (symbol-function 'event-to-character)
+                          last-input-event) ?\?)
+                (char-equal
+                 (funcall (symbol-function 'event-to-character)
+                          last-input-event) ?\t)
+                (char-equal
+                 (funcall (symbol-function 'event-to-character)
+                          last-input-event) ?\ ))))
     t)))
 
 (defun tramp-completion-handle-file-exists-p (filename)
@@ -3538,7 +4340,7 @@ necessary anymore."
     (tramp-completion-run-real-handler
      'file-exists-p (list filename))))
 
-;; Path manipulation in case of partial TRAMP file names.
+;; Localname manipulation in case of partial TRAMP file names.
 (defun tramp-completion-handle-file-name-directory (file)
   "Like `file-name-directory' but aware of TRAMP files."
   (if (tramp-completion-mode file)
@@ -3546,7 +4348,7 @@ necessary anymore."
     (tramp-completion-run-real-handler
      'file-name-directory (list file))))
 
-;; Path manipulation in case of partial TRAMP file names.
+;; Localname manipulation in case of partial TRAMP file names.
 (defun tramp-completion-handle-file-name-nondirectory (file)
   "Like `file-name-nondirectory' but aware of TRAMP files."
   (substring
@@ -3576,12 +4378,13 @@ necessary anymore."
             (method (tramp-file-name-method car))
             (user (tramp-file-name-user car))
             (host (tramp-file-name-host car))
-            (path (tramp-file-name-path car))
+            (localname (tramp-file-name-localname car))
             (m (tramp-find-method multi-method method user host))
+            (tramp-current-user user) ; see `tramp-parse-passwd'
             all-user-hosts)
 
        (unless (or multi-method ;; Not handled (yet).
-                   path)        ;; Nothing to complete
+                   localname)        ;; Nothing to complete
 
          (if (or user host)
 
@@ -3594,7 +4397,7 @@ necessary anymore."
                               (funcall (nth 0 x) (nth 1 x)))))
               (tramp-get-completion-function m))
 
-             (setq result (append result 
+             (setq result (append result
                (mapcar
                 (lambda (x)
                   (tramp-get-completion-user-host
@@ -3625,7 +4428,7 @@ necessary anymore."
 ;; I misuse a little bit the tramp-file-name structure in order to handle
 ;; completion possibilities for partial methods / user names / host names.
 ;; Return value is a list of tramp-file-name structures according to possible
-;; completions. If "multi-method" or "path" is non-nil it means there
+;; completions. If "multi-method" or "localname" is non-nil it means there
 ;; shouldn't be a completion anymore.
 
 ;; Expected results:
@@ -3635,7 +4438,7 @@ necessary anymore."
 ;; [nil nil "x" nil nil]
 ;; [nil "x" nil nil nil]
 
-;; "/x:"                    "/x:y"                   "/x:y:"                 
+;; "/x:"                    "/x:y"                   "/x:y:"
 ;; [nil nil nil "x" ""]     [nil nil nil "x" "y"]    [nil "x" nil "y" ""]
 ;;       "/[x/"                   "/[x/y"
 ;; [nil "x" nil "" nil]     [nil "x" nil "y" nil]
@@ -3707,7 +4510,7 @@ They are collected by `tramp-completion-dissect-file-name1'."
 (defun tramp-completion-dissect-file-name1 (structure name)
   "Returns a `tramp-file-name' structure matching STRUCTURE.
 The structure consists of multi-method, remote method, remote user,
-remote host and remote path name."
+remote host and localname (filename on remote host)."
 
   (let (method)
     (save-match-data
@@ -3721,19 +4524,19 @@ remote host and remote path name."
             :method nil
             :user nil
             :host nil
-            :path nil)
+            :localname nil)
          (let ((user   (and (nth 2 structure)
                             (match-string (nth 2 structure) name)))
                (host   (and (nth 3 structure)
                             (match-string (nth 3 structure) name)))
-               (path   (and (nth 4 structure)
+               (localname   (and (nth 4 structure)
                             (match-string (nth 4 structure) name))))
            (make-tramp-file-name
             :multi-method nil
             :method method
             :user user
             :host host
-            :path path)))))))
+            :localname localname)))))))
 
 ;; This function returns all possible method completions, adding the
 ;; trailing method delimeter.
@@ -3785,7 +4588,7 @@ PARTIAL-USER must match USER, PARTIAL-HOST must match HOST."
 Either user or host may be nil."
 
   (let (res)
-    (when (file-exists-p filename)
+    (when (file-readable-p filename)
       (with-temp-buffer
        (insert-file-contents filename)
        (goto-char (point-min))
@@ -3822,7 +4625,7 @@ Either user or host may be nil."
 User is always nil."
 
   (let (res)
-    (when (file-exists-p filename)
+    (when (file-readable-p filename)
       (with-temp-buffer
        (insert-file-contents filename)
        (goto-char (point-min))
@@ -3846,12 +4649,70 @@ User is always nil."
       (forward-line 1))
      result))
 
+(defun tramp-parse-sconfig (filename)
+  "Return a list of (user host) tuples allowed to access.
+User is always nil."
+
+  (let (res)
+    (when (file-readable-p filename)
+      (with-temp-buffer
+       (insert-file-contents filename)
+       (goto-char (point-min))
+       (while (not (eobp))
+         (push (tramp-parse-sconfig-group) res))))
+    res))
+
+(defun tramp-parse-sconfig-group ()
+   "Return a (user host) tuple allowed to access.
+User is always nil."
+
+   (let ((result)
+        (regexp (concat "^[ \t]*Host[ \t]+" "\\(" tramp-host-regexp "\\)")))
+
+     (narrow-to-region (point) (tramp-point-at-eol))
+     (when (re-search-forward regexp nil t)
+       (setq result (list nil (match-string 1))))
+     (widen)
+     (or
+      (> (skip-chars-forward ",") 0)
+      (forward-line 1))
+     result))
+
+(defun tramp-parse-shostkeys (dirname)
+  "Return a list of (user host) tuples allowed to access.
+User is always nil."
+
+  (let ((regexp (concat "^key_[0-9]+_\\(" tramp-host-regexp "\\)\\.pub$"))
+       (files (when (file-directory-p dirname) (directory-files dirname)))
+       result)
+
+    (while files
+      (when (string-match regexp (car files))
+       (push (list nil (match-string 1 (car files))) result))
+      (setq files (cdr files)))
+    result))
+
+(defun tramp-parse-sknownhosts (dirname)
+  "Return a list of (user host) tuples allowed to access.
+User is always nil."
+
+  (let ((regexp (concat "^\\(" tramp-host-regexp
+                       "\\)\\.ssh-\\(dss\\|rsa\\)\\.pub$"))
+       (files (when (file-directory-p dirname) (directory-files dirname)))
+       result)
+
+    (while files
+      (when (string-match regexp (car files))
+       (push (list nil (match-string 1 (car files))) result))
+      (setq files (cdr files)))
+    result))
+
 (defun tramp-parse-hosts (filename)
   "Return a list of (user host) tuples allowed to access.
 User is always nil."
 
   (let (res)
-    (when (file-exists-p filename)
+    (when (file-readable-p filename)
       (with-temp-buffer
        (insert-file-contents filename)
        (goto-char (point-min))
@@ -3876,14 +4737,18 @@ User is always nil."
       (forward-line 1))
      result))
 
+;; For su-alike methods it would be desirable to return "root@localhost"
+;; as default.  Unfortunately, we have no information whether any user name
+;; has been typed already.  So we (mis-)use tramp-current-user as indication,
+;; assuming it is set in `tramp-completion-handle-file-name-all-completions'.
 (defun tramp-parse-passwd (filename)
   "Return a list of (user host) tuples allowed to access.
 Host is always \"localhost\"."
 
   (let (res)
-    (if (and (symbolp 'user) (zerop (length user)))
+    (if (zerop (length tramp-current-user))
        '(("root" nil))
-      (when (file-exists-p filename)
+      (when (file-readable-p filename)
        (with-temp-buffer
          (insert-file-contents filename)
          (goto-char (point-min))
@@ -3910,7 +4775,7 @@ Host is always \"localhost\"."
 User may be nil."
 
   (let (res)
-    (when (file-exists-p filename)
+    (when (file-readable-p filename)
       (with-temp-buffer
        (insert-file-contents filename)
        (goto-char (point-min))
@@ -3938,14 +4803,38 @@ User may be nil."
 (defun tramp-completion-handle-expand-file-name (name &optional dir)
   "Like `expand-file-name' for tramp files."
   (let ((fullname (concat (or dir default-directory) name)))
-    (if (tramp-completion-mode fullname)
-       (tramp-run-real-handler
-        'expand-file-name (list name dir))
-      (tramp-completion-run-real-handler
-       'expand-file-name (list name dir)))))
+    (tramp-drop-volume-letter
+     (if (tramp-completion-mode fullname)
+        (tramp-run-real-handler
+         'expand-file-name (list name dir))
+       (tramp-completion-run-real-handler
+       'expand-file-name (list name dir))))))
 
 ;;; Internal Functions:
 
+(defun tramp-maybe-send-perl-script (multi-method method user host script name)
+  "Define in remote shell function NAME implemented as perl SCRIPT.
+Only send the definition if it has not already been done.
+Function may have 0-3 parameters."
+  (let ((remote-perl (tramp-get-remote-perl multi-method method user host)))
+    (unless remote-perl (error "No remote perl"))
+    (let ((perl-scripts (tramp-get-connection-property "perl-scripts" nil
+                                                       multi-method method user host)))
+      (unless (memq name perl-scripts)
+        (with-current-buffer (tramp-get-buffer multi-method method user host)
+          (tramp-message 5 (concat "Sending the Perl script `" name "'..."))
+          (tramp-send-string multi-method method user host
+                             (concat name
+                                     " () {\n"
+                                     remote-perl
+                                     " -e '"
+                                     script
+                                     "' \"$1\" \"$2\" \"$3\" 2>/dev/null\n}"))
+          (tramp-wait-for-output)
+          (tramp-set-connection-property "perl-scripts" (cons name perl-scripts)
+                                         multi-method method user host)
+          (tramp-message 5 (concat "Sending the Perl script `" name "'...done.")))))))
+
 (defun tramp-set-auto-save ()
   (when (and (buffer-file-name)
              (tramp-tramp-file-p (buffer-file-name))
@@ -3962,7 +4851,7 @@ Returns the exit code of the `test' program."
        (tramp-file-name-multi-method v) (tramp-file-name-method v)
        (tramp-file-name-user v) (tramp-file-name-host v)
        (format "test %s %s" switch
-               (tramp-shell-quote-argument (tramp-file-name-path v)))))))
+               (tramp-shell-quote-argument (tramp-file-name-localname v)))))))
 
 (defun tramp-run-test2 (program file1 file2 &optional switch)
   "Run `test'-like PROGRAM on the remote system, given FILE1, FILE2.
@@ -3979,8 +4868,8 @@ hosts, or files, disagree."
          (user2 (tramp-file-name-user v2))
          (host1 (tramp-file-name-host v1))
          (host2 (tramp-file-name-host v2))
-         (path1 (tramp-file-name-path v1))
-         (path2 (tramp-file-name-path v2)))
+         (localname1 (tramp-file-name-localname v1))
+         (localname2 (tramp-file-name-localname v2)))
     (unless (and method1 method2 host1 host2
                  (equal mmethod1 mmethod2)
                  (equal method1 method2)
@@ -3993,18 +4882,40 @@ hosts, or files, disagree."
        mmethod1 method1 user1 host1
        (format "%s %s %s %s"
                program
-               (tramp-shell-quote-argument path1)
+               (tramp-shell-quote-argument localname1)
                (or switch "")
-               (tramp-shell-quote-argument path2))))))
+               (tramp-shell-quote-argument localname2))))))
+
+(defun tramp-touch (file time)
+  "Set the last-modified timestamp of the given file.
+TIME is an Emacs internal time value as returned by `current-time'."
+  (let ((touch-time (format-time-string "%Y%m%d%H%M.%S" time)))
+    (if (tramp-tramp-file-p file)
+       (with-parsed-tramp-file-name file nil
+         (let ((buf (tramp-get-buffer multi-method method user host)))
+           (unless (zerop (tramp-send-command-and-check
+                           multi-method method user host
+                           (format "touch -t %s %s"
+                                   touch-time
+                                   localname)))
+             (pop-to-buffer buf)
+             (error "tramp-touch: touch failed, see buffer `%s' for details"
+                    buf))))
+      ;; It's a local file
+      (with-temp-buffer
+       (unless (zerop (call-process
+                       "touch" nil (current-buffer) nil "-t" touch-time file))
+             (pop-to-buffer (current-buffer))
+             (error "tramp-touch: touch failed"))))))
 
 (defun tramp-buffer-name (multi-method method user host)
   "A name for the connection buffer for USER at HOST using METHOD."
-  (cond (multi-method
-         (tramp-buffer-name-multi-method "tramp" multi-method method user host))
-        (user
-         (format "*tramp/%s %s@%s*" method user host))
-        (t
-         (format "*tramp/%s %s*" method host))))
+  (if multi-method
+      (tramp-buffer-name-multi-method "tramp" multi-method method user host)
+    (let ((method (tramp-find-method multi-method method user host)))
+      (if user
+         (format "*tramp/%s %s@%s*" method user host)
+       (format "*tramp/%s %s*" method host)))))
 
 (defun tramp-buffer-name-multi-method (prefix multi-method method user host)
   "A name for the multi method connection buffer.
@@ -4030,21 +4941,28 @@ USER the array of user names, HOST the array of host names."
 
 (defun tramp-get-buffer (multi-method method user host)
   "Get the connection buffer to be used for USER at HOST using METHOD."
-  (get-buffer-create (tramp-buffer-name multi-method method user host)))
+  (with-current-buffer
+      (get-buffer-create (tramp-buffer-name multi-method method user host))
+    (setq buffer-undo-list t)
+    (current-buffer)))
 
 (defun tramp-debug-buffer-name (multi-method method user host)
   "A name for the debug buffer for USER at HOST using METHOD."
-  (cond (multi-method
-         (tramp-buffer-name-multi-method "debug tramp"
-                                         multi-method method user host))
-        (user
-         (format "*debug tramp/%s %s@%s*" method user host))
-        (t
-         (format "*debug tramp/%s %s*" method host))))
+  (if multi-method
+      (tramp-buffer-name-multi-method "debug tramp"
+                                     multi-method method user host)
+    (let ((method (tramp-find-method multi-method method user host)))
+      (if user
+         (format "*debug tramp/%s %s@%s*" method user host)
+       (format "*debug tramp/%s %s*" method host)))))
 
 (defun tramp-get-debug-buffer (multi-method method user host)
   "Get the debug buffer for USER at HOST using METHOD."
-  (get-buffer-create (tramp-debug-buffer-name multi-method method user host)))
+  (with-current-buffer
+      (get-buffer-create
+       (tramp-debug-buffer-name multi-method method user host))
+    (setq buffer-undo-list t)
+    (current-buffer)))
 
 (defun tramp-find-executable (multi-method method user host
                                          progname dirlist ignore-tilde)
@@ -4054,7 +4972,7 @@ is the program to search for, and DIRLIST gives the list of directories
 to search.  If IGNORE-TILDE is non-nil, directory names starting
 with `~' will be ignored.
 
-Returns the full path name of PROGNAME, if found, and nil otherwise.
+Returns the absolute file name of PROGNAME, if found, and nil otherwise.
 
 This function expects to be in the right *tramp* buffer."
   (let (result)
@@ -4142,19 +5060,19 @@ file exists and nonzero exit status otherwise."
     ;; `/usr/bin/test -e'       In case `/bin/test' does not exist.
     (unless (or
              (and (setq tramp-file-exists-command "test -e %s")
-                  (tramp-handle-file-exists-p existing)
-                  (not (tramp-handle-file-exists-p nonexisting)))
+                  (file-exists-p existing)
+                  (not (file-exists-p nonexisting)))
              (and (setq tramp-file-exists-command "/bin/test -e %s")
-                  (tramp-handle-file-exists-p existing)
-                  (not (tramp-handle-file-exists-p nonexisting)))
+                  (file-exists-p existing)
+                  (not (file-exists-p nonexisting)))
              (and (setq tramp-file-exists-command "/usr/bin/test -e %s")
-                  (tramp-handle-file-exists-p existing)
-                  (not (tramp-handle-file-exists-p nonexisting)))
+                  (file-exists-p existing)
+                  (not (file-exists-p nonexisting)))
              (and (setq tramp-file-exists-command "ls -d %s")
-                  (tramp-handle-file-exists-p existing)
-                  (not (tramp-handle-file-exists-p nonexisting))))
+                  (file-exists-p existing)
+                  (not (file-exists-p nonexisting))))
       (error "Couldn't find command to check if file exists."))))
-    
+
 
 ;; CCC test ksh or bash found for tilde expansion?
 (defun tramp-find-shell (multi-method method user host)
@@ -4206,16 +5124,16 @@ file exists and nonzero exit status otherwise."
        9 "Setting remote shell prompt...done")
       )
      (t (tramp-message 5 "Remote `%s' groks tilde expansion, good"
-                      (tramp-get-remote-sh multi-method method user host))))))
+                      (tramp-get-method-parameter
+                       multi-method method user host 'tramp-remote-sh))))))
 
 (defun tramp-check-ls-command (multi-method method user host cmd)
   "Checks whether the given `ls' executable groks `-n'.
-METHOD, USER and HOST specify the connection, CMD (the full path name of)
+METHOD, USER and HOST specify the connection, CMD (the absolute file name of)
 the `ls' executable.  Returns t if CMD supports the `-n' option, nil
 otherwise."
-  (tramp-message 9 "Checking remote `%s' command for `-n' option"
-               cmd)
-  (when (tramp-handle-file-executable-p
+  (tramp-message 9 "Checking remote `%s' command for `-n' option" cmd)
+  (when (file-executable-p
          (tramp-make-tramp-file-name multi-method method user host cmd))
     (let ((result nil))
       (tramp-message 7 "Testing remote command `%s' for -n..." cmd)
@@ -4233,16 +5151,16 @@ otherwise."
   "Checks whether the given `ls' executable in one of the dirs groks `-n'.
 Returns nil if none was found, else the command is returned."
   (let ((dl dirlist)
-        (result nil)
-       (directory-sep-char ?/))        ;for XEmacs
-    ;; It would be better to use the CL function `find', but
-    ;; we don't want run-time dependencies on CL.
-    (while (and dl (not result))
-      (let ((x (concat (file-name-as-directory (car dl)) cmd)))
-        (when (tramp-check-ls-command multi-method method user host x)
-          (setq result x)))
-      (setq dl (cdr dl)))
-    result))
+        (result nil))
+    (tramp-let-maybe directory-sep-char ?/ ;for XEmacs
+      ;; It would be better to use the CL function `find', but
+      ;; we don't want run-time dependencies on CL.
+      (while (and dl (not result))
+       (let ((x (concat (file-name-as-directory (car dl)) cmd)))
+         (when (tramp-check-ls-command multi-method method user host x)
+           (setq result x)))
+       (setq dl (cdr dl)))
+      result)))
 
 (defun tramp-find-ls-command (multi-method method user host)
   "Finds an `ls' command which groks the `-n' option, returning nil if failed.
@@ -4253,9 +5171,9 @@ Returns nil if none was found, else the command is returned."
    (tramp-check-ls-commands multi-method method user host "gnuls" tramp-remote-path)
    (tramp-check-ls-commands multi-method method user host "gls" tramp-remote-path)))
 
-;; ------------------------------------------------------------ 
-;; -- Functions for establishing connection -- 
-;; ------------------------------------------------------------ 
+;; ------------------------------------------------------------
+;; -- Functions for establishing connection --
+;; ------------------------------------------------------------
 
 ;; The following functions are actions to be taken when seeing certain
 ;; prompts from the remote host.  See the variable
@@ -4272,13 +5190,8 @@ Returns nil if none was found, else the command is returned."
 (defun tramp-action-password (p multi-method method user host)
   "Query the user for a password."
   (let ((pw-prompt (match-string 0)))
-    (when (tramp-method-out-of-band-p multi-method method user host)
-      (kill-process (get-buffer-process (current-buffer)))
-      (error (concat "Out of band method `%s' not applicable "
-                    "for remote shell asking for a password")
-            method))
     (tramp-message 9 "Sending password")
-    (tramp-enter-password p pw-prompt)))
+    (tramp-enter-password p pw-prompt user host)))
 
 (defun tramp-action-succeed (p multi-method method user host)
   "Signal success in finding shell prompt."
@@ -4327,6 +5240,32 @@ The terminal type can be configured with `tramp-terminal-type'."
   (process-send-string nil (concat tramp-terminal-type
                                   tramp-rsh-end-of-line)))
 
+(defun tramp-action-process-alive (p multi-method method user host)
+  "Check whether a process has finished."
+  (unless (memq (process-status p) '(run open))
+    (throw 'tramp-action 'process-died)))
+
+(defun tramp-action-out-of-band (p multi-method method user host)
+  "Check whether an out-of-band copy has finished."
+  (cond ((and (memq (process-status p) '(stop exit))
+             (zerop (process-exit-status p)))
+        (tramp-message 9 "Process has finished.")
+        (throw 'tramp-action 'ok))
+       ((or (and (memq (process-status p) '(stop exit))
+                 (not (zerop (process-exit-status p))))
+            (memq (process-status p) '(signal)))
+        ;; `scp' could have copied correctly, but set modes could have failed.
+        ;; This can be ignored.
+        (goto-char (point-min))
+        (if (re-search-forward tramp-operation-not-permitted-regexp nil t)
+            (progn
+              (tramp-message 10 "'set mode' error ignored.")
+              (tramp-message 9 "Process has finished.")
+              (throw 'tramp-action 'ok))
+          (tramp-message 9 "Process has died.")
+          (throw 'tramp-action 'process-died)))
+       (t nil)))
+
 ;; The following functions are specifically for multi connections.
 
 (defun tramp-multi-action-login (p method user host)
@@ -4338,7 +5277,7 @@ The terminal type can be configured with `tramp-terminal-type'."
 (defun tramp-multi-action-password (p method user host)
   "Query the user for a password."
   (tramp-message 9 "Sending password")
-  (tramp-enter-password p (match-string 0)))
+  (tramp-enter-password p (match-string 0) user host))
 
 (defun tramp-multi-action-succeed (p method user host)
   "Signal success in finding shell prompt."
@@ -4353,6 +5292,11 @@ The terminal type can be configured with `tramp-terminal-type'."
   (erase-buffer)
   (throw 'tramp-action 'permission-denied))
 
+(defun tramp-multi-action-process-alive (p method user host)
+  "Check whether a process has finished."
+  (unless (memq (process-status p) '(run open))
+    (throw 'tramp-action 'process-died)))
+
 ;; Functions for processing the actions.
 
 (defun tramp-process-one-action (p multi-method method user host actions)
@@ -4387,6 +5331,7 @@ The terminal type can be configured with `tramp-terminal-type'."
               p multi-method method user host actions)
              nil)))
     (unless (eq exit 'ok)
+      (tramp-clear-passwd user host)
       (error "Login failed"))))
 
 ;; For multi-actions.
@@ -4422,8 +5367,31 @@ The terminal type can be configured with `tramp-terminal-type'."
              (tramp-process-one-multi-action p method user host actions)
              nil)))
     (unless (eq exit 'ok)
+      (tramp-clear-passwd user host)
       (error "Login failed"))))
 
+;; Functions to execute when we have seen the remote shell prompt but
+;; before we exec the Bourne-ish shell.  Note that these commands
+;; might be sent to any shell, not just a Bourne-ish shell.  This
+;; means that the commands need to work in all shells.  (It is also
+;; okay for some commands to just fail with an error message, but
+;; please make sure that they at least don't crash the odd shell people
+;; might be running...)
+(defun tramp-process-initial-commands (p
+                                      multi-method method user host
+                                      commands)
+  "Send list of commands to remote host, in order."
+  (let (cmd)
+    (while commands
+      (setq cmd (pop commands))
+      (erase-buffer)
+      (tramp-message 10 "Sending command to remote shell: %s"
+                    cmd)
+      (tramp-send-command multi-method method user host cmd nil t)
+      (tramp-barf-if-no-shell-prompt
+       p 60 "Remote shell command failed: %s" cmd))
+    (erase-buffer)))
+
 ;; The actual functions for opening connections.
 
 (defun tramp-open-connection-telnet (multi-method method user host)
@@ -4454,7 +5422,7 @@ Maybe the different regular expressions need to be tuned.
     (when multi-method
       (error "Cannot multi-connect using telnet connection method"))
     (tramp-pre-connection multi-method method user host)
-    (tramp-message 7 "Opening connection for %s@%s using %s..." 
+    (tramp-message 7 "Opening connection for %s@%s using %s..."
                   (or user (user-login-name)) host method)
     (let ((process-environment (copy-sequence process-environment)))
       (setenv "TERM" tramp-terminal-type)
@@ -4468,18 +5436,18 @@ Maybe the different regular expressions need to be tuned.
              (p (apply 'start-process
                        (tramp-buffer-name multi-method method user host)
                        (tramp-get-buffer multi-method method user host)
-                      (tramp-get-telnet-program
+                      (tramp-get-method-parameter
                        multi-method
                        (tramp-find-method multi-method method user host)
-                       user host)
+                       user host 'tramp-login-program)
                        host
-                      (tramp-get-telnet-args
+                      (tramp-get-method-parameter
                        multi-method
                        (tramp-find-method multi-method method user host)
-                       user host)))
+                       user host 'tramp-login-args)))
              (found nil)
              (pw nil))
-        (process-kill-without-query p)
+        (tramp-set-process-query-on-exit-flag p nil)
        (set-buffer (tramp-get-buffer multi-method method user host))
        (erase-buffer)
        (tramp-process-actions p multi-method method user host
@@ -4488,7 +5456,7 @@ Maybe the different regular expressions need to be tuned.
          p multi-method method user host)
         (tramp-post-connection multi-method method user host)))))
 
-           
+
 (defun tramp-open-connection-rsh (multi-method method user host)
   "Open a connection using an rsh METHOD.
 This starts the command `rsh HOST -l USER'[*], then waits for a remote
@@ -4502,12 +5470,6 @@ Recognition of the remote shell prompt is based on the variables
 `shell-prompt-pattern' and `tramp-shell-prompt-pattern' which must be
 set up correctly.
 
-Please note that it is NOT possible to use this connection method with
-an out-of-band transfer method if this function asks the user for a
-password!  You must use an inline transfer method in this case.
-Sadly, the transfer method cannot be switched on the fly, instead you
-must specify the right method in the file name.
-
 Kludgy feature: if HOST has the form \"xx#yy\", then yy is assumed to
 be a port number for ssh, and \"-p yy\" will be added to the list of
 arguments, and xx will be used as the host name to connect to.
@@ -4519,25 +5481,26 @@ arguments, and xx will be used as the host name to connect to.
       (error "Cannot multi-connect using rsh connection method"))
     (tramp-pre-connection multi-method method user host)
     (if (and user (not (string= user "")))
-       (tramp-message 7 "Opening connection for %s@%s using %s..." 
+       (tramp-message 7 "Opening connection for %s@%s using %s..."
                       user host method)
       (tramp-message 7 "Opening connection at %s using %s..." host method))
     (let ((process-environment (copy-sequence process-environment))
          (bufnam (tramp-buffer-name multi-method method user host))
          (buf (tramp-get-buffer multi-method method user host))
-         (rsh-program (tramp-get-rsh-program
+         (login-program (tramp-get-method-parameter
                        multi-method
                        (tramp-find-method multi-method method user host)
-                       user host))
-         (rsh-args (tramp-get-rsh-args
+                       user host 'tramp-login-program))
+         (login-args (tramp-get-method-parameter
                     multi-method
                     (tramp-find-method multi-method method user host)
-                    user host)))
+                    user host 'tramp-login-args))
+         (real-host host))
       ;; The following should be changed.  We need a more general
       ;; mechanism to parse extra host args.
       (when (string-match "\\([^#]*\\)#\\(.*\\)" host)
-       (setq rsh-args (cons "-p" (cons (match-string 2 host) rsh-args)))
-       (setq host (match-string 1 host)))
+       (setq login-args (cons "-p" (cons (match-string 2 host) login-args)))
+       (setq real-host (match-string 1 host)))
       (setenv "TERM" tramp-terminal-type)
       (let* ((default-directory (tramp-temporary-file-directory))
             ;; If we omit the conditional, we would use
@@ -4547,12 +5510,12 @@ arguments, and xx will be used as the host name to connect to.
                                                   (> emacs-major-version 20))
                                        tramp-dos-coding-system))
              (p (if (and user (not (string= user "")))
-                    (apply #'start-process bufnam buf rsh-program  
-                           host "-l" user rsh-args)
-                  (apply #'start-process bufnam buf rsh-program 
-                         host rsh-args)))
+                    (apply #'start-process bufnam buf login-program
+                           real-host "-l" user login-args)
+                  (apply #'start-process bufnam buf login-program
+                         real-host login-args)))
              (found nil))
-        (process-kill-without-query p)
+        (tramp-set-process-query-on-exit-flag p nil)
 
        (set-buffer buf)
        (tramp-process-actions p multi-method method user host
@@ -4600,29 +5563,29 @@ prompt than you do, so it is not at all unlikely that the variable
              (p (apply 'start-process
                        (tramp-buffer-name multi-method method user host)
                        (tramp-get-buffer multi-method method user host)
-                      (tramp-get-su-program
+                      (tramp-get-method-parameter
                        multi-method
                        (tramp-find-method multi-method method user host)
-                       user host)
+                       user host 'tramp-login-program)
                        (mapcar
                         (lambda (x)
                          (format-spec x `((?u . ,(or user "root")))))
-                        (tramp-get-su-args
+                        (tramp-get-method-parameter
                         multi-method
                         (tramp-find-method multi-method method user host)
-                        user host))))
+                        user host 'tramp-login-args))))
              (found nil)
              (pw nil))
-        (process-kill-without-query p)
+        (tramp-set-process-query-on-exit-flag p nil)
        (set-buffer (tramp-get-buffer multi-method method user host))
        (tramp-process-actions p multi-method method user host
                               tramp-actions-before-shell)
         (tramp-open-connection-setup-interactive-shell
          p multi-method method user host)
-        (tramp-post-connection multi-method method 
+        (tramp-post-connection multi-method method
                                user host)))))
 
-;; HHH: Not Changed.  Multi method.  It is not clear to me how this can 
+;; HHH: Not Changed.  Multi method.  It is not clear to me how this can
 ;;      handle not giving a user name in the "file name".
 ;;
 ;;      This is more difficult than for the single-hop method.  In the
@@ -4666,7 +5629,7 @@ log in as u2 to h2."
                                tramp-multi-sh-program))
              (num-hops (length method))
              (i 0))
-        (process-kill-without-query p)
+        (tramp-set-process-query-on-exit-flag p nil)
         (tramp-message 9 "Waiting 60s for local shell to come up...")
         (unless (tramp-wait-for-regexp
                 p 60 (format "\\(%s\\)\\'\\|\\(%s\\)\\'"
@@ -4692,7 +5655,7 @@ log in as u2 to h2."
         (tramp-post-connection multi-method method user host)))))
 
 ;; HHH: Changed.  Multi method.  Don't know how to handle this in the case
-;;      of no user name provided.  Hack to make it work as it did before:  
+;;      of no user name provided.  Hack to make it work as it did before:
 ;;      changed `user' to `(or user (user-login-name))' in the places where
 ;;      the value is actually used.
 (defun tramp-multi-connect-telnet (p method user host command)
@@ -4714,8 +5677,8 @@ If USER is nil, uses the return value of (user-login-name) instead."
     (tramp-process-multi-actions p method user host
                                 tramp-multi-actions)))
 
-;; HHH: Changed.  Multi method.  Don't know how to handle this in the case 
-;;      of no user name provided.  Hack to make it work as it did before:  
+;; HHH: Changed.  Multi method.  Don't know how to handle this in the case
+;;      of no user name provided.  Hack to make it work as it did before:
 ;;      changed `user' to `(or user (user-login-name))' in the places where
 ;;      the value is actually used.
 (defun tramp-multi-connect-rlogin (p method user host command)
@@ -4740,8 +5703,8 @@ If USER is nil, uses the return value of (user-login-name) instead."
     (tramp-process-multi-actions p method user host
                                 tramp-multi-actions)))
 
-;; HHH: Changed.  Multi method.  Don't know how to handle this in the case 
-;;      of no user name provided.  Hack to make it work as it did before:  
+;; HHH: Changed.  Multi method.  Don't know how to handle this in the case
+;;      of no user name provided.  Hack to make it work as it did before:
 ;;      changed `user' to `(or user (user-login-name))' in the places where
 ;;      the value is actually used.
 (defun tramp-multi-connect-su (p method user host command)
@@ -4786,12 +5749,16 @@ nil."
              (with-timeout (timeout)
                (while (not found)
                  (accept-process-output proc 1)
+                (unless (memq (process-status proc) '(run open))
+                  (error "Process has died"))
                  (goto-char (point-min))
                  (setq found (when (re-search-forward regexp nil t)
                                (tramp-match-string-list)))))))
           (t
            (while (not found)
              (accept-process-output proc 1)
+            (unless (memq (process-status proc) '(run open))
+              (error "Process has died"))
              (goto-char (point-min))
              (setq found (when (re-search-forward regexp nil t)
                            (tramp-match-string-list))))))
@@ -4811,16 +5778,42 @@ nil."
                   "]]"))))
     found))
 
-(defun tramp-enter-password (p prompt)
+(defun tramp-wait-for-shell-prompt (proc timeout)
+  "Wait for the shell prompt to appear from process PROC within TIMEOUT seconds.
+See `tramp-wait-for-regexp' for more details.
+Shell prompt pattern is determined by variables `shell-prompt-pattern'
+and `tramp-shell-prompt-pattern'."
+  (tramp-wait-for-regexp
+   proc timeout
+   (format "\\(%s\\|%s\\)\\'"
+          shell-prompt-pattern tramp-shell-prompt-pattern)))
+
+(defun tramp-barf-if-no-shell-prompt (proc timeout &rest error-args)
+  "Wait for shell prompt and barf if none appears.
+Looks at process PROC to see if a shell prompt appears in TIMEOUT
+seconds.  If not, it produces an error message with the given ERROR-ARGS."
+  (unless (tramp-wait-for-shell-prompt proc timeout)
+    (pop-to-buffer (buffer-name))
+    (apply 'error error-args)))
+
+(defun tramp-enter-password (p prompt user host)
   "Prompt for a password and send it to the remote end.
 Uses PROMPT as a prompt and sends the password to process P."
-  (let ((pw (tramp-read-passwd prompt)))
+  (let ((pw (tramp-read-passwd user host prompt)))
     (erase-buffer)
-    (process-send-string p (concat pw tramp-password-end-of-line))))
+    (process-send-string
+     p (concat pw
+              (or (tramp-get-method-parameter
+                   tramp-current-multi-method
+                   tramp-current-method
+                   tramp-current-user
+                   tramp-current-host
+                   'tramp-password-end-of-line)
+                  tramp-default-password-end-of-line)))))
 
 ;; HHH: Not Changed.  This might handle the case where USER is not
 ;;      given in the "File name" very poorly.  Then, the local
-;;      variable tramp-current user will be set to nil.
+;;      variable tramp-current-user will be set to nil.
 (defun tramp-pre-connection (multi-method method user host)
   "Do some setup before actually logging in.
 METHOD, USER and HOST specify the connection."
@@ -4842,6 +5835,8 @@ to set up.  METHOD, USER and HOST specify the connection."
   ;; a Kerberos login.
   (sit-for 1)
   (tramp-discard-garbage-erase-buffer p multi-method method user host)
+  (tramp-process-initial-commands p multi-method method user host
+                                 tramp-initial-commands)
   ;; It is useful to set the prompt in the following command because
   ;; some people have a setting for $PS1 which /bin/sh doesn't know
   ;; about and thus /bin/sh will display a strange prompt.  For
@@ -4850,56 +5845,41 @@ to set up.  METHOD, USER and HOST specify the connection."
   ;; sign.  The following command line sets $PS1 to a sane value, and
   ;; works under Bourne-ish shells as well as csh-like shells.  Daniel
   ;; Pittman reports that the unusual positioning of the single quotes
-  ;; makes it work under `rc', too.
-  (process-send-string nil (format "exec env 'PS1=$ ' %s%s"
-                                   (tramp-get-remote-sh
-                                   multi-method method user host)
-                                   tramp-rsh-end-of-line))
-  (when tramp-debug-buffer
-    (save-excursion
-      (set-buffer (tramp-get-debug-buffer multi-method method user host))
-      (goto-char (point-max))
-      (tramp-insert-with-face
-       'bold (format "$ exec env PS1='$ ' %s\n"
-                    (tramp-get-remote-sh multi-method method user host)))))
-  (tramp-message 9 "Waiting 30s for remote `%s' to come up..."
-               (tramp-get-remote-sh multi-method method user host))
-  (unless (tramp-wait-for-regexp
-          p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error "Remote `%s' didn't come up.  See buffer `%s' for details"
-           (tramp-get-remote-sh multi-method method user host)
-          (buffer-name)))
-  (tramp-message 9 "Setting up remote shell environment")
+  ;; makes it work under `rc', too.  We also unset the variable $ENV
+  ;; because that is read by some sh implementations (eg, bash when
+  ;; called as sh) on startup; this way, we avoid the startup file
+  ;; clobbering $PS1.
+  (tramp-send-command-internal
+   multi-method method user host
+   (format "exec env 'ENV=' 'PS1=$ ' %s"
+          (tramp-get-method-parameter
+           multi-method method user host 'tramp-remote-sh))
+   (format "remote `%s' to come up"
+          (tramp-get-method-parameter
+           multi-method method user host 'tramp-remote-sh)))
+  (tramp-barf-if-no-shell-prompt
+   p 30
+   "Remote `%s' didn't come up.  See buffer `%s' for details"
+   (tramp-get-method-parameter multi-method method user host 'tramp-remote-sh)
+   (buffer-name))
+  (tramp-message 8 "Setting up remote shell environment")
   (tramp-discard-garbage-erase-buffer p multi-method method user host)
-  (process-send-string
-   nil (format "stty -inlcr -echo kill '^U'%s" tramp-rsh-end-of-line))
-  (unless (tramp-wait-for-regexp
-          p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error "Couldn't `stty -echo', see buffer `%s'" (buffer-name)))
+  (tramp-send-command-internal multi-method method user host
+                              "stty -inlcr -echo kill '^U'")
   (erase-buffer)
-  (process-send-string nil (format "TERM=dumb; export TERM%s"
-                                   tramp-rsh-end-of-line))
-  (unless (tramp-wait-for-regexp
-          p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error "Couldn't `TERM=dumb; export TERM', see buffer `%s'" (buffer-name)))
+  ;; Ignore garbage after stty command.
+  (tramp-send-command-internal multi-method method user host
+                              "echo foo")
+  (erase-buffer)
+  (tramp-send-command-internal multi-method method user host
+                              "TERM=dumb; export TERM")
   ;; Try to set up the coding system correctly.
   ;; CCC this can't be the right way to do it.  Hm.
   (save-excursion
     (erase-buffer)
     (tramp-message 9 "Determining coding system")
-    (process-send-string nil (format "echo foo ; echo bar %s"
-                                     tramp-rsh-end-of-line))
-    (unless (tramp-wait-for-regexp
-             p 30 (format "\\(%s\\|%s\\)\\'"
-                         shell-prompt-pattern tramp-shell-prompt-pattern))
-      (pop-to-buffer (buffer-name))
-      (error "Couldn't `echo foo; echo bar' to determine line endings'"))
+    (tramp-send-command-internal multi-method method user host
+                                "echo foo ; echo bar")
     (goto-char (point-min))
     (if (featurep 'mule)
         ;; Use MULE to select the right EOL convention for communicating
@@ -4922,58 +5902,29 @@ to set up.  METHOD, USER and HOST specify the connection."
         ;; We have found a ^M but cannot frob the process coding system
         ;; because we're running on a non-MULE Emacs.  Let's try
         ;; stty, instead.
+       (erase-buffer)
         (tramp-message 9 "Trying `stty -onlcr'")
-        (process-send-string nil (format "stty -onlcr%s" tramp-rsh-end-of-line))
-        (unless (tramp-wait-for-regexp
-                 p 30 (format "\\(%s\\|%s\\)\\'"
-                             shell-prompt-pattern tramp-shell-prompt-pattern))
-          (pop-to-buffer (buffer-name))
-          (error "Couldn't `stty -onlcr', see buffer `%s'" (buffer-name))))))
+       (tramp-send-command-internal multi-method method user host
+                                    "stty -onlcr"))))
   (erase-buffer)
   (tramp-message
-   9 "Waiting 30s for `HISTFILE=$HOME/.tramp_history; HISTSIZE=1'")
-  (process-send-string
-   nil (format "HISTFILE=$HOME/.tramp_history; HISTSIZE=1%s"
-               tramp-rsh-end-of-line))
-  (unless (tramp-wait-for-regexp
-           p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error (concat "Couldn't `HISTFILE=$HOME/.tramp_history; "
-                   "HISTSIZE=1', see buffer `%s'")
-           (buffer-name)))
+   9 "Waiting 30s for `HISTFILE=$HOME/.tramp_history; HISTSIZE=1; export HISTFILE; export HISTSIZE'")
+  (tramp-send-command-internal
+   multi-method method user host
+   "HISTFILE=$HOME/.tramp_history; HISTSIZE=1; export HISTFILE; export HISTSIZE")
   (erase-buffer)
   (tramp-message 9 "Waiting 30s for `set +o vi +o emacs'")
-  (process-send-string
-   nil (format "set +o vi +o emacs%s"      ;mustn't `>/dev/null' with AIX?
-               tramp-rsh-end-of-line))
-  (unless (tramp-wait-for-regexp
-           p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error "Couldn't `set +o vi +o emacs', see buffer `%s'"
-           (buffer-name)))
+  (tramp-send-command-internal multi-method method user host
+                              "set +o vi +o emacs")
   (erase-buffer)
   (tramp-message 9 "Waiting 30s for `unset MAIL MAILCHECK MAILPATH'")
-  (process-send-string
-   nil (format "unset MAIL MAILCHECK MAILPATH 1>/dev/null 2>/dev/null%s"
-               tramp-rsh-end-of-line))
-  (unless (tramp-wait-for-regexp
-           p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error "Couldn't `unset MAIL MAILCHECK MAILPATH', see buffer `%s'"
-           (buffer-name)))
+  (tramp-send-command-internal
+   multi-method method user host
+   "unset MAIL MAILCHECK MAILPATH 1>/dev/null 2>/dev/null")
   (erase-buffer)
   (tramp-message 9 "Waiting 30s for `unset CDPATH'")
-  (process-send-string
-   nil (format "unset CDPATH%s" tramp-rsh-end-of-line))
-  (unless (tramp-wait-for-regexp
-           p 30 (format "\\(%s\\|%s\\)\\'"
-                       shell-prompt-pattern tramp-shell-prompt-pattern))
-    (pop-to-buffer (buffer-name))
-    (error "Couldn't `unset CDPATH', see buffer `%s'"
-           (buffer-name)))
+  (tramp-send-command-internal multi-method method user host
+                              "unset CDPATH")
   (erase-buffer)
   (tramp-message 9 "Setting shell prompt")
   ;; Douglas Gray Stephens <DGrayStephens@slb.com> says that we must
@@ -5075,10 +6026,11 @@ locale to C and sets up the remote shell search path."
   (tramp-wait-for-output)
   ;; Send the fallback `uudecode' script.
   (erase-buffer)
-  (tramp-send-linewise multi-method method user host tramp-uudecode)
+  (tramp-send-string multi-method method user host tramp-uudecode)
   (tramp-wait-for-output)
   ;; Find a `perl'.
   (erase-buffer)
+  (tramp-set-connection-property "perl-scripts" nil multi-method method user host)
   (let ((tramp-remote-perl
         (or (tramp-find-executable multi-method method user host
                                    "perl5" tramp-remote-path nil)
@@ -5087,50 +6039,37 @@ locale to C and sets up the remote shell search path."
     (when tramp-remote-perl
       (tramp-set-connection-property "perl" tramp-remote-perl
                                     multi-method method user host)
-      ;; Set up stat in Perl if we can.
-      (when tramp-remote-perl
-       (tramp-message 5 "Sending the Perl `file-attributes' implementation.")
-       (tramp-send-linewise
-        multi-method method user host
-        (concat "tramp_file_attributes () {\n"
-                tramp-remote-perl
-                " -e '" tramp-perl-file-attributes "' $1 2>/dev/null\n"
-                "}"))
-       (tramp-wait-for-output)
-       (unless (tramp-get-rcp-program
-                multi-method
-                (tramp-find-method multi-method method user host)
-                user host)
-         (tramp-message 5 "Sending the Perl `mime-encode' implementations.")
-         (tramp-send-linewise
-          multi-method method user host
-          (concat "tramp_encode () {\n"
-                  (format tramp-perl-encode tramp-remote-perl)
-                  " 2>/dev/null"
-                  "\n}"))
-         (tramp-wait-for-output)
-         (tramp-send-linewise
-          multi-method method user host
-          (concat "tramp_encode_with_module () {\n"
-                  (format tramp-perl-encode-with-module tramp-remote-perl)
-                  " 2>/dev/null"
-                  "\n}"))
-         (tramp-wait-for-output)
-         (tramp-message 5 "Sending the Perl `mime-decode' implementations.")
-         (tramp-send-linewise
-          multi-method method user host
-          (concat "tramp_decode () {\n"
-                  (format tramp-perl-decode tramp-remote-perl)
-                  " 2>/dev/null"
-                  "\n}"))
-         (tramp-wait-for-output)
-         (tramp-send-linewise
-          multi-method method user host
-          (concat "tramp_decode_with_module () {\n"
-                  (format tramp-perl-decode-with-module tramp-remote-perl)
-                  " 2>/dev/null"
-                  "\n}"))
-         (tramp-wait-for-output)))))
+      (unless (tramp-method-out-of-band-p multi-method method user host)
+        (tramp-message 5 "Sending the Perl `mime-encode' implementations.")
+        (tramp-send-string
+         multi-method method user host
+         (concat "tramp_encode () {\n"
+                 (format tramp-perl-encode tramp-remote-perl)
+                 " 2>/dev/null"
+                 "\n}"))
+        (tramp-wait-for-output)
+        (tramp-send-string
+         multi-method method user host
+         (concat "tramp_encode_with_module () {\n"
+                 (format tramp-perl-encode-with-module tramp-remote-perl)
+                 " 2>/dev/null"
+                 "\n}"))
+        (tramp-wait-for-output)
+        (tramp-message 5 "Sending the Perl `mime-decode' implementations.")
+        (tramp-send-string
+         multi-method method user host
+         (concat "tramp_decode () {\n"
+                 (format tramp-perl-decode tramp-remote-perl)
+                 " 2>/dev/null"
+                 "\n}"))
+        (tramp-wait-for-output)
+        (tramp-send-string
+         multi-method method user host
+         (concat "tramp_decode_with_module () {\n"
+                 (format tramp-perl-decode-with-module tramp-remote-perl)
+                 " 2>/dev/null"
+                 "\n}"))
+        (tramp-wait-for-output))))
   ;; Find ln(1)
   (erase-buffer)
   (let ((ln (tramp-find-executable multi-method method user host
@@ -5139,10 +6078,7 @@ locale to C and sets up the remote shell search path."
       (tramp-set-connection-property "ln" ln multi-method method user host)))
   (erase-buffer)
   ;; Find the right encoding/decoding commands to use.
-  (unless (tramp-get-rcp-program
-          multi-method
-          (tramp-find-method multi-method method user host)
-          user host)
+  (unless (tramp-method-out-of-band-p multi-method method user host)
     (tramp-find-inline-encoding multi-method method user host))
   ;; If encoding/decoding command are given, test to see if they work.
   ;; CCC: Maybe it would be useful to run the encoder both locally and
@@ -5197,6 +6133,8 @@ locale to C and sets up the remote shell search path."
      base64-encode-region base64-decode-region)
     ("recode data..base64" "recode base64..data"
      base64-encode-region base64-decode-region)
+    ("uuencode xxx" "uudecode -o /dev/stdout"
+     tramp-uuencode-region uudecode-decode-region)
     ("uuencode xxx" "uudecode -o -"
      tramp-uuencode-region uudecode-decode-region)
     ("uuencode xxx" "uudecode -p"
@@ -5355,11 +6293,12 @@ connection if a previous connection has died for some reason."
     (unless (and p (processp p) (memq (process-status p) '(run open)))
       (when (and p (processp p))
         (delete-process p))
-      (funcall (tramp-get-connection-function
-               multi-method
-               (tramp-find-method multi-method method user host)
-               user host)
-               multi-method method user host))))
+      (let ((process-connection-type tramp-process-connection-type))
+       (funcall (tramp-get-method-parameter
+                 multi-method
+                 (tramp-find-method multi-method method user host)
+                 user host 'tramp-connection-function)
+                multi-method method user host)))))
 
 (defun tramp-send-command
   (multi-method method user host command &optional noerase neveropen)
@@ -5372,6 +6311,7 @@ connection.  This is meant to be used from
   (or neveropen
       (tramp-maybe-open-connection multi-method method user host))
   (setq tramp-last-cmd-time (current-time))
+  (setq tramp-last-cmd command)
   (when tramp-debug-buffer
     (save-excursion
       (set-buffer (tramp-get-debug-buffer multi-method method user host))
@@ -5384,41 +6324,23 @@ connection.  This is meant to be used from
     (process-send-string proc
                          (concat command tramp-rsh-end-of-line))))
 
-;; It seems that Tru64 Unix does not like it if long strings are sent
-;; to it in one go.  (This happens when sending the Perl
-;; `file-attributes' implementation, for instance.)  Therefore, we
-;; have this function which waits a bit at each line.
-(defun tramp-send-linewise
-  (multi-method method user host string &optional noerase)
-  "Send the STRING to USER at HOST linewise.
-Erases temporary buffer before sending the STRING (unless NOERASE
-is true).
-
-The STRING is expected to use Unix line-endings, but the lines sent to
-the remote host use line-endings as defined in the variable
-`tramp-rsh-end-of-line'."
-  (tramp-maybe-open-connection multi-method method user host)
-  (when tramp-debug-buffer
-    (save-excursion
-      (set-buffer (tramp-get-debug-buffer multi-method method user host))
-      (goto-char (point-max))
-      (tramp-insert-with-face 'bold (format "$ %s\n" string))))
-  (let ((proc nil)
-       (lines (split-string string "\n")))
-    (set-buffer (tramp-get-buffer multi-method method user host))
-    (unless noerase (erase-buffer))
-    (setq proc (get-buffer-process (current-buffer)))
-    (mapcar (lambda (x)
-             (sleep-for 0.1)
-             (process-send-string proc
-                                  (concat x tramp-rsh-end-of-line)))
-           lines)))
+(defun tramp-send-command-internal
+  (multi-method method user host command &optional msg)
+  "Send command to remote host and wait for success.
+Sends COMMAND, then waits 30 seconds for shell prompt."
+  (tramp-send-command multi-method method user host command t t)
+  (when msg
+    (tramp-message 9 "Waiting 30s for %s..." msg))
+  (tramp-barf-if-no-shell-prompt
+   nil 30
+   "Couldn't `%s', see buffer `%s'" command (buffer-name)))
 
 (defun tramp-wait-for-output (&optional timeout)
   "Wait for output from remote rsh command."
   (let ((proc (get-buffer-process (current-buffer)))
         (found nil)
         (start-time (current-time))
+       (start-point (point))
         (end-of-output (concat "^"
                                (regexp-quote tramp-end-of-output)
                                "\r?$")))
@@ -5438,12 +6360,16 @@ the remote host use line-endings as defined in the variable
                (with-timeout (timeout)
                  (while (not found)
                    (accept-process-output proc 1)
+                  (unless (memq (process-status proc) '(run open))
+                    (error "Process has died"))
                    (goto-char (point-max))
                    (forward-line -1)
                    (setq found (looking-at end-of-output))))))
             (t
              (while (not found)
                (accept-process-output proc 1)
+              (unless (memq (process-status proc) '(run open))
+                (error "Process has died"))
                (goto-char (point-max))
                (forward-line -1)
                (setq found (looking-at end-of-output))))))
@@ -5453,6 +6379,12 @@ the remote host use line-endings as defined in the variable
       (goto-char (point-max))
       (forward-line -2)
       (delete-region (point) (point-max)))
+    ;; If processing echoes, look for it in the first line and delete.
+    (when tramp-process-echoes
+      (save-excursion
+       (goto-char start-point)
+       (when (looking-at (regexp-quote tramp-last-cmd))
+         (delete-region (point) (progn (forward-line 1) (point))))))
     ;; Add output to debug buffer if appropriate.
     (when tramp-debug-buffer
       (append-to-buffer
@@ -5518,34 +6450,49 @@ FMT and ARGS which are passed to `error'."
     (pop-to-buffer (current-buffer))
     (funcall 'signal signal (apply 'format fmt args))))
 
-;; Chunked sending kluge.
-(defvar tramp-chunksize nil
-  "If non-nil, chunksize for sending things to remote host.")
+;; It seems that Tru64 Unix does not like it if long strings are sent
+;; to it in one go.  (This happens when sending the Perl
+;; `file-attributes' implementation, for instance.)  Therefore, we
+;; have this function which waits a bit at each line.
+(defun tramp-send-string
+  (multi-method method user host string)
+  "Send the STRING to USER at HOST using METHOD.
 
-(defun tramp-send-region (multi-method method user host start end)
-  "Send the region from START to END to remote command
-running as USER on HOST using METHOD."
+The STRING is expected to use Unix line-endings, but the lines sent to
+the remote host use line-endings as defined in the variable
+`tramp-rsh-end-of-line'."
   (let ((proc (get-buffer-process
                (tramp-get-buffer multi-method method user host))))
     (unless proc
-      (error "Can't send region to remote host -- not logged in"))
-    (if tramp-chunksize
-       (let ((pos start))
+      (error "Can't send string to remote host -- not logged in"))
+    ;; debug message
+    (when tramp-debug-buffer
+      (save-excursion
+       (set-buffer (tramp-get-debug-buffer multi-method method user host))
+       (goto-char (point-max))
+       (tramp-insert-with-face 'bold (format "$ %s\n" string))))
+    ;; replace "\n" by `tramp-rsh-end-of-line'
+    (setq string
+         (mapconcat 'identity
+                    (split-string string "\n")
+                    tramp-rsh-end-of-line))
+    (unless (or (string= string "")
+               (string-equal (substring string -1) tramp-rsh-end-of-line))
+      (setq string (concat string tramp-rsh-end-of-line)))
+    ;; send the string
+    (if (and tramp-chunksize (not (zerop tramp-chunksize)))
+       (let ((pos 0)
+             (end (length string)))
          (while (< pos end)
            (tramp-message-for-buffer
             multi-method method user host 10
-            "Sending chunk from %s to %s" pos end)
-           (process-send-region proc
-                                pos
-                                (min (+ pos tramp-chunksize)
-                                     end))
+            "Sending chunk from %s to %s"
+            pos (min (+ pos tramp-chunksize) end))
+           (process-send-string
+            proc (substring string pos (min (+ pos tramp-chunksize) end)))
            (setq pos (+ pos tramp-chunksize))
            (sleep-for 0.1)))
-      (process-send-region proc start end))
-    (when tramp-debug-buffer
-      (append-to-buffer
-       (tramp-get-debug-buffer multi-method method user host)
-       start end))))
+      (process-send-string proc string))))
 
 (defun tramp-send-eof (multi-method method user host)
   "Send EOF to the remote end.
@@ -5631,6 +6578,26 @@ If `tramp-discard-garbage' is nil, just erase buffer."
          (t (error "Tenth char `%c' must be one of `xtT-'"
                    other-execute-or-sticky)))))))
 
+(defun tramp-convert-file-attributes (multi-method method user host attr)
+  "Convert file-attributes ATTR generated by perl script or ls.
+Convert file mode bits to string and set virtual device number.
+Return ATTR."
+  (unless (stringp (nth 8 attr))
+    ;; Convert file mode bits to string.
+    (setcar (nthcdr 8 attr) (tramp-file-mode-from-int (nth 8 attr))))
+  ;; Set virtual device number.
+  (setcar (nthcdr 11 attr)
+          (tramp-get-device multi-method method user host))
+  attr)
+
+(defun tramp-get-device (multi-method method user host)
+  "Returns the virtual device number.
+If it doesn't exist, generate a new one."
+  (let ((string (tramp-make-tramp-file-name multi-method method user host "")))
+    (unless (assoc string tramp-devices)
+      (add-to-list 'tramp-devices
+                  (list string (length tramp-devices))))
+    (list -1 (nth 1 (assoc string tramp-devices)))))
 
 (defun tramp-file-mode-from-int (mode)
   "Turn an integer representing a file mode into an ls(1)-like string."
@@ -5700,27 +6667,27 @@ Not actually used.  Use `(format \"%o\" i)' instead?"
    ""))
 
 
-;; ------------------------------------------------------------ 
-;; -- TRAMP file names -- 
-;; ------------------------------------------------------------ 
+;; ------------------------------------------------------------
+;; -- TRAMP file names --
+;; ------------------------------------------------------------
 ;; Conversion functions between external representation and
 ;; internal data structure.  Convenience functions for internal
 ;; data structure.
 
-(defstruct tramp-file-name multi-method method user host path)
+(defstruct tramp-file-name multi-method method user host localname)
 
 (defun tramp-tramp-file-p (name)
   "Return t iff NAME is a tramp file."
   (save-match-data
     (string-match tramp-file-name-regexp name)))
+
 ;; HHH: Changed.  Used to assign the return value of (user-login-name)
 ;;      to the `user' part of the structure if a user name was not
 ;;      provided, now it assigns nil.
 (defun tramp-dissect-file-name (name)
   "Return an `tramp-file-name' structure.
 The structure consists of remote method, remote user, remote host and
-remote path name."
+localname (file name on remote host)."
   (save-match-data
     (let* ((match (string-match (nth 0 tramp-file-name-structure) name))
           (method
@@ -5739,13 +6706,13 @@ remote path name."
        (unless match (error "Not a tramp file name: %s" name))
        (let ((user (match-string (nth 2 tramp-file-name-structure) name))
              (host (match-string (nth 3 tramp-file-name-structure) name))
-             (path (match-string (nth 4 tramp-file-name-structure) name)))
+             (localname (match-string (nth 4 tramp-file-name-structure) name)))
          (make-tramp-file-name
           :multi-method nil
           :method method
           :user (or user nil)
           :host host
-          :path path))))))
+          :localname localname))))))
 
 (defun tramp-find-default-method (user host)
   "Look up the right method to use in `tramp-default-method-alist'."
@@ -5766,7 +6733,7 @@ This is MULTI-METHOD, if non-nil.  Otherwise, it is METHOD, if non-nil.
 If both MULTI-METHOD and METHOD are nil, do a lookup in
 `tramp-default-method-alist'."
   (or multi-method method (tramp-find-default-method user host)))
-    
+
 ;; HHH: Not Changed.  Multi method.  Will probably not handle the case where
 ;;      a user name is not provided in the "file name" very well.
 (defun tramp-dissect-multi-file-name (name)
@@ -5774,19 +6741,19 @@ If both MULTI-METHOD and METHOD are nil, do a lookup in
   (let ((regexp           (nth 0 tramp-multi-file-name-structure))
         (method-index     (nth 1 tramp-multi-file-name-structure))
         (hops-index       (nth 2 tramp-multi-file-name-structure))
-        (path-index       (nth 3 tramp-multi-file-name-structure))
+        (localname-index       (nth 3 tramp-multi-file-name-structure))
         (hop-regexp       (nth 0 tramp-multi-file-name-hop-structure))
         (hop-method-index (nth 1 tramp-multi-file-name-hop-structure))
         (hop-user-index   (nth 2 tramp-multi-file-name-hop-structure))
         (hop-host-index   (nth 3 tramp-multi-file-name-hop-structure))
-        method hops len hop-methods hop-users hop-hosts path)
+        method hops len hop-methods hop-users hop-hosts localname)
     (unless (string-match (format regexp hop-regexp) name)
       (error "Not a multi tramp file name: %s" name))
     (setq method (match-string method-index name))
     (setq hops (match-string hops-index name))
     (setq len (/ (length (match-data t)) 2))
-    (when (< path-index 0) (incf path-index len))
-    (setq path (match-string path-index name))
+    (when (< localname-index 0) (incf localname-index len))
+    (setq localname (match-string localname-index name))
     (let ((index 0))
       (while (string-match hop-regexp hops index)
         (setq index (match-end 0))
@@ -5801,32 +6768,32 @@ If both MULTI-METHOD and METHOD are nil, do a lookup in
      :method       (apply 'vector (reverse hop-methods))
      :user         (apply 'vector (reverse hop-users))
      :host         (apply 'vector (reverse hop-hosts))
-     :path         path)))
+     :localname         localname)))
 
-(defun tramp-make-tramp-file-name (multi-method method user host path)
-  "Constructs a tramp file name from METHOD, USER, HOST and PATH."
+(defun tramp-make-tramp-file-name (multi-method method user host localname)
+  "Constructs a tramp file name from METHOD, USER, HOST and LOCALNAME."
   (if multi-method
-      (tramp-make-tramp-multi-file-name multi-method method user host path)
+      (tramp-make-tramp-multi-file-name multi-method method user host localname)
     (format-spec
      (concat tramp-prefix-format
       (when method (concat "%m" tramp-postfix-single-method-format))
       (when user   (concat "%u" tramp-postfix-user-format))
       (when host   (concat "%h" tramp-postfix-host-format))
-      (when path   (concat "%p")))
-    `((?m . ,method) (?u . ,user) (?h . ,host) (?p . ,path)))))
+      (when localname   (concat "%p")))
+    `((?m . ,method) (?u . ,user) (?h . ,host) (?p . ,localname)))))
 
 ;; CCC: Henrik Holm: Not Changed.  Multi Method.  What should be done
 ;; with this when USER is nil?
-(defun tramp-make-tramp-multi-file-name (multi-method method user host path)
+(defun tramp-make-tramp-multi-file-name (multi-method method user host localname)
   "Constructs a tramp file name for a multi-hop method."
   (unless tramp-make-multi-tramp-file-format
     (error "`tramp-make-multi-tramp-file-format' is nil"))
   (let* ((prefix-format (nth 0 tramp-make-multi-tramp-file-format))
          (hop-format    (nth 1 tramp-make-multi-tramp-file-format))
-         (path-format   (nth 2 tramp-make-multi-tramp-file-format))
+         (localname-format   (nth 2 tramp-make-multi-tramp-file-format))
          (prefix (format-spec prefix-format `((?m . ,multi-method))))
          (hops "")
-         (path (format-spec path-format `((?p . ,path))))
+         (localname (format-spec localname-format `((?p . ,localname))))
          (i 0)
          (len (length method)))
     (while (< i len)
@@ -5834,22 +6801,20 @@ If both MULTI-METHOD and METHOD are nil, do a lookup in
         (setq hops (concat hops (format-spec hop-format
                                             `((?m . ,m) (?u . ,u) (?h . ,h)))))
         (incf i)))
-    (concat prefix hops path)))
+    (concat prefix hops localname)))
 
-(defun tramp-make-rcp-program-file-name (user host path)
-  "Create a file name suitable to be passed to `rcp'."
+(defun tramp-make-copy-program-file-name (user host localname)
+  "Create a file name suitable to be passed to `rcp' and workalikes."
   (if user
-      (format "%s@%s:%s" user host path)
-    (format "%s:%s" host path)))
+      (format "%s@%s:%s" user host localname)
+    (format "%s:%s" host localname)))
 
 (defun tramp-method-out-of-band-p (multi-method method user host)
-  "Return t if this is an out-of-band method, nil otherwise.
-It is important to check for this condition, since it is not possible
-to enter a password for the `tramp-rcp-program'."
-  (tramp-get-rcp-program
+  "Return t if this is an out-of-band method, nil otherwise."
+  (tramp-get-method-parameter
    multi-method
    (tramp-find-method multi-method method user host)
-   user host))
+   user host 'tramp-copy-program))
 
 ;; Variables local to connection.
 
@@ -5928,84 +6893,18 @@ If the value is not set for the connection, return `default'"
   (tramp-get-connection-property "local-decoding" nil
                                 multi-method method user host))
 
-
-
-(defun tramp-get-connection-function (multi-method method user host)
-  (second (or (assoc 'tramp-connection-function
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify a connection function"
-                     (or multi-method method)))))
-
-(defun tramp-get-remote-sh (multi-method method user host)
-  (second (or (assoc 'tramp-remote-sh
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify a remote shell"
-                     (or multi-method method)))))
-
-(defun tramp-get-rsh-program (multi-method method user host)
-  (second (or (assoc 'tramp-rsh-program
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify an rsh program"
-                     (or multi-method method)))))
-
-(defun tramp-get-rsh-args (multi-method method user host)
-  (second (or (assoc 'tramp-rsh-args
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify rsh args"
-                     (or multi-method method)))))
-
-(defun tramp-get-rcp-program (multi-method method user host)
-  (second (or (assoc 'tramp-rcp-program
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify an rcp program"
-                     (or multi-method method)))))
-
-(defun tramp-get-rcp-args (multi-method method user host)
-  (second (or (assoc 'tramp-rcp-args
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify rcp args"
-                     (or multi-method method)))))
-
-(defun tramp-get-rcp-keep-date-arg (multi-method method user host)
-  (second (or (assoc 'tramp-rcp-keep-date-arg
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify `keep-date' arg for tramp"
-                     (or multi-method method)))))
-
-(defun tramp-get-su-program (multi-method method user host)
-  (second (or (assoc 'tramp-su-program
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify a su program"
-                     (or multi-method method)))))
-
-(defun tramp-get-su-args (multi-method method user host)
-  (second (or (assoc 'tramp-su-args
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify su args"
-                     (or multi-method method)))))
-
-(defun tramp-get-telnet-program (multi-method method user host)
-  (second (or (assoc 'tramp-telnet-program
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify a telnet program"
-                     (or multi-method method)))))
-
-(defun tramp-get-telnet-args (multi-method method user host)
-  (second (or (assoc 'tramp-telnet-args
-                     (assoc (tramp-find-method multi-method method user host)
-                            tramp-methods))
-              (error "Method `%s' didn't specify telnet args"
-                     (or multi-method method)))))
+(defun tramp-get-method-parameter (multi-method method user host param)
+  "Return the method parameter PARAM.
+If the `tramp-methods' entry does not exist, use the variable PARAM
+as default."
+  (unless (boundp param)
+    (error "Non-existing method parameter `%s'" param))
+  (let ((entry (assoc param
+                     (assoc (tramp-find-method multi-method method user host)
+                            tramp-methods))))
+    (if entry
+       (second entry)
+      (symbol-value param))))
 
 
 ;; Auto saving to a special directory.
@@ -6038,6 +6937,31 @@ If the value is not set for the connection, return `default'"
             (tramp-make-auto-save-file-name (buffer-file-name)))
     ad-do-it))
 
+;; In Emacs < 22.1 and XEmacs < 21.5 autosaved remote files have
+;; permission 666 minus umask. This is a security threat.
+
+(defun tramp-set-auto-save-file-modes ()
+  "Set permissions of autosaved remote files to the original permissions."
+  (let ((bfn (buffer-file-name)))
+    (when (and (stringp bfn)
+              (tramp-tramp-file-p bfn)
+              (stringp buffer-auto-save-file-name)
+              (not (equal bfn buffer-auto-save-file-name))
+              (not (file-exists-p buffer-auto-save-file-name)))
+      (write-region "" nil buffer-auto-save-file-name)
+      (set-file-modes buffer-auto-save-file-name (file-modes bfn)))))
+
+(unless (or (> emacs-major-version 21)
+           (and (featurep 'xemacs)
+                (= emacs-major-version 21)
+                (> emacs-minor-version 4))
+           (and (not (featurep 'xemacs))
+                (= emacs-major-version 21)
+                (or (> emacs-minor-version 3)
+                    (and (string-match "^21\\.3\\.\\([0-9]+\\)" emacs-version)
+                         (>= (string-to-int (match-string 1 emacs-version)) 50)))))
+  (add-hook 'auto-save-hook 'tramp-set-auto-save-file-modes))
+
 (defun tramp-subst-strs-in-string (alist string)
   "Replace all occurrences of the string FROM with TO in STRING.
 ALIST is of the form ((FROM . TO) ...)."
@@ -6080,12 +7004,28 @@ this is the function `temp-directory'."
                             "`temp-directory' is defined -- using /tmp."))
            (file-name-as-directory "/tmp"))))
 
-(defun tramp-read-passwd (prompt)
+(defun tramp-read-passwd (user host prompt)
   "Read a password from user (compat function).
-Invokes `read-passwd' if that is defined, else `ange-ftp-read-passwd'."
-  (apply
-   (if (fboundp 'read-passwd) #'read-passwd #'ange-ftp-read-passwd)
-   (list prompt)))
+Invokes `password-read' if available, `read-passwd' else."
+  (if (functionp 'password-read)
+      (let* ((key (concat (or user (user-login-name)) "@" host))
+            (password (apply #'password-read (list prompt key))))
+       (apply #'password-cache-add (list key password))
+       password)
+    (read-passwd prompt)))
+
+(defun tramp-clear-passwd (&optional user host)
+  "Clear password cache for connection related to current-buffer."
+  (interactive)
+  (let ((filename (or buffer-file-name list-buffers-directory "")))
+    (when (and (functionp 'password-cache-remove)
+              (or (and user host) (tramp-tramp-file-p filename)))
+      (let* ((v (when (tramp-tramp-file-p filename)
+                 (tramp-dissect-file-name filename)))
+            (luser (or user (tramp-file-name-user v) (user-login-name)))
+            (lhost (or host (tramp-file-name-host v) (system-name)))
+            (key (concat luser "@" lhost)))
+       (apply #'password-cache-remove (list key))))))
 
 (defun tramp-time-diff (t1 t2)
   "Return the difference between the two times, in seconds.
@@ -6094,18 +7034,28 @@ T1 and T2 are time values (as returned by `current-time' for example).
 NOTE: This function will fail if the time difference is too large to
 fit in an integer."
   ;; Pacify byte-compiler with `symbol-function'.
-  (cond ((fboundp 'subtract-time)
-         (cadr (funcall (symbol-function 'subtract-time) t1 t2)))
+  (cond ((and (fboundp 'subtract-time)
+             (fboundp 'float-time))
+         (funcall (symbol-function 'float-time)
+                 (funcall (symbol-function 'subtract-time) t1 t2)))
+       ((and (fboundp 'subtract-time)
+             (fboundp 'time-to-seconds))
+         (funcall (symbol-function 'time-to-seconds)
+                 (funcall (symbol-function 'subtract-time) t1 t2)))
         ((fboundp 'itimer-time-difference)
          (floor (funcall
                 (symbol-function 'itimer-time-difference)
                 (if (< (length t1) 3) (append t1 '(0)) t1)
                 (if (< (length t2) 3) (append t2 '(0)) t2))))
         (t
-         ;; snarfed from Emacs 21 time-date.el
-         (cadr (let ((borrow (< (cadr t1) (cadr t2))))
+         ;; snarfed from Emacs 21 time-date.el; combining
+        ;; time-to-seconds and subtract-time
+        (let ((time  (let ((borrow (< (cadr t1) (cadr t2))))
                  (list (- (car t1) (car t2) (if borrow 1 0))
-                       (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))))))
+                       (- (+ (if borrow 65536 0) (cadr t1)) (cadr t2))))))
+          (+ (* (car time) 65536.0)
+             (cadr time)
+             (/ (or (nth 2 time) 0) 1000000.0))))))
 
 (defun tramp-coding-system-change-eol-conversion (coding-system eol-type)
   "Return a coding system like CODING-SYSTEM but with given EOL-TYPE.
@@ -6137,9 +7087,19 @@ If you want to use it for something else, you'll have to check whether
 it does the right thing."
   (delete "" (split-string string pattern)))
 
-;; ------------------------------------------------------------ 
-;; -- Kludges section -- 
-;; ------------------------------------------------------------ 
+(defun tramp-set-process-query-on-exit-flag (process flag)
+  "Specify if query is needed for process when Emacs is exited.
+If the second argument flag is non-nil, Emacs will query the user before
+exiting if process is running."
+  (if (fboundp 'set-process-query-on-exit-flag)
+      (set-process-query-on-exit-flag process flag)
+    (funcall (symbol-function 'process-kill-without-query)
+            process flag)))
+
+
+;; ------------------------------------------------------------
+;; -- Kludges section --
+;; ------------------------------------------------------------
 
 ;; Currently (as of Emacs 20.5), the function `shell-quote-argument'
 ;; does not deal well with newline characters.  Newline is replaced by
@@ -6183,7 +7143,7 @@ Only works for Bourne-like shells."
 
 ;; ;; EFS hooks itself into the file name handling stuff in more places
 ;; ;; than just `file-name-handler-alist'. The following tells EFS to stay
-;; ;; away from tramp.el paths.
+;; ;; away from tramp.el file names.
 ;; ;;
 ;; ;; This is needed because EFS installs (efs-dired-before-readin) into
 ;; ;; 'dired-before-readin-hook'. This prevents EFS from opening an FTP
@@ -6198,8 +7158,8 @@ Only works for Bourne-like shells."
 ;; ;; not to call defadvice unless it's necessary.  How do we find out whether
 ;; ;; it is necessary?  (featurep 'efs) is surely the wrong way --
 ;; ;; EFS might nicht be loaded yet.
-;; (defadvice efs-ftp-path (around dont-match-tramp-path activate protect)
-;;   "Cause efs-ftp-path to fail when the path is a TRAMP path."
+;; (defadvice efs-ftp-path (around dont-match-tramp-localname activate protect)
+;;   "Cause efs-ftp-path to fail when the path is a TRAMP localname."
 ;;   (if (tramp-tramp-file-p (ad-get-arg 0))
 ;;       nil
 ;;     ad-do-it))
@@ -6220,7 +7180,7 @@ Only works for Bourne-like shells."
        ;; If it's a Tramp file, dissect it and look if wildcards
        ;; need to be expanded at all.
        (let ((v (tramp-dissect-file-name name)))
-         (if (string-match "[[*?]" (tramp-file-name-path v))
+         (if (string-match "[[*?]" (tramp-file-name-localname v))
              (let ((res ad-do-it))
                (setq ad-return-value (or res (list name))))
            (setq ad-return-value (list name))))
@@ -6263,13 +7223,15 @@ Only works for Bourne-like shells."
        tramp-auto-save-directory        ; vars to dump
        tramp-default-method
        tramp-rsh-end-of-line
-       tramp-password-end-of-line
+       tramp-default-password-end-of-line
        tramp-remote-path
        tramp-login-prompt-regexp
        tramp-password-prompt-regexp
        tramp-wrong-passwd-regexp
        tramp-yesno-prompt-regexp
        tramp-yn-prompt-regexp
+       tramp-terminal-prompt-regexp
+       tramp-out-of-band-prompt-regexp
        tramp-temp-name-prefix
        tramp-file-name-structure
        tramp-file-name-regexp
@@ -6281,9 +7243,15 @@ Only works for Bourne-like shells."
        tramp-end-of-output
        tramp-coding-commands
        tramp-actions-before-shell
+       tramp-actions-copy-out-of-band
        tramp-multi-actions
        tramp-terminal-type
        tramp-shell-prompt-pattern
+       tramp-chunksize
+       ,(when (boundp 'tramp-backup-directory-alist)
+         'tramp-backup-directory-alist)
+       ,(when (boundp 'tramp-bkup-backup-directory-info)
+         'tramp-bkup-backup-directory-info)
 
        ;; Non-tramp variables of interest
        shell-prompt-pattern
@@ -6292,6 +7260,14 @@ Only works for Bourne-like shells."
        backup-by-copying-when-mismatch
        ,(when (boundp 'backup-by-copying-when-privileged-mismatch)
           'backup-by-copying-when-privileged-mismatch)
+       ,(when (boundp 'password-cache)
+          'password-cache)
+       ,(when (boundp 'password-cache-expiry)
+          'password-cache-expiry)
+       ,(when (boundp 'backup-directory-alist)
+         'backup-directory-alist)
+       ,(when (boundp 'bkup-backup-directory-info)
+         'bkup-backup-directory-info)
        file-name-handler-alist)
      nil                               ; pre-hook
      nil                               ; post-hook
@@ -6354,7 +7330,6 @@ report.
 ;; * Rewrite `tramp-shell-quote-argument' to abstain from using
 ;;   `shell-quote-argument'.
 ;; * Completion gets confused when you leave out the method name.
-;; * Support `dired-compress-file' filename handler.
 ;; * In Emacs 21, `insert-directory' shows total number of bytes used
 ;;   by the files in that directory.  Add this here.
 ;; * Avoid screen blanking when hitting `g' in dired.  (Eli Tziperman)
@@ -6375,41 +7350,32 @@ report.
 ;;   if it does show files when run locally.
 ;; * Allow correction of passwords, if the remote end allows this.
 ;;   (Mark Hershberger)
-;; * Make sure permissions of tmp file are good.
-;;   (Nelson Minar <nelson@media.mit.edu>)
-;; * Grok passwd prompts with scp?  (David Winter
-;;   <winter@nevis1.nevis.columbia.edu>).  Maybe just do `ssh -l user
-;;   host', then wait a while for the passwd or passphrase prompt.  If
-;;   there is one, remember the passwd/phrase.
 ;; * How to deal with MULE in `insert-file-contents' and `write-region'?
 ;; * Do asynchronous `shell-command's.
 ;; * Grok `append' parameter for `write-region'.
 ;; * Test remote ksh or bash for tilde expansion in `tramp-find-shell'?
 ;; * abbreviate-file-name
 ;; * grok ~ in tramp-remote-path  (Henrik Holm <henrikh@tele.ntnu.no>)
-;; * `C' in dired gives error `not tramp file name'.
 ;; * Also allow to omit user names when doing multi-hop.  Not sure yet
 ;;   what the user names should default to, though.
 ;; * better error checking.  At least whenever we see something
 ;;   strange when doing zerop, we should kill the process and start
 ;;   again.  (Greg Stark)
 ;; * Add caching for filename completion.  (Greg Stark)
-;;   Of course, this has issues with usability (stale cache bites) 
+;;   Of course, this has issues with usability (stale cache bites)
 ;;      -- <daniel@danann.net>
 ;; * Provide a local cache of old versions of remote files for the rsync
 ;;   transfer method to use.  (Greg Stark)
 ;; * Remove unneeded parameters from methods.
 ;; * Invoke rsync once for copying a whole directory hierarchy.
-;;   (Francesco Potortì)
+;;   (Francesco Potort\e,Al\e(B)
 ;; * Should we set PATH ourselves or should we rely on the remote end
 ;;   to do it?
-;; * Do the autoconf thing.
 ;; * Make it work for XEmacs 20, which is missing `with-timeout'.
-;; * Allow non-Unix remote systems.  (More a long-term thing.)
 ;; * Make it work for different encodings, and for different file name
 ;;   encodings, too.  (Daniel Pittman)
 ;; * Change applicable functions to pass a struct tramp-file-name rather
-;;   than the individual items MULTI-METHOD, METHOD, USER, HOST, PATH.
+;;   than the individual items MULTI-METHOD, METHOD, USER, HOST, LOCALNAME.
 ;; * Implement asynchronous shell commands.
 ;; * Clean up unused *tramp/foo* buffers after a while.  (Pete Forman)
 ;; * Progress reports while copying files.  (Michael Kifer)
@@ -6420,13 +7386,6 @@ report.
 ;; * When editing a remote CVS controlled file as a different user, VC
 ;;   gets confused about the file locking status.  Try to find out why
 ;;   the workaround doesn't work.
-;; * When user is running ssh-agent, it would be useful to add the
-;;   passwords typed by the user to that agent.  This way, the next time
-;;   round, the users don't have to type all this in again.
-;;   This would be especially useful for start-process, I think.
-;;   An easy way to implement start-process is to open a second shell
-;;   connection which is inconvenient if the user has to reenter
-;;   passwords.
 ;; * Change `copy-file' to grok the case where the filename handler
 ;;   for the source and the target file are different.  Right now,
 ;;   it looks at the source file and then calls that handler, if
@@ -6439,27 +7398,22 @@ report.
 ;;    how to suppress. Maybe not an essential problem.
 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode'.
 ;; ** Extend `tramp-get-completion-su' for NIS and shadow passwords.
-;; ** Unify `tramp-parse-{rhosts,shosts,hosts,passwd,netrc}'.
+;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.
 ;;    Code is nearly identical.
 ;; ** Decide whiche files to take for searching user/host names depending on
 ;;    operating system (windows-nt) in `tramp-completion-function-alist'.
 ;; ** Enhance variables for debug.
 ;; ** Implement "/multi:" completion.
 ;; ** Add a learning mode for completion. Make results persistent.
+;; * Allow out-of-band methods as _last_ multi-hop.
 
 ;; Functions for file-name-handler-alist:
 ;; diff-latest-backup-file -- in diff.el
-;; dired-compress-file
 ;; dired-uncache -- this will be needed when we do insert-directory caching
 ;; file-name-as-directory -- use primitive?
-;; file-name-directory -- use primitive?
-;; file-name-nondirectory -- use primitive?
 ;; file-name-sans-versions -- use primitive?
-;; file-newer-than-file-p
-;; find-backup-file-name
 ;; get-file-buffer -- use primitive
-;; load
-;; unhandled-file-name-directory
 ;; vc-registered
 
+;;; arch-tag: 3a21a994-182b-48fa-b0cd-c1d9fede424a
 ;;; tramp.el ends here