summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-01-19 15:25:32 +0000
committerRichard M. Stallman <rms@gnu.org>1994-01-19 15:25:32 +0000
commitf9c68a7c1e549c7827ecf33d6edf481bc0f70edb (patch)
tree57c84852942ad752ef18c17e7d1d7edba341fe55
parentbc943dc20323e575e854d952e99d4418fc5c1cf5 (diff)
downloademacs-f9c68a7c1e549c7827ecf33d6edf481bc0f70edb.tar.gz
(shell-command-on-region): If we quit the command,
display the output buffer anyway.
-rw-r--r--lisp/simple.el76
1 files changed, 41 insertions, 35 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 46fed18c818..461ee1e92e0 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -757,41 +757,47 @@ deleted."
(and interactive swap (exchange-point-and-mark)))
;; No prefix argument: put the output in a temp buffer,
;; replacing its entire contents.
- (let ((buffer (get-buffer-create "*Shell Command Output*")))
- (if (eq buffer (current-buffer))
- ;; If the input is the same buffer as the output,
- ;; delete everything but the specified region,
- ;; then replace that region with the output.
- (progn (delete-region end (point-max))
- (delete-region (point-min) start)
- (call-process-region (point-min) (point-max)
- shell-file-name t t nil
- "-c" command))
- ;; Clear the output buffer, then run the command with output there.
- (save-excursion
- (set-buffer buffer)
- (erase-buffer))
- (call-process-region start end shell-file-name
- nil buffer nil
- "-c" command))
- ;; Report the amount of output.
- (let ((lines (save-excursion
- (set-buffer buffer)
- (if (= (buffer-size) 0)
- 0
- (count-lines (point-min) (point-max))))))
- (cond ((= lines 0)
- (message "(Shell command completed with no output)")
- (kill-buffer "*Shell Command Output*"))
- ((= lines 1)
- (message "%s"
- (save-excursion
- (set-buffer buffer)
- (goto-char (point-min))
- (buffer-substring (point)
- (progn (end-of-line) (point))))))
- (t
- (set-window-start (display-buffer buffer) 1)))))))
+ (let ((buffer (get-buffer-create "*Shell Command Output*"))
+ (success nil))
+ (unwind-protect
+ (if (eq buffer (current-buffer))
+ ;; If the input is the same buffer as the output,
+ ;; delete everything but the specified region,
+ ;; then replace that region with the output.
+ (progn (delete-region end (point-max))
+ (delete-region (point-min) start)
+ (call-process-region (point-min) (point-max)
+ shell-file-name t t nil
+ "-c" command)
+ (setq success t))
+ ;; Clear the output buffer, then run the command with output there.
+ (save-excursion
+ (set-buffer buffer)
+ (erase-buffer))
+ (call-process-region start end shell-file-name
+ nil buffer nil
+ "-c" command)
+ (setq success t))
+ ;; Report the amount of output.
+ (let ((lines (save-excursion
+ (set-buffer buffer)
+ (if (= (buffer-size) 0)
+ 0
+ (count-lines (point-min) (point-max))))))
+ (cond ((= lines 0)
+ (if success
+ (message "(Shell command completed with no output)"))
+ (kill-buffer buffer))
+ ((and success (= lines 1))
+ (message "%s"
+ (save-excursion
+ (set-buffer buffer)
+ (goto-char (point-min))
+ (buffer-substring (point)
+ (progn (end-of-line) (point)))))
+ (kill-buffer buffer))
+ (t
+ (set-window-start (display-buffer buffer) 1))))))))
(defun universal-argument ()
"Begin a numeric argument for the following command.