From: Reuben Thomas <rrt@sc3d.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 18133@debbugs.gnu.org, Juri Linkov <juri@linkov.net>
Subject: bug#18133: Suppressing asynchronous command output
Date: Wed, 28 Jun 2017 22:45:43 +0100 [thread overview]
Message-ID: <CAOnWdoh5bz6u2Eb0=pp1yhNeCK4RicAY97h_1BQrZaL_AD22mw@mail.gmail.com> (raw)
In-Reply-To: <83zijch4nc.fsf@gnu.org>
[-- Attachment #1.1: Type: text/plain, Size: 967 bytes --]
On 31 December 2016 at 08:41, Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Reuben Thomas <rrt@sc3d.org>
> > Date: Sat, 31 Dec 2016 00:19:21 +0000
> > Cc: Eli Zaretskii <eliz@gnu.org>, martin rudalics <rudalics@gmx.at>,
> 18133@debbugs.gnu.org
> >
> > Thanks, Juri; can you converge with Eli, and then I'll have a coherent
> proposal I can program?
>
> I'm okay with Juri's approach as well.
>
Here is a patch that attempts to implement Juri's approach.
However, at the moment it doesn't work. I think the problem is to do with
combining process filters. As suggested in the Emacs manual, I use
add-function to combine the new process filter with the default
comint-output-filter. But no matter what I try, the original filter does
not seem to be run any more, even if I pass a trivial function to
add-function. I've studied the documentation, and I can't see what I'm
doing wrong.
--
https://rrt.sc3d.org <http://rrt.sc3d.org>
[-- Attachment #1.2: Type: text/html, Size: 1731 bytes --]
[-- Attachment #2: 0001-Allow-async-command-output-buffer-to-be-shown-only-o.patch --]
[-- Type: text/x-patch, Size: 2749 bytes --]
From ee79ead9f2f132e85806c75f30ec861bb094f387 Mon Sep 17 00:00:00 2001
From: Reuben Thomas <rrt@sc3d.org>
Date: Wed, 28 Jun 2017 22:40:33 +0100
Subject: [PATCH] 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.
Thanks to Juri Linkov and Eli Zaretskii for advice and guidance.
---
lisp/simple.el | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/lisp/simple.el b/lisp/simple.el
index a5565ab..2f2887e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3271,6 +3271,17 @@ async-shell-command-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'."
@@ -3517,7 +3528,6 @@ shell-command
(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
@@ -3528,7 +3538,16 @@ shell-command
;; 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)))
+ (eq (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)))))))
--
2.7.4
next prev parent reply other threads:[~2017-06-28 21:45 UTC|newest]
Thread overview: 56+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-28 18:47 bug#18133: Suppressing asynchronous command output Reuben Thomas
2014-07-29 23:47 ` Juri Linkov
2014-07-30 9:16 ` Reuben Thomas
2014-07-30 9:48 ` Reuben Thomas
2014-07-30 16:35 ` Juri Linkov
2016-12-19 15:48 ` Reuben Thomas
2016-12-21 17:55 ` Eli Zaretskii
2016-12-21 22:44 ` Reuben Thomas
2016-12-22 16:28 ` Eli Zaretskii
2016-12-22 17:53 ` martin rudalics
2016-12-22 18:32 ` Eli Zaretskii
2016-12-22 19:42 ` Reuben Thomas
2016-12-22 20:15 ` martin rudalics
2016-12-22 20:26 ` Reuben Thomas
2016-12-23 18:59 ` martin rudalics
2016-12-23 19:10 ` Reuben Thomas
2016-12-23 19:55 ` martin rudalics
2016-12-23 21:07 ` Reuben Thomas
2016-12-24 9:16 ` martin rudalics
2016-12-24 11:11 ` Reuben Thomas
2016-12-24 12:06 ` Eli Zaretskii
2016-12-24 13:54 ` martin rudalics
2016-12-24 14:45 ` Reuben Thomas
2016-12-24 16:32 ` martin rudalics
2016-12-24 16:03 ` Eli Zaretskii
2016-12-24 16:33 ` martin rudalics
2016-12-24 16:56 ` Eli Zaretskii
2016-12-24 18:14 ` martin rudalics
2016-12-25 2:23 ` Reuben Thomas
2016-12-26 23:43 ` Reuben Thomas
2016-12-27 7:29 ` martin rudalics
2016-12-26 23:27 ` Juri Linkov
2016-12-27 1:09 ` Reuben Thomas
2016-12-27 1:20 ` Reuben Thomas
2016-12-27 6:23 ` Eli Zaretskii
2016-12-27 9:01 ` Reuben Thomas
2016-12-27 9:28 ` Eli Zaretskii
2016-12-27 22:21 ` Reuben Thomas
2016-12-28 16:01 ` Eli Zaretskii
2016-12-28 20:58 ` Reuben Thomas
2016-12-29 15:50 ` Eli Zaretskii
2016-12-29 23:08 ` Juri Linkov
2016-12-30 18:28 ` Reuben Thomas
2016-12-30 20:50 ` Eli Zaretskii
2016-12-30 22:33 ` Reuben Thomas
2016-12-30 22:56 ` Juri Linkov
2016-12-31 0:19 ` Reuben Thomas
2016-12-31 8:41 ` Eli Zaretskii
2017-06-28 21:45 ` Reuben Thomas [this message]
2017-06-28 21:53 ` Reuben Thomas
2017-06-28 22:05 ` Reuben Thomas
2017-08-07 12:31 ` Reuben Thomas
2017-08-07 16:25 ` Eli Zaretskii
2020-09-18 13:40 ` Lars Ingebrigtsen
2020-09-18 13:51 ` Reuben Thomas via Bug reports for GNU Emacs, the Swiss army knife of text editors
2020-09-18 14:04 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAOnWdoh5bz6u2Eb0=pp1yhNeCK4RicAY97h_1BQrZaL_AD22mw@mail.gmail.com' \
--to=rrt@sc3d.org \
--cc=18133@debbugs.gnu.org \
--cc=eliz@gnu.org \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.