changeset 88072:948a005afe18

* net/tramp.el (tramp-methods): Use "-H" option for "sudo". Suggested by Trent W. Buck <trentbuck@gmail.com>. Make ("%h") a single element in "plinkx". (tramp-handle-shell-command): Reuse "*Async Shell Command*" or "*Shell Command Output*" buffers. Check, whether there is already an asynchronous process running. Display always the buffer of the asynchronous process. (tramp-compute-multi-hops): Adapt error message.
author Michael Albinus <michael.albinus@gmx.de>
date Tue, 29 Jan 2008 21:14:04 +0000
parents 1fcb6b1de8dc
children c720c7381645
files lisp/net/tramp.el
diffstat 1 files changed, 43 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/net/tramp.el	Tue Jan 29 21:13:00 2008 +0000
+++ b/lisp/net/tramp.el	Tue Jan 29 21:14:04 2008 +0000
@@ -441,7 +441,7 @@
 	     (tramp-password-end-of-line nil))
     ("sudo"  (tramp-login-program        "sudo")
              (tramp-login-args           (("-u" "%u")
-					  ("-s" "-p" "Password:")))
+					  ("-s") ("-H") ("-p" "Password:")))
 	     (tramp-remote-sh            "/bin/sh")
 	     (tramp-copy-program         nil)
 	     (tramp-copy-args            nil)
@@ -519,7 +519,9 @@
 	     (tramp-default-port         22))
     ("plinkx"
              (tramp-login-program        "plink")
-	     (tramp-login-args           (("-load" "%h") ("-t")
+	     ;; ("%h") must be a single element, see
+	     ;; `tramp-compute-multi-hops'.
+	     (tramp-login-args           (("-load") ("%h") ("-t")
 					  (,(format
 					     "env 'TERM=%s' 'PROMPT_COMMAND=' 'PS1=$ '"
 					     tramp-terminal-type))
@@ -3789,7 +3791,7 @@
 	   ((bufferp output-buffer) output-buffer)
 	   ((stringp output-buffer) (get-buffer-create output-buffer))
 	   (output-buffer (current-buffer))
-	   (t (generate-new-buffer
+	   (t (get-buffer-create
 	       (if asynchronous
 		   "*Async Shell Command*"
 		 "*Shell Command Output*")))))
@@ -3801,22 +3803,42 @@
 	  (if (and (not asynchronous) error-buffer)
 	      (with-parsed-tramp-file-name default-directory nil
 		(list output-buffer (tramp-make-tramp-temp-file v)))
-	    output-buffer)))
-
-    (prog1
-	;; Run the process.
-	(if (integerp asynchronous)
+	    output-buffer))
+	 (proc (get-buffer-process output-buffer)))
+
+    ;; Check whether there is another process running.  Tramp does not
+    ;; support 2 (asynchronous) processes in parallel.
+    (when proc
+      (if (yes-or-no-p "A command is running.  Kill it? ")
+	  (ignore-errors (kill-process proc))
+	(error "Shell command in progress")))
+
+    (with-current-buffer output-buffer
+      (setq buffer-read-only nil
+	    buffer-undo-list t)
+      (erase-buffer))
+
+    (if (integerp asynchronous)
+	(prog1
+	    ;; Run the process.
 	    (apply 'start-file-process "*Async Shell*" buffer args)
-	  (apply 'process-file (car args) nil buffer nil (cdr args)))
-      ;; Insert error messages if they were separated.
-      (when (listp buffer)
-	(with-current-buffer error-buffer (insert-file-contents (cadr buffer)))
-	(delete-file (cadr buffer)))
-      ;; There's some output, display it.
-      (when (with-current-buffer output-buffer (> (point-max) (point-min)))
-	(if (functionp 'display-message-or-buffer)
-	    (funcall (symbol-function 'display-message-or-buffer) output-buffer)
-	  (pop-to-buffer output-buffer))))))
+	  ;; Display output.
+	  (pop-to-buffer output-buffer))
+
+      (prog1
+	  ;; Run the process.
+	  (apply 'process-file (car args) nil buffer nil (cdr args))
+	;; Insert error messages if they were separated.
+	(when (listp buffer)
+	  (with-current-buffer error-buffer
+	    (insert-file-contents (cadr buffer)))
+	  (delete-file (cadr buffer)))
+	;; There's some output, display it.
+	(when (with-current-buffer output-buffer (> (point-max) (point-min)))
+	  (if (functionp 'display-message-or-buffer)
+	      (funcall (symbol-function 'display-message-or-buffer)
+		       output-buffer)
+	    (pop-to-buffer output-buffer)))))))
 
 ;; File Editing.
 
@@ -6073,7 +6095,9 @@
 	    (concat "^" (regexp-opt (list "localhost" (system-name)) t) "$")
 	    host))
 	(tramp-error
-	 v 'file-error "Wrong hostname `%s' for method `%s'" host method)))
+	 v 'file-error
+	 "Host `%s' looks like a remote host, `%s' can only use the local host"
+	 host method)))
 
     ;; Result.
     target-alist))