# HG changeset patch # User Richard M. Stallman # Date 758993132 0 # Node ID 82a127d7ef7d2b1bae23d7e8559566c932c5b2ea # Parent e77e9d7386bec11900ea36d4bc7f006e2cabe9e0 (shell-command-on-region): If we quit the command, display the output buffer anyway. diff -r e77e9d7386be -r 82a127d7ef7d lisp/simple.el --- a/lisp/simple.el Wed Jan 19 15:12:34 1994 +0000 +++ b/lisp/simple.el Wed Jan 19 15:25:32 1994 +0000 @@ -757,41 +757,47 @@ (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.