From c945a962d9fcfb55dae2c9df2f419164258ba360 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Thu, 2 Jul 2009 22:47:52 +0000 Subject: [PATCH] (async-shell-command): New command. --- lisp/simple.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lisp/simple.el b/lisp/simple.el index 44d3ae5040d..0bdc21a75b0 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2054,6 +2054,23 @@ to `shell-command-history'." (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. -- 2.39.2