all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
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 23:05:08 +0100	[thread overview]
Message-ID: <CAOnWdojqm8fAWcLNh7D57NxQU080kApe6eSit4BwDMVs2hjjSQ@mail.gmail.com> (raw)
In-Reply-To: <CAOnWdojEzy5aU9m45RVtUN8GbjwfXrkLMLxDpL9GJOiB1fE7_A@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 206 bytes --]

​Here's an update to the previous patch; the problem seemed to be the use
of eq for comparing strings rather than string=.​

It seems to work now.

-- 
https://rrt.sc3d.org <http://rrt.sc3d.org>

[-- Attachment #1.2: Type: text/html, Size: 515 bytes --]

[-- Attachment #2: 0001-Allow-async-command-output-buffer-to-be-shown-only-o.patch --]
[-- Type: text/x-patch, Size: 2754 bytes --]

From a82dcca70d3aa527dee3c03bee3bdfcda03a1bb9 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..62422f1 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)))
+                                                (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)))))))
-- 
2.7.4


  reply	other threads:[~2017-06-28 22:05 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
2017-06-28 21:53                                                       ` Reuben Thomas
2017-06-28 22:05                                                         ` Reuben Thomas [this message]
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=CAOnWdojqm8fAWcLNh7D57NxQU080kApe6eSit4BwDMVs2hjjSQ@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.