1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2025-01-13 16:38:14 +00:00

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.
This commit is contained in:
Reuben Thomas 2017-06-28 22:40:33 +01:00
parent 14ea76af5f
commit 85512e7521
3 changed files with 31 additions and 2 deletions

View File

@ -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

View File

@ -205,6 +205,11 @@ When 'shell-command-dont-erase-buffer' is nil, the default value,
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

View File

@ -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)))))))