changeset 91486:76c777ce052a

* net/tramp.el (tramp-process-sentinel): New defun. (tramp-do-copy-or-rename-file-out-of-band) (tramp-maybe-open-connection): Use it as process sentinel. (tramp-handle-delete-directory): Don't use the "-f" option; it isn't portable. (tramp-handle-start-file-process): Echo `tramp-end-of-output' after the command. (tramp-handle-shell-command): Set `mode-line-process' in the asynchronous case.
author Michael Albinus <michael.albinus@gmx.de>
date Sun, 03 Feb 2008 12:05:05 +0000
parents 202f9737703b
children f8cab158daf2
files lisp/net/tramp.el
diffstat 1 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/net/tramp.el	Sun Feb 03 12:02:39 2008 +0000
+++ b/lisp/net/tramp.el	Sun Feb 03 12:05:05 2008 +0000
@@ -3274,7 +3274,7 @@
 				(append copy-args (list source target))))))
 		(tramp-message
 		 v 6 "%s" (mapconcat 'identity (process-command p) " "))
-		(set-process-sentinel p 'tramp-flush-connection-property)
+		(set-process-sentinel p 'tramp-process-sentinel)
 		(tramp-set-process-query-on-exit-flag p nil)
 		(tramp-process-actions p v tramp-actions-copy-out-of-band))))
 
@@ -3315,8 +3315,7 @@
     (tramp-flush-directory-property v localname)
     (unless (zerop (tramp-send-command-and-check
 		    v
-		    (format "rmdir -f %s"
-			    (tramp-shell-quote-argument localname))))
+		    (format "rmdir %s" (tramp-shell-quote-argument localname))))
       (tramp-error v 'file-error "Couldn't delete %s" directory))))
 
 (defun tramp-handle-delete-file (filename)
@@ -3649,9 +3648,10 @@
 	  ;; Send the command.
 	  (tramp-send-command
 	   v
-	   (format "%s; exit"
+	   (format "%s; echo %s; exit"
 		   (mapconcat 'tramp-shell-quote-argument
-			      (cons program args) " "))
+			      (cons program args) " ")
+		   (tramp-shell-quote-argument tramp-end-of-output))
 	   nil t) ; nooutput
 	  ;; Return process.
 	  (tramp-get-connection-process v))
@@ -3804,13 +3804,13 @@
 	      (with-parsed-tramp-file-name default-directory nil
 		(list output-buffer (tramp-make-tramp-temp-file v)))
 	    output-buffer))
-	 (proc (get-buffer-process output-buffer)))
+	 (p (get-buffer-process output-buffer)))
 
     ;; Check whether there is another process running.  Tramp does not
     ;; support 2 (asynchronous) processes in parallel.
-    (when proc
+    (when p
       (if (yes-or-no-p "A command is running.  Kill it? ")
-	  (ignore-errors (kill-process proc))
+	  (ignore-errors (kill-process p))
 	(error "Shell command in progress")))
 
     (with-current-buffer output-buffer
@@ -3823,7 +3823,9 @@
 	    ;; Run the process.
 	    (apply 'start-file-process "*Async Shell*" buffer args)
 	  ;; Display output.
-	  (pop-to-buffer output-buffer))
+	  (pop-to-buffer output-buffer)
+	  (setq mode-line-process '(":%s"))
+	  (require 'shell) (shell-mode))
 
       (prog1
 	  ;; Run the process.
@@ -4190,7 +4192,7 @@
 			;; conditions are satisfied, it tries to write
 			;; to a local file in default-directory, but
 			;; at this point, default-directory is remote.
-			;; (CALL-PROCESS-REGION can't write to remote
+			;; (`call-process-region' can't write to remote
 			;; files, it seems.)  The file in question is
 			;; a tmp file anyway.
 			(let ((default-directory
@@ -5305,7 +5307,9 @@
    vec (format "PATH=%s; export PATH"
 	       (mapconcat 'identity (tramp-get-remote-path vec) ":"))))
 
-;; -- communication with external shell --
+;; ------------------------------------------------------------
+;; -- Communication with external shell --
+;; ------------------------------------------------------------
 
 (defun tramp-find-file-exists-command (vec)
   "Find a command on the remote host for checking if a file exists.
@@ -5357,7 +5361,6 @@
        vec 'file-error "Couldn't find command to check if file exists"))
     result))
 
-
 ;; CCC test ksh or bash found for tilde expansion?
 (defun tramp-find-shell (vec)
   "Opens a shell on the remote host which groks tilde expansion."
@@ -5644,6 +5647,20 @@
 		     'tramp-password-end-of-line)
 		    tramp-default-password-end-of-line))))
 
+(defun tramp-process-sentinel (proc event)
+  "Process sentinel for Tramp processes."
+  (when (memq (process-status proc) '(stop exit signal))
+    (tramp-flush-connection-property proc)
+    ;; The "Connection closed" and "exit" messages disturb the output
+    ;; for asynchronous processes. That's why we have echoed the Tramp
+    ;; prompt at the end.  Trailing messages can be removed.
+    (with-current-buffer (process-buffer proc)
+      (goto-char (point-max))
+      (re-search-backward
+       (mapconcat 'identity (split-string tramp-end-of-output "\n") "\r?\n")
+       (line-beginning-position -8) t)
+      (delete-region (point) (point-max)))))
+
 (defun tramp-open-connection-setup-interactive-shell (proc vec)
   "Set up an interactive shell.
 Mainly sets the prompt and the echo correctly.  PROC is the shell
@@ -6176,7 +6193,7 @@
 	 vec 6 "%s" (mapconcat 'identity (process-command p) " "))
 
 	;; Check whether process is alive.
-	(set-process-sentinel p 'tramp-flush-connection-property)
+	(set-process-sentinel p 'tramp-process-sentinel)
 	(tramp-set-process-query-on-exit-flag p nil)
 	(tramp-message vec 3 "Waiting 60s for local shell to come up...")
 	(tramp-barf-if-no-shell-prompt
@@ -7367,7 +7384,9 @@
 ;; ** Try to avoid usage of `last-input-event' in `tramp-completion-mode-p'.
 ;; ** Unify `tramp-parse-{rhosts,shosts,sconfig,hosts,passwd,netrc}'.
 ;;    Code is nearly identical.
-;; * Allow out-of-band methods as _last_ multi-hop.
+;; * Allow out-of-band methods as _last_ multi-hop.  Open a connection
+;;   until the last but one hop via `start-file-process'.  Apply it
+;;   also for ftp and smb.
 ;; * WIBNI if we had a command "trampclient"?  If I was editing in
 ;;   some shell with root priviledges, it would be nice if I could
 ;;   just call