[Top][All Lists]
[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, 29 Jul 2008 19:51:08 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) |
> 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/
- Re: & and M-& to run programs asynchronously, (continued)
Re: & and M-& to run programs asynchronously, Juri Linkov, 2008/07/06
Re: & and M-& to run programs asynchronously, Daniel Clemente, 2008/07/16
- Re: & and M-& to run programs asynchronously, Juri Linkov, 2008/07/16
- Re: & and M-& to run programs asynchronously, Daniel Clemente, 2008/07/18
- Re: & and M-& to run programs asynchronously, Juri Linkov, 2008/07/18
- Re: & and M-& to run programs asynchronously, Mathias Dahl, 2008/07/22
- Re: & and M-& to run programs asynchronously, Juri Linkov, 2008/07/22
- Re: & and M-& to run programs asynchronously, Daniel Clemente, 2008/07/29
- Re: & and M-& to run programs asynchronously,
Juri Linkov <=
- Re: & and M-& to run programs asynchronously, Chong Yidong, 2008/07/31
- Re: & and M-& to run programs asynchronously, Juri Linkov, 2008/07/31