aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReuben Thomas2017-06-28 22:40:33 +0100
committerReuben Thomas2017-08-07 21:57:22 +0100
commit85512e752191091d38cd5e34e7bed80eac1e9013 (patch)
treec021cd02e533631e4bc7bad90472997e4622e76b
parent14ea76af5f3596d48747c2437006f6e1abcb67a7 (diff)
downloademacs-85512e752191091d38cd5e34e7bed80eac1e9013.tar.gz
emacs-85512e752191091d38cd5e34e7bed80eac1e9013.zip
Allow async command output buffer to be shown only on output
* lisp/simple.el (async-shell-command-display-buffer): Add defcustom. (shell-command): Use the new defcustom to determine whether to show the buffer immediately, or add a process filter that shows it only when there is some output. * etc/NEWS: Document the new variable. * doc/emacs/misc.texi: Likewise. Thanks to Juri Linkov and Eli Zaretskii for advice and guidance.
-rw-r--r--doc/emacs/misc.texi5
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/simple.el23
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
742use a different buffer for the new command. Consult the variable's 742use a different buffer for the new command. Consult the variable's
743documentation for more possibilities. 743documentation for more possibilities.
744 744
745@vindex async-shell-command-display-buffer
746 If you want the output buffer for asynchronous shell commands to be
747displayed only when the command generates output, set
748@code{async-shell-command-display-buffer} to @code{nil}.
749
745@kindex M-| 750@kindex M-|
746@findex shell-command-on-region 751@findex shell-command-on-region
747 @kbd{M-|} (@code{shell-command-on-region}) is like @kbd{M-!}, but 752 @kbd{M-|} (@code{shell-command-on-region}) is like @kbd{M-!}, but
diff --git a/etc/NEWS b/etc/NEWS
index b47bf959bed..58b08348b10 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -206,6 +206,11 @@ the behavior of 'shell-command', 'shell-command-on-region' and
206'async-shell-command' is as usual. 206'async-shell-command' is as usual.
207 207
208+++ 208+++
209** The new user option 'async-shell-command-display-buffer' controls
210whether the output buffer of an asynchronous command is shown
211immediately, or only when there is output.
212
213+++
209** The new user option 'mouse-select-region-move-to-beginning' 214** The new user option 'mouse-select-region-move-to-beginning'
210controls the position of point when double-clicking mouse-1 on the end 215controls the position of point when double-clicking mouse-1 on the end
211of a parenthetical grouping or string-delimiter: the default value nil 216of 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,
3279 :group 'shell 3279 :group 'shell
3280 :version "24.3") 3280 :version "24.3")
3281 3281
3282(defcustom async-shell-command-display-buffer t
3283 "Whether to display the command buffer immediately.
3284If t, display the buffer immediately; if nil, wait until there
3285is output."
3286 :type '(choice (const :tag "Display buffer immediately"
3287 t)
3288 (const :tag "Display buffer on output"
3289 nil))
3290 :group 'shell
3291 :version "26.1")
3292
3282(defun shell-command--save-pos-or-erase () 3293(defun shell-command--save-pos-or-erase ()
3283 "Store a buffer position or erase the buffer. 3294 "Store a buffer position or erase the buffer.
3284See `shell-command-dont-erase-buffer'." 3295See `shell-command-dont-erase-buffer'."
@@ -3525,7 +3536,6 @@ the use of a shell (with its need to quote arguments)."
3525 (setq buffer (get-buffer-create 3536 (setq buffer (get-buffer-create
3526 (or output-buffer "*Async Shell Command*")))))) 3537 (or output-buffer "*Async Shell Command*"))))))
3527 (with-current-buffer buffer 3538 (with-current-buffer buffer
3528 (display-buffer buffer '(nil (allow-no-window . t)))
3529 (shell-command--save-pos-or-erase) 3539 (shell-command--save-pos-or-erase)
3530 (setq default-directory directory) 3540 (setq default-directory directory)
3531 (setq proc (start-process "Shell" buffer shell-file-name 3541 (setq proc (start-process "Shell" buffer shell-file-name
@@ -3536,7 +3546,16 @@ the use of a shell (with its need to quote arguments)."
3536 ;; Use the comint filter for proper handling of carriage motion 3546 ;; Use the comint filter for proper handling of carriage motion
3537 ;; (see `comint-inhibit-carriage-motion'),. 3547 ;; (see `comint-inhibit-carriage-motion'),.
3538 (set-process-filter proc 'comint-output-filter) 3548 (set-process-filter proc 'comint-output-filter)
3539 )) 3549 (if async-shell-command-display-buffer
3550 (display-buffer buffer '(nil (allow-no-window . t)))
3551 (add-function :before (process-filter proc)
3552 `(lambda (process string)
3553 (when (and (= 0 (buffer-size (process-buffer process)))
3554 (string= (buffer-name (process-buffer process))
3555 ,(or output-buffer "*Async Shell Command*")))
3556 (display-buffer (process-buffer process))))
3557 ))
3558 ))
3540 ;; Otherwise, command is executed synchronously. 3559 ;; Otherwise, command is executed synchronously.
3541 (shell-command-on-region (point) (point) command 3560 (shell-command-on-region (point) (point) command
3542 output-buffer nil error-buffer))))))) 3561 output-buffer nil error-buffer)))))))