From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#4719: 23.1; M-& to run commands asynchronously (async-shell-command) Date: Tue, 17 Jul 2012 21:57:12 +0300 Organization: JURTA Message-ID: <871ukammuf.fsf@mail.jurta.org> References: <719865.25574.qm@web53206.mail.re2.yahoo.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1342551798 12913 80.91.229.3 (17 Jul 2012 19:03:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 17 Jul 2012 19:03:18 +0000 (UTC) Cc: 4719@debbugs.gnu.org To: dcl441-bugs@yahoo.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 17 21:03:14 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SrD35-0000nb-ET for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 21:03:07 +0200 Original-Received: from localhost ([::1]:42493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrD34-0007h2-Nz for geb-bug-gnu-emacs@m.gmane.org; Tue, 17 Jul 2012 15:03:06 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:59748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrD30-0007gw-Md for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 15:03:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrD2z-0006D6-4v for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 15:03:02 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37100) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrD2z-0006Cv-0r for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 15:03:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SrD8o-00041Y-8z for bug-gnu-emacs@gnu.org; Tue, 17 Jul 2012 15:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 17 Jul 2012 19:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 4719 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 4719-submit@debbugs.gnu.org id=B4719.134255209915415 (code B ref 4719); Tue, 17 Jul 2012 19:09:02 +0000 Original-Received: (at 4719) by debbugs.gnu.org; 17 Jul 2012 19:08:19 +0000 Original-Received: from localhost ([127.0.0.1]:46646 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrD87-00040Z-1W for submit@debbugs.gnu.org; Tue, 17 Jul 2012 15:08:19 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:48676 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SrD84-00040S-1Z for 4719@debbugs.gnu.org; Tue, 17 Jul 2012 15:08:16 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id CCF33451C974; Tue, 17 Jul 2012 12:02:12 -0700 (PDT) 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)") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:62064 Archived-At: > 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