summaryrefslogtreecommitdiff
path: root/lisp/simple.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el23
1 files changed, 21 insertions, 2 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 027ce3959a9..9838f1644f8 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3279,6 +3279,17 @@ output buffer and running a new command in the default buffer,
:group 'shell
:version "24.3")
+(defcustom async-shell-command-display-buffer t
+ "Whether to display the command buffer immediately.
+If t, display the buffer immediately; if nil, wait until there
+is output."
+ :type '(choice (const :tag "Display buffer immediately"
+ t)
+ (const :tag "Display buffer on output"
+ nil))
+ :group 'shell
+ :version "26.1")
+
(defun shell-command--save-pos-or-erase ()
"Store a buffer position or erase the buffer.
See `shell-command-dont-erase-buffer'."
@@ -3525,7 +3536,6 @@ the use of a shell (with its need to quote arguments)."
(setq buffer (get-buffer-create
(or output-buffer "*Async Shell Command*"))))))
(with-current-buffer buffer
- (display-buffer buffer '(nil (allow-no-window . t)))
(shell-command--save-pos-or-erase)
(setq default-directory directory)
(setq proc (start-process "Shell" buffer shell-file-name
@@ -3536,7 +3546,16 @@ the use of a shell (with its need to quote arguments)."
;; Use the comint filter for proper handling of carriage motion
;; (see `comint-inhibit-carriage-motion'),.
(set-process-filter proc 'comint-output-filter)
- ))
+ (if async-shell-command-display-buffer
+ (display-buffer buffer '(nil (allow-no-window . t)))
+ (add-function :before (process-filter proc)
+ `(lambda (process string)
+ (when (and (= 0 (buffer-size (process-buffer process)))
+ (string= (buffer-name (process-buffer process))
+ ,(or output-buffer "*Async Shell Command*")))
+ (display-buffer (process-buffer process))))
+ ))
+ ))
;; Otherwise, command is executed synchronously.
(shell-command-on-region (point) (point) command
output-buffer nil error-buffer)))))))