emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: & and M-& to run programs asynchronously


From: Juri Linkov
Subject: Re: & and M-& to run programs asynchronously
Date: Tue, 30 Jun 2009 03:02:45 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1.50 (x86_64-pc-linux-gnu)

>>> Could the patch for M-&=async-shell-command be finally checked in?
>>
>> I think `async-shell-command' in
>> http://thread.gmane.org/gmane.emacs.devel/99764/focus=101699
>> is just a starting point for implementing more powerful command
>> that accepts more proposed options (like either to display the output
>> buffer or not, etc.)
>
>   Ok; then could this starting point be checked in? It is already useful.
>
>   I think that before trying to extend it, it has to be correctly bound to 
> M-& in the right places and without colliding with other M-&
>   Extensions can also wait because there are many and there isn't full 
> consensus ([1]). So better get the base in first.
>
> [1] http://thread.gmane.org/gmane.emacs.devel/99764/focus=100293

Below is a ready patch submitted for verification before checking in:

Index: lisp/bindings.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/bindings.el,v
retrieving revision 1.219
diff -c -r1.219 bindings.el
*** lisp/bindings.el    23 Jun 2009 07:39:43 -0000      1.219
--- lisp/bindings.el    30 Jun 2009 00:01:46 -0000
***************
*** 756,761 ****
--- 760,766 ----
  
  (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.988
diff -c -r1.988 simple.el
*** lisp/simple.el      13 Jun 2009 18:56:11 -0000      1.988
--- lisp/simple.el      30 Jun 2009 00:02:15 -0000
***************
*** 2054,2059 ****
--- 2054,2076 ----
           (or hist 'shell-command-history)
           args)))
  
+ (defun async-shell-command (command &optional output-buffer error-buffer)
+   "Execute string COMMAND asynchronously in background.
+ 
+ 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.
  With prefix argument, insert the COMMAND's output at point.

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]