Merge from emacs-23; up to 2010-06-22T07:41:10Z!rgm@gnu.org
[bpt/emacs.git] / lisp / net / tramp.el
index 6475ea4..5fca101 100644 (file)
@@ -58,7 +58,6 @@
 ;;; Code:
 
 (require 'tramp-compat)
-(require 'shell)
 
 ;;; User Customizable Internal Variables:
 
@@ -192,15 +191,16 @@ This is a list of entries of the form (NAME PARAM1 PARAM2 ...).
 Each NAME stands for a remote access method.  Each PARAM is a
 pair of the form (KEY VALUE).  The following KEYs are defined:
   * `tramp-remote-shell'
-    This specifies the Bourne shell to use on the remote host.  This
-    MUST be a Bourne-like shell.  It is normally not necessary to set
-    this to any value other than \"/bin/sh\": Tramp wants to use a shell
-    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.
+    This specifies the shell to use on the remote host.  This
+    MUST be a Bourne-like shell.  It is normally not necessary to
+    set this to any value other than \"/bin/sh\": Tramp wants to
+    use a shell 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-remote-shell-args'
     For implementation of `shell-command', this specifies the
-    argument to let `tramp-remote-shell' run a command.
+    arguments to let `tramp-remote-shell' run a single command.
   * `tramp-login-program'
     This specifies the name of the program to use for logging in to the
     remote host.  This may be the name of rsh or a workalike program,
@@ -255,6 +255,9 @@ pair of the form (KEY VALUE).  The following KEYs are defined:
     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\".
+  * `tramp-tmpdir'
+    A directory on the remote host for temporary files.  If not
+    specified, \"/tmp\" is taken as default.
 
 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,
@@ -1603,24 +1606,28 @@ This is intended to be used as a minibuffer `post-command-hook' for
 `file-name-shadow-mode'; the minibuffer should have already
 been set up by `rfn-eshadow-setup-minibuffer'."
   ;; In remote files name, there is a shadowing just for the local part.
-  (let ((end (or (tramp-compat-funcall
-                 'overlay-end (symbol-value 'rfn-eshadow-overlay))
-                (tramp-compat-funcall 'minibuffer-prompt-end))))
-    (when
-       (file-remote-p
-        (tramp-compat-funcall 'buffer-substring-no-properties end (point-max)))
-      (save-excursion
-       (save-restriction
-         (narrow-to-region
-          (1+ (or (string-match
-                   tramp-rfn-eshadow-update-overlay-regexp (buffer-string) end)
-                  end))
-          (point-max))
-         (let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay)
-               (rfn-eshadow-update-overlay-hook nil))
-           (tramp-compat-funcall
-            'move-overlay rfn-eshadow-overlay (point-max) (point-max))
-           (tramp-compat-funcall 'rfn-eshadow-update-overlay)))))))
+  (ignore-errors
+    (let ((end (or (tramp-compat-funcall
+                   'overlay-end (symbol-value 'rfn-eshadow-overlay))
+                  (tramp-compat-funcall 'minibuffer-prompt-end))))
+      (when
+         (file-remote-p
+          (tramp-compat-funcall
+           'buffer-substring-no-properties end (point-max)))
+       (save-excursion
+         (save-restriction
+           (narrow-to-region
+            (1+ (or (string-match
+                     tramp-rfn-eshadow-update-overlay-regexp
+                     (buffer-string) end)
+                    end))
+            (point-max))
+           (let ((rfn-eshadow-overlay tramp-rfn-eshadow-overlay)
+                 (rfn-eshadow-update-overlay-hook nil)
+                 file-name-handler-alist)
+             (tramp-compat-funcall
+              'move-overlay rfn-eshadow-overlay (point-max) (point-max))
+             (tramp-compat-funcall 'rfn-eshadow-update-overlay))))))))
 
 (when (boundp 'rfn-eshadow-update-overlay-hook)
   (add-hook 'rfn-eshadow-update-overlay-hook
@@ -1879,11 +1886,11 @@ Falls back to normal file name handler if no Tramp file name handler exists."
                      (when (and (listp sf) (eq (car sf) 'autoload))
                        (let ((default-directory
                                (tramp-compat-temporary-file-directory)))
-                         (load (cadr sf) 'noerror)))
+                         (load (cadr sf) 'noerror 'nomessage)))
                      (apply foreign operation args))
 
                  ;; Trace that somebody has interrupted the operation.
-                 (quit
+                 ((debug quit)
                   (let (tramp-message-show-message)
                     (tramp-message
                      v 1 "Interrupt received in operation %s"
@@ -1895,6 +1902,9 @@ Falls back to normal file name handler if no Tramp file name handler exists."
                  ;; operations shall return at least a default value
                  ;; in order to give the user a chance to correct the
                  ;; file name in the minibuffer.
+                 ;; We cannot use 'debug as error handler.  In order
+                 ;; to get a full backtrace, one could apply
+                 ;;   (setq debug-on-error t debug-on-signal t)
                  (error
                   (cond
                    ((and completion (zerop (length localname))
@@ -2093,8 +2103,9 @@ This is true, if either the remote host is already connected, or if we are
 not in completion mode."
   (and (tramp-tramp-file-p filename)
        (with-parsed-tramp-file-name filename nil
-        (or (get-buffer (tramp-buffer-name v))
-            (not (tramp-completion-mode-p))))))
+        (or (not (tramp-completion-mode-p))
+            (let ((p (tramp-get-connection-process v)))
+              (and p (processp p) (memq (process-status p) '(run open))))))))
 
 ;; Method, host name and user name completion.
 ;; `tramp-completion-dissect-file-name' returns a list of
@@ -3021,11 +3032,13 @@ User is always nil."
     (if (and (not current-buffer-p) (integerp asynchronous))
        (prog1
            ;; Run the process.
-           (apply 'start-file-process "*Async Shell*" buffer args)
+           (setq p (apply 'start-file-process "*Async Shell*" buffer args))
          ;; Display output.
          (pop-to-buffer output-buffer)
          (setq mode-line-process '(":%s"))
-         (shell-mode))
+         (shell-mode)
+         (set-process-sentinel p 'shell-command-sentinel)
+         (set-process-filter p 'comint-output-filter))
 
       (prog1
          ;; Run the process.
@@ -3531,20 +3544,26 @@ If the `tramp-methods' entry does not exist, return nil."
         ;; loaded already.
         (zerop (tramp-compat-funcall 'tramp-get-remote-uid vec 'integer))))))
 
+(defun tramp-get-remote-tmpdir (vec)
+  "Return directory for temporary files on the remote host identified by VEC."
+  (with-connection-property vec "tmpdir"
+    (let ((dir (tramp-make-tramp-file-name
+               (tramp-file-name-method vec)
+               (tramp-file-name-user vec)
+               (tramp-file-name-host vec)
+               (or
+                (tramp-get-method-parameter
+                 (tramp-file-name-method vec) 'tramp-tmpdir)
+                "/tmp"))))
+      (if (and (file-directory-p dir) (file-writable-p dir))
+         dir
+       (tramp-error vec 'file-error "Directory %s not accessible" dir)))))
+
 (defun tramp-make-tramp-temp-file (vec)
   "Create a temporary file on the remote host identified by VEC.
 Return the local name of the temporary file."
-  (let ((prefix
-        (tramp-make-tramp-file-name
-         (tramp-file-name-method vec)
-         (tramp-file-name-user vec)
-         (tramp-file-name-host vec)
-         (tramp-drop-volume-letter
-          (expand-file-name
-           tramp-temp-name-prefix
-           ;; This is defined in tramp-sh.el.  Let's assume this is
-           ;; loaded already.
-           (tramp-compat-funcall 'tramp-get-remote-tmpdir vec)))))
+  (let ((prefix (expand-file-name
+                tramp-temp-name-prefix (tramp-get-remote-tmpdir vec)))
        result)
     (while (not result)
       ;; `make-temp-file' would be the natural choice for
@@ -3839,9 +3858,9 @@ Only works for Bourne-like shells."
 ;; * Run emerge on two remote files.  Bug is described here:
 ;;   <http://www.mail-archive.com/tramp-devel@nongnu.org/msg01041.html>.
 ;;   (Bug#6850)
-
-;; Functions for file-name-handler-alist:
-;; diff-latest-backup-file -- in diff.el
+;; * It would be very useful if it were possible to load or save a
+;;   buffer using Tramp in a non-blocking way so that use of Emacs on
+;;   other buffers could continue.  (Bug#9617)
 
 ;;; tramp.el ends here