aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-10-15 10:16:09 +0000
committerRichard M. Stallman1994-10-15 10:16:09 +0000
commitd0d74413b708a53a2ec0db35ffb5e47b818b88d1 (patch)
treed3cfc68931bc0069fcddb5aca7bc3dc719d3e4d2
parentc30b759d47de447ec79d721aeb5c766919f15e10 (diff)
downloademacs-d0d74413b708a53a2ec0db35ffb5e47b818b88d1.tar.gz
emacs-d0d74413b708a53a2ec0db35ffb5e47b818b88d1.zip
(shell-command, shell-command-on-region):
Rename arg FLAG to OUTPUT-BUFFER and allow it to be a buffer.
-rw-r--r--lisp/simple.el38
1 files changed, 27 insertions, 11 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 8ca4eb99e91..b4edb5c7ed3 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -658,17 +658,22 @@ then call `undo-more' one or more times to undo them."
658(defvar shell-command-history nil 658(defvar shell-command-history nil
659 "History list for some commands that read shell commands.") 659 "History list for some commands that read shell commands.")
660 660
661(defun shell-command (command &optional flag) 661(defun shell-command (command &optional output-buffer)
662 "Execute string COMMAND in inferior shell; display output, if any. 662 "Execute string COMMAND in inferior shell; display output, if any.
663If COMMAND ends in ampersand, execute it asynchronously. 663If COMMAND ends in ampersand, execute it asynchronously.
664 664The output appears in the buffer `*Shell Command*'.
665Optional second arg non-nil (prefix arg, if interactive) 665
666means insert output in current buffer after point (leave mark after it). 666The optional second argument OUTPUT-BUFFER, if non-nil,
667This cannot be done asynchronously." 667says to put the output in some other buffer.
668If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
669If OUTPUT-BUFFER is not a buffer and not nil,
670insert output in current buffer. (This cannot be done asynchronously.)
671In either case, the output is inserted after point (leaving mark after it)."
668 (interactive (list (read-from-minibuffer "Shell command: " 672 (interactive (list (read-from-minibuffer "Shell command: "
669 nil nil nil 'shell-command-history) 673 nil nil nil 'shell-command-history)
670 current-prefix-arg)) 674 current-prefix-arg))
671 (if flag 675 (if (and output-buffer
676 (not (or (bufferp output-buffer) (stringp output-buffer))))
672 (progn (barf-if-buffer-read-only) 677 (progn (barf-if-buffer-read-only)
673 (push-mark) 678 (push-mark)
674 ;; We do not use -f for csh; we will not support broken use of 679 ;; We do not use -f for csh; we will not support broken use of
@@ -689,7 +694,8 @@ This cannot be done asynchronously."
689 (unwind-protect 694 (unwind-protect
690 (if (string-match "[ \t]*&[ \t]*$" command) 695 (if (string-match "[ \t]*&[ \t]*$" command)
691 ;; Command ending with ampersand means asynchronous. 696 ;; Command ending with ampersand means asynchronous.
692 (let ((buffer (get-buffer-create "*Shell-Command*")) 697 (let ((buffer (get-buffer-create
698 (or output-buffer "*Shell-Command*")))
693 (directory default-directory) 699 (directory default-directory)
694 proc) 700 proc)
695 ;; Remove the ampersand. 701 ;; Remove the ampersand.
@@ -751,7 +757,8 @@ This cannot be done asynchronously."
751 (goto-char opoint)) 757 (goto-char opoint))
752 (set-buffer obuf)))) 758 (set-buffer obuf))))
753 759
754(defun shell-command-on-region (start end command &optional flag interactive) 760(defun shell-command-on-region (start end command
761 &optional output-buffer interactive)
755 "Execute string COMMAND in inferior shell with region as input. 762 "Execute string COMMAND in inferior shell with region as input.
756Normally display output (if any) in temp buffer `*Shell Command Output*'; 763Normally display output (if any) in temp buffer `*Shell Command Output*';
757Prefix arg means replace the region with it. 764Prefix arg means replace the region with it.
@@ -763,13 +770,21 @@ If the output is one line, it is displayed in the echo area,
763but it is nonetheless available in buffer `*Shell Command Output*' 770but it is nonetheless available in buffer `*Shell Command Output*'
764even though that buffer is not automatically displayed. If there is no output 771even though that buffer is not automatically displayed. If there is no output
765or output is inserted in the current buffer then `*Shell Command Output*' is 772or output is inserted in the current buffer then `*Shell Command Output*' is
766deleted." 773deleted.
774
775The optional second argument OUTPUT-BUFFER, if non-nil,
776says to put the output in some other buffer.
777If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
778If OUTPUT-BUFFER is not a buffer and not nil,
779insert output in the current buffer.
780In either case, the output is inserted after point (leaving mark after it)."
767 (interactive (list (region-beginning) (region-end) 781 (interactive (list (region-beginning) (region-end)
768 (read-from-minibuffer "Shell command on region: " 782 (read-from-minibuffer "Shell command on region: "
769 nil nil nil 'shell-command-history) 783 nil nil nil 'shell-command-history)
770 current-prefix-arg 784 current-prefix-arg
771 (prefix-numeric-value current-prefix-arg))) 785 (prefix-numeric-value current-prefix-arg)))
772 (if flag 786 (if (and output-buffer
787 (not (or (bufferp output-buffer) (stringp output-buffer))))
773 ;; Replace specified region with output from command. 788 ;; Replace specified region with output from command.
774 (let ((swap (and interactive (< (point) (mark))))) 789 (let ((swap (and interactive (< (point) (mark)))))
775 ;; Don't muck with mark 790 ;; Don't muck with mark
@@ -783,7 +798,8 @@ deleted."
783 (and interactive swap (exchange-point-and-mark))) 798 (and interactive swap (exchange-point-and-mark)))
784 ;; No prefix argument: put the output in a temp buffer, 799 ;; No prefix argument: put the output in a temp buffer,
785 ;; replacing its entire contents. 800 ;; replacing its entire contents.
786 (let ((buffer (get-buffer-create "*Shell Command Output*")) 801 (let ((buffer (get-buffer-create
802 (or output-buffer "*Shell Command Output*")))
787 (success nil)) 803 (success nil))
788 (unwind-protect 804 (unwind-protect
789 (if (eq buffer (current-buffer)) 805 (if (eq buffer (current-buffer))