bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#18133: Suppressing asynchronous command output


From: Reuben Thomas
Subject: bug#18133: Suppressing asynchronous command output
Date: Wed, 30 Jul 2014 10:16:25 +0100

On 30 July 2014 00:47, Juri Linkov <address@hidden> wrote:
> When using an asychronous command, e.g. & from dired-mode, it would be nice
> if it didn't pop up the buffer until output was received. Often, no output
> is received, for example, when using an asynchronous command to start an
> external viewer (here, it makes sense to start it asynchronously, as the
> user doesn't want Emacs to block until the viewer exits).
>
> This thread:
> https://groups.google.com/forum/#!topic/gnu.emacs.help/xrs6ny67c_4
> discusses the issue, and gives some workarounds and partial solutions; but
> would there be any disadvantage to changing the behavior to pop up the
> buffer when input arrives, and otherwise not do so?

It's possible to display *Async Shell Command* only
when the command finishes with empty input using:

  (add-to-list 'display-buffer-alist '("\\*Async Shell Command\\*"
                                       display-buffer-no-window (nil)))

  (advice-add 'shell-command-sentinel :after
              (lambda (process signal)
                (when (and (string-match-p "\\*Async Shell Command\\*"
                                           (buffer-name (process-buffer process)))
                           (memq (process-status process) '(exit signal))
                           (not (zerop (buffer-size (process-buffer process)))))
                  (display-buffer (process-buffer process)))))

or when the first output is received:

  (add-to-list 'display-buffer-alist '("\\*Async Shell Command\\*"
                                       display-buffer-no-window (nil)))

  (advice-add 'comint-output-filter :after
              (lambda (process string)
                (when (and (string-match-p "\\*Async Shell Command\\*"
                                           (buffer-name (process-buffer process))))
                  (display-buffer (process-buffer process)))))

Thanks very much. The second form seems like the "right" one: when running a command asynchronously, output should be immediately visible.

Is this suitable also to be used as the basis of a patch to Emacs?

--
http://rrt.sc3d.org

reply via email to

[Prev in Thread] Current Thread [Next in Thread]