changeset 46088:9d9568a15aa3

(shell-command-on-region): Handle errors and signals from shell command execution.
author Andreas Schwab <schwab@suse.de>
date Sat, 29 Jun 2002 18:08:22 +0000
parents 393e6d989d19
children 9e996888f3ec
files lisp/simple.el
diffstat 1 files changed, 18 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Sat Jun 29 17:40:36 2002 +0000
+++ b/lisp/simple.el	Sat Jun 29 18:08:22 2002 +0000
@@ -1466,8 +1466,7 @@
       ;; No prefix argument: put the output in a temp buffer,
       ;; replacing its entire contents.
       (let ((buffer (get-buffer-create
-		     (or output-buffer "*Shell Command Output*")))
-	    (success nil))
+		     (or output-buffer "*Shell Command Output*"))))
 	(unwind-protect
 	    (if (eq buffer (current-buffer))
 		;; If the input is the same buffer as the output,
@@ -1499,12 +1498,15 @@
 					     (list buffer error-file)
 					   buffer)
 					 nil shell-command-switch command)))
-	  (setq success (and exit-status (equal 0 exit-status)))
 	  ;; Report the output.
 	  (with-current-buffer buffer
 	    (setq mode-line-process 
-		  (if (not success)
-		    (concat (format " - Exit [%d]" exit-status)))))
+		  (cond ((null exit-status)
+			 " - Error")
+			((stringp exit-status)
+			 (format " - Signal [%s]" exit-status))
+			((not (equal 0 exit-status))
+			 (format " - Exit [%d]" exit-status)))))
 	  (if (with-current-buffer buffer (> (point-max) (point-min)))
 	      ;; There's some output, display it
 	      (display-message-or-buffer buffer)
@@ -1514,11 +1516,17 @@
 			    (< 0 (nth 7 (file-attributes error-file))))
 		       "some error output"
 		     "no output")))
-	      (if (equal 0 exit-status)
-		  (message "(Shell command succeeded with %s)"
-			   output)
-		(message "(Shell command failed with code %d and %s)"
-			 exit-status output)))
+	      (cond ((null exit-status)
+		     (message "(Shell command failed with error)"))
+		    ((equal 0 exit-status)
+		     (message "(Shell command succeeded with %s)"
+			      output))
+		    ((stringp exit-status)
+		     (message "(Shell command killed by signal %s)"
+			      exit-status))
+		    (t
+		     (message "(Shell command failed with code %d and %s)"
+			      exit-status output))))
 	    ;; Don't kill: there might be useful info in the undo-log.
 	    ;; (kill-buffer buffer)
 	    ))))