From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: & and M-& to run programs asynchronously Date: Tue, 29 Jul 2008 19:51:08 +0300 Organization: JURTA Message-ID: <874p68iqgz.fsf@jurta.org> References: <87hcbkpo0e.fsf@gmail.com> <86y74wzeq1.fsf@lola.quinscape.zz> <874p7ifonh.fsf@jurta.org> <873amryzdu.fsf_-_@gmail.com> <87sku9hdkr.fsf@gmail.com> <87mykh1hpi.fsf@jurta.org> <87prpba6qj.fsf@gmail.com> <87abgfun32.fsf@jurta.org> <7dbe73ed0807221250v510e83b7u75dd271846704abb@mail.gmail.com> <87tzehd0ll.fsf@jurta.org> <87hca868s8.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1217351057 29668 80.91.229.12 (29 Jul 2008 17:04:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 29 Jul 2008 17:04:17 +0000 (UTC) Cc: emacs-devel@gnu.org To: Daniel Clemente Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jul 29 19:05:07 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1KNsd8-00022D-8Y for ged-emacs-devel@m.gmane.org; Tue, 29 Jul 2008 19:04:58 +0200 Original-Received: from localhost ([127.0.0.1]:37183 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNscD-0007ho-UW for ged-emacs-devel@m.gmane.org; Tue, 29 Jul 2008 13:04:01 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KNsSl-0003iQ-Ln for emacs-devel@gnu.org; Tue, 29 Jul 2008 12:54:15 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KNsSk-0003hv-U5 for emacs-devel@gnu.org; Tue, 29 Jul 2008 12:54:15 -0400 Original-Received: from [199.232.76.173] (port=47700 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KNsSk-0003hi-N7 for emacs-devel@gnu.org; Tue, 29 Jul 2008 12:54:14 -0400 Original-Received: from smtp-out.neti.ee ([194.126.126.37]:38713) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KNsSk-0000ZF-1C for emacs-devel@gnu.org; Tue, 29 Jul 2008 12:54:14 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by MXR-13.estpak.ee (Postfix) with ESMTP id 1367B26E8C; Tue, 29 Jul 2008 19:54:12 +0300 (EEST) X-Virus-Scanned: amavisd-new at !change-mydomain-variable!.example.com Original-Received: from smtp-out.neti.ee ([127.0.0.1]) by localhost (MXR-1.estpak.ee [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6igpTT3eOvF9; Tue, 29 Jul 2008 19:54:09 +0300 (EEST) Original-Received: from Relayhost1.neti.ee (Relayhost1 [88.196.174.141]) by MXR-13.estpak.ee (Postfix) with ESMTP id 6CFAE275C9; Tue, 29 Jul 2008 19:54:09 +0300 (EEST) Original-Received: from mail.estpak.ee (66.132.191.90.dyn.estpak.ee [90.191.132.66]) by Relayhost1.neti.ee (Postfix) with ESMTP id BB74B2A4A64; Tue, 29 Jul 2008 19:54:09 +0300 (EEST) In-Reply-To: <87hca868s8.fsf@gmail.com> (Daniel Clemente's message of "Tue, 29 Jul 2008 16:53:59 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:101699 Archived-At: > Thanks for the patch to bind & to dired-do-async-shell-command in dired. It is installed now. > I suppose the next step is to do the same for async-shell-command and bind it to M-& > That's in simple.el. A function can read the user's input, add "&", > and pass the command to shell-command. This can be done with the following patch that adds a new command `async-shell-command'. I also noticed that code that sets `minibuffer-default-add-shell-commands' could be moved from the interactive spec of `shell-command' to `read-shell-command' so this feature will be available for all functions that read a shell command from the minibuffer (including a new command `async-shell-command'). Index: lisp/bindings.el =================================================================== RCS file: /sources/emacs/emacs/lisp/bindings.el,v retrieving revision 1.209 diff -c -r1.209 bindings.el *** lisp/bindings.el 30 Jun 2008 19:37:02 -0000 1.209 --- lisp/bindings.el 29 Jul 2008 16:48:03 -0000 *************** *** 746,751 **** --- 749,755 ---- (define-key esc-map "!" 'shell-command) (define-key esc-map "|" 'shell-command-on-region) + (define-key esc-map "&" 'async-shell-command) (define-key ctl-x-map [right] 'next-buffer) (define-key ctl-x-map [C-right] 'next-buffer) Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.939 diff -c -r1.939 simple.el *** lisp/simple.el 27 Jul 2008 18:24:31 -0000 1.939 --- lisp/simple.el 29 Jul 2008 16:46:20 -0000 *************** *** 2011,2021 **** The arguments are the same as the ones of `read-from-minibuffer', except READ and KEYMAP are missing and HIST defaults to `shell-command-history'." ! (apply 'read-from-minibuffer prompt initial-contents ! minibuffer-local-shell-command-map ! nil ! (or hist 'shell-command-history) ! args)) (defun shell-command (command &optional output-buffer error-buffer) "Execute string COMMAND in inferior shell; display output, if any. --- 2004,2035 ---- The arguments are the same as the ones of `read-from-minibuffer', except READ and KEYMAP are missing and HIST defaults to `shell-command-history'." ! (minibuffer-with-setup-hook ! (lambda () ! (set (make-local-variable 'minibuffer-default-add-function) ! 'minibuffer-default-add-shell-commands)) ! (apply 'read-from-minibuffer prompt initial-contents ! minibuffer-local-shell-command-map ! nil ! (or hist 'shell-command-history) ! args))) ! ! (defun async-shell-command (command &optional output-buffer error-buffer) ! "Execute string COMMAND asynchronously. ! ! Like `shell-command' but if COMMAND doesn't end in ampersand, adds `&' ! surrounded by whitespace and executes the command asynchronously. ! The output appears in the buffer `*Async Shell Command*'." ! (interactive ! (list ! (read-shell-command "Async shell command: " nil nil ! (and buffer-file-name ! (file-relative-name buffer-file-name))) ! current-prefix-arg ! shell-command-default-error-buffer)) ! (unless (string-match "&[ \t]*\\'" command) ! (setq command (concat command " &"))) ! (shell-command command output-buffer error-buffer)) (defun shell-command (command &optional output-buffer error-buffer) "Execute string COMMAND in inferior shell; display output, if any. *************** *** 2069,2081 **** (interactive (list ! (minibuffer-with-setup-hook ! (lambda () ! (set (make-local-variable 'minibuffer-default-add-function) ! 'minibuffer-default-add-shell-commands)) ! (read-shell-command "Shell command: " nil nil ! (and buffer-file-name ! (file-relative-name buffer-file-name)))) current-prefix-arg shell-command-default-error-buffer)) ;; Look for a handler in case default-directory is a remote file name. --- 2083,2091 ---- (interactive (list ! (read-shell-command "Shell command: " nil nil ! (and buffer-file-name ! (file-relative-name buffer-file-name))) current-prefix-arg shell-command-default-error-buffer)) ;; Look for a handler in case default-directory is a remote file name. -- Juri Linkov http://www.jurta.org/emacs/