Subject: bug#18133: Suppressing asynchronous command output

From: Juri Linkov <[email-masked]>
Date: Tue, 27 Dec 2016 01:27:11 +0200

> Here is the implementation I currently use (from Juri Linkov, message #8,
> second block of code):
>
> (advice-add 'comint-output-filter :after
>             "Stop Async Shell Command output from appearing until there is
> output."
>             (lambda (process string)
>               (when (and (string-match-p "\\*Async Shell Command\\*"
>                                          (buffer-name (process-buffer
> process))))
>                 (display-buffer (process-buffer process)))))

This code is mostly intended for the users to put in their ~/.emacs.
For core implementation, we need a new customizable variable that you
could check in the filter, and display the buffer when necessary.  This is
like other options we already have, e.g. ‘comint-move-point-for-output’,
‘comint-scroll-show-maximum-output’ used from ‘comint-output-filter-functions’.

A good name would be ‘async-shell-command-display-buffer’ with a list of
options when to display the buffer: the first choice to implement now
would be just “on the first output received”, but later we could add
more options like “on every output received”, etc.

Then you could use the code Martin posted here with using such option
in the call to ‘display-buffer’, i.e. the first use of this option
in ‘display-buffer’ is not to display the buffer, and the second use
in the filter-function is to display it on first output.  Please note
that also you have to take care about not displaying the same buffer
many times in filter-function because it is called repeatedly on
small chunks of output, depending on the size of output.

PS: I'm not sure about using async-specific variables like
‘async-shell-command-display-buffer’ in comint-filters,
so maybe better would be add async-specific comint-filters
dynamically in ‘async-shell-command’?