From: Juri Linkov <juri@jurta.org>
To: dcl441-bugs@yahoo.com
Cc: 4719@debbugs.gnu.org
Subject: bug#4719: 23.1; M-& to run commands asynchronously (async-shell-command)
Date: Tue, 17 Jul 2012 21:57:12 +0300 [thread overview]
Message-ID: <871ukammuf.fsf@mail.jurta.org> (raw)
In-Reply-To: <719865.25574.qm@web53206.mail.re2.yahoo.com> (Daniel Clemente's message of "Thu, 15 Oct 2009 23:48:08 -0700 (PDT)")
> Ok, let's see what's missing to do.
> I saw following topics being discussed (summary here):
> http://article.gmane.org/gmane.emacs.devel/100293
>
> - command can be in background or not: we have this
> - the output might be visible or not
> - a new buffer might be spawned for each process or not
The problem with the design and implementation of this feature is that
there is too wide range of opinions and wishes.
So I propose a minimal change that just removes the current annoyance
where async-shell-command asks to kill the buffer instead of doing
something more constructive like creating a new buffer for running
another asynchronous command.
This is implemented in the patch below.
As for displaying the output buffer or not, I think this is the
responsibility of the window configuration system to decide whether
and where to display the output buffer.
=== modified file 'lisp/simple.el'
--- lisp/simple.el 2012-07-17 18:40:15 +0000
+++ lisp/simple.el 2012-07-17 18:55:25 +0000
@@ -2244,6 +2316,24 @@ (defun read-shell-command (prompt &optio
(or hist 'shell-command-history)
args)))
+(defcustom async-shell-command-buffer 'confirm-new-buffer
+ "What to do when the output buffer is used by another shell command.
+This option specifies how to resolve the conflict where a new command
+want to direct its output to the buffer `*Async Shell Command*',
+but this buffer is already taken by another running shell command."
+ :type '(choice (const :tag "Confirm killing of running command"
+ confirm-kill-process)
+ (const :tag "Confirm renaming of existing buffer"
+ confirm-rename-buffer)
+ (const :tag "Confirm creation of a new buffer"
+ confirm-new-buffer)
+ (const :tag "Rename the existing buffer"
+ rename-buffer)
+ (const :tag "Create a new buffer"
+ new-buffer))
+ :group 'shell
+ :version "24.2")
+
(defun async-shell-command (command &optional output-buffer error-buffer)
"Execute string COMMAND asynchronously in background.
@@ -2398,12 +2488,40 @@ (defun shell-command (command &optional
proc)
;; Remove the ampersand.
(setq command (substring command 0 (match-beginning 0)))
- ;; If will kill a process, query first.
+ ;; Ask the user what to do with already running process.
(setq proc (get-buffer-process buffer))
- (if proc
+ (when proc
+ (cond
+ ((eq async-shell-command-buffer 'confirm-kill-process)
+ ;; If will kill a process, query first.
(if (yes-or-no-p "A command is running. Kill it? ")
(kill-process proc)
(error "Shell command in progress")))
+ ((eq async-shell-command-buffer 'confirm-rename-buffer)
+ ;; If will create a new buffer, query first.
+ (if (yes-or-no-p "A command is running. Rename its output buffer before running a new command? ")
+ (progn
+ (with-current-buffer buffer
+ (rename-uniquely))
+ (setq buffer (get-buffer-create
+ (or output-buffer "*Async Shell Command*"))))
+ (error "Shell command in progress")))
+ ((eq async-shell-command-buffer 'confirm-new-buffer)
+ ;; If will create a new buffer, query first.
+ (if (yes-or-no-p "A command is running in the default buffer. Run in a new buffer? ")
+ (setq buffer (generate-new-buffer
+ (or output-buffer "*Async Shell Command*")))
+ (error "Shell command in progress")))
+ ((eq async-shell-command-buffer 'rename-buffer)
+ ;; It will create a new buffer.
+ (with-current-buffer buffer
+ (rename-uniquely))
+ (setq buffer (get-buffer-create
+ (or output-buffer "*Async Shell Command*"))))
+ ((eq async-shell-command-buffer 'new-buffer)
+ ;; It will create a new buffer.
+ (setq buffer (generate-new-buffer
+ (or output-buffer "*Async Shell Command*"))))))
(with-current-buffer buffer
(setq buffer-read-only nil)
;; Setting buffer-read-only to nil doesn't suffice
next prev parent reply other threads:[~2012-07-17 18:57 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-14 0:10 bug#4719: 23.1; M-& to run commands asynchronously (async-shell-command) Daniel Clemente
2009-10-14 3:01 ` Stefan Monnier
2009-10-14 7:50 ` Daniel Clemente
2009-10-14 20:41 ` Juri Linkov
2009-10-16 6:48 ` Daniel Clemente
2012-07-17 18:57 ` Juri Linkov [this message]
2012-07-28 15:19 ` Chong Yidong
2012-07-29 0:04 ` Juri Linkov
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=871ukammuf.fsf@mail.jurta.org \
--to=juri@jurta.org \
--cc=4719@debbugs.gnu.org \
--cc=dcl441-bugs@yahoo.com \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).