diff options
-rw-r--r-- | doc/emacs/misc.texi | 5 | ||||
-rw-r--r-- | etc/NEWS | 5 | ||||
-rw-r--r-- | lisp/simple.el | 23 |
3 files changed, 31 insertions, 2 deletions
diff --git a/doc/emacs/misc.texi b/doc/emacs/misc.texi index 84681f2269a..73a6bae767a 100644 --- a/doc/emacs/misc.texi +++ b/doc/emacs/misc.texi @@ -742,6 +742,11 @@ this; e.g., whether to rename the pre-existing output buffer, or to use a different buffer for the new command. Consult the variable's documentation for more possibilities. +@vindex async-shell-command-display-buffer + If you want the output buffer for asynchronous shell commands to be +displayed only when the command generates output, set +@code{async-shell-command-display-buffer} to @code{nil}. + @kindex M-| @findex shell-command-on-region @kbd{M-|} (@code{shell-command-on-region}) is like @kbd{M-!}, but @@ -206,6 +206,11 @@ the behavior of 'shell-command', 'shell-command-on-region' and 'async-shell-command' is as usual. +++ +** The new user option 'async-shell-command-display-buffer' controls +whether the output buffer of an asynchronous command is shown +immediately, or only when there is output. + ++++ ** The new user option 'mouse-select-region-move-to-beginning' controls the position of point when double-clicking mouse-1 on the end of a parenthetical grouping or string-delimiter: the default value nil 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))))))) |