(defvar shell-command-history nil
"History list for some commands that read shell commands.")
-(defun shell-command (command &optional flag)
+(defun shell-command (command &optional output-buffer)
"Execute string COMMAND in inferior shell; display output, if any.
If COMMAND ends in ampersand, execute it asynchronously.
-
-Optional second arg non-nil (prefix arg, if interactive)
-means insert output in current buffer after point (leave mark after it).
-This cannot be done asynchronously."
+The output appears in the buffer `*Shell Command*'.
+
+The optional second argument OUTPUT-BUFFER, if non-nil,
+says to put the output in some other buffer.
+If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
+If OUTPUT-BUFFER is not a buffer and not nil,
+insert output in current buffer. (This cannot be done asynchronously.)
+In either case, the output is inserted after point (leaving mark after it)."
(interactive (list (read-from-minibuffer "Shell command: "
nil nil nil 'shell-command-history)
current-prefix-arg))
- (if flag
+ (if (and output-buffer
+ (not (or (bufferp output-buffer) (stringp output-buffer))))
(progn (barf-if-buffer-read-only)
(push-mark)
;; We do not use -f for csh; we will not support broken use of
(unwind-protect
(if (string-match "[ \t]*&[ \t]*$" command)
;; Command ending with ampersand means asynchronous.
- (let ((buffer (get-buffer-create "*Shell-Command*"))
+ (let ((buffer (get-buffer-create
+ (or output-buffer "*Shell-Command*")))
(directory default-directory)
proc)
;; Remove the ampersand.
(goto-char opoint))
(set-buffer obuf))))
-(defun shell-command-on-region (start end command &optional flag interactive)
+(defun shell-command-on-region (start end command
+ &optional output-buffer interactive)
"Execute string COMMAND in inferior shell with region as input.
Normally display output (if any) in temp buffer `*Shell Command Output*';
Prefix arg means replace the region with it.
but it is nonetheless available in buffer `*Shell Command Output*'
even though that buffer is not automatically displayed. If there is no output
or output is inserted in the current buffer then `*Shell Command Output*' is
-deleted."
+deleted.
+
+The optional second argument OUTPUT-BUFFER, if non-nil,
+says to put the output in some other buffer.
+If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
+If OUTPUT-BUFFER is not a buffer and not nil,
+insert output in the current buffer.
+In either case, the output is inserted after point (leaving mark after it)."
(interactive (list (region-beginning) (region-end)
(read-from-minibuffer "Shell command on region: "
nil nil nil 'shell-command-history)
current-prefix-arg
(prefix-numeric-value current-prefix-arg)))
- (if flag
+ (if (and output-buffer
+ (not (or (bufferp output-buffer) (stringp output-buffer))))
;; Replace specified region with output from command.
(let ((swap (and interactive (< (point) (mark)))))
;; Don't muck with mark
(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*"))
+ (let ((buffer (get-buffer-create
+ (or output-buffer "*Shell Command Output*")))
(success nil))
(unwind-protect
(if (eq buffer (current-buffer))