summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTino Calancha <tino.calancha@gmail.com>2016-08-25 22:17:56 +0900
committerTino Calancha <tino.calancha@gmail.com>2016-08-25 22:17:56 +0900
commit5e84dcefb4b7fcf3b5af985345ed1ee5ef5df135 (patch)
tree872bead49b7bcb8494df444d2f7448af4e45e932
parent95c82efdb141029de89d9136a9ce4fe907de7c5e (diff)
call-shell-region: New defun
Suggested by Stefan Monnier in Bug#22679. * lisp/subr.el (call-shell-region): New defun; execute a command in an inferior shell with the buffer region as input. * lisp/simple.el (shell-command-on-region): Use it. * lisp/gnus/message.el (message-do-fcc): Idem. * doc/lispref/processes.texi: Document call-shell-region in the manual. ;* etc/NEWS: Add entry for this new function.
-rw-r--r--doc/lispref/processes.texi20
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/gnus/message.el4
-rw-r--r--lisp/simple.el10
-rw-r--r--lisp/subr.el22
5 files changed, 44 insertions, 16 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index cd1201276e..e043578e29 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -492,20 +492,17 @@ inputinput@point{}
@end smallexample
For example, the @code{shell-command-on-region} command uses
-@code{call-process-region} in a manner similar to this:
+@code{call-shell-region} in a manner similar to this:
@smallexample
@group
-(call-process-region
+(call-shell-region
start end
- shell-file-name ; @r{name of program}
+ command ; @r{shell command}
nil ; @r{do not delete region}
- buffer ; @r{send output to @code{buffer}}
- nil ; @r{no redisplay during output}
- "-c" command) ; @r{arguments for the shell}
+ buffer) ; @r{send output to @code{buffer}}
@end group
@end smallexample
-@c It actually uses shell-command-switch, but no need to mention that here.
@end defun
@defun call-process-shell-command command &optional infile destination display
@@ -525,6 +522,15 @@ convention allowed passing any number of additional arguments after
supported, but strongly discouraged.
@end defun
+@defun call-shell-region start end command &optional delete destination
+This function sends the text from @var{start} to @var{end} as
+standard input to an inferior shell running @var{command}. This function
+is similar than @code{call-process-region}, with process being a shell.
+The arguments @code{delete}, @code{destination} and the return value
+are like in @code{call-process-region}.
+Note that this funtion doesn't accept additional arguments.
+@end defun
+
@defun shell-command-to-string command
This function executes @var{command} (a string) as a shell command,
then returns the command's output as a string.
diff --git a/etc/NEWS b/etc/NEWS
index 494a091a36..d30d1faf7a 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -56,6 +56,10 @@ affected by this, as SGI stopped supporting IRIX in December 2013.
* Changes in Emacs 25.2
+++
+** The new funtion 'call-shell-region' executes a command in an
+inferior shell with the buffer region as input.
+
++++
** The new user option 'shell-command-not-erase-buffer' controls
if the output buffer is erased between shell commands; if non-nil,
the output buffer is not erased; this variable also controls where
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el
index cb4843e146..e4e42df74b 100644
--- a/lisp/gnus/message.el
+++ b/lisp/gnus/message.el
@@ -5409,9 +5409,7 @@ Otherwise, generate and save a value for `canlock-password' first."
(setq file (pop list))
(if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file)
;; Pipe the article to the program in question.
- (call-process-region (point-min) (point-max) shell-file-name
- nil nil nil shell-command-switch
- (match-string 1 file))
+ (call-shell-region (point-min) (point-max) (match-string 1 file))
;; Save the article.
(setq file (expand-file-name file))
(unless (file-exists-p (file-name-directory file))
diff --git a/lisp/simple.el b/lisp/simple.el
index 6105f016b9..de8883a937 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3667,11 +3667,10 @@ interactively, this is t."
(goto-char start)
(and replace (push-mark (point) 'nomsg))
(setq exit-status
- (call-process-region start end shell-file-name replace
+ (call-shell-region start end command replace
(if error-file
(list t error-file)
- t)
- nil shell-command-switch command))
+ t)))
;; It is rude to delete a buffer which the command is not using.
;; (let ((shell-buffer (get-buffer "*Shell Command Output*")))
;; (and shell-buffer (not (eq shell-buffer (current-buffer)))
@@ -3709,11 +3708,10 @@ interactively, this is t."
(setq default-directory directory))
(shell-command--save-pos-or-erase)))
(setq exit-status
- (call-process-region start end shell-file-name nil
+ (call-shell-region start end command nil
(if error-file
(list buffer error-file)
- buffer)
- nil shell-command-switch command)))
+ buffer))))
;; Report the output.
(with-current-buffer buffer
(setq mode-line-process
diff --git a/lisp/subr.el b/lisp/subr.el
index 8ab1178f4c..96917b9ea9 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -3078,6 +3078,28 @@ Similar to `call-process-shell-command', but calls `process-file'."
infile buffer display
(if (file-remote-p default-directory) "-c" shell-command-switch)
(mapconcat 'identity (cons command args) " ")))
+
+(defun call-shell-region (start end command &optional delete buffer)
+ "Send text from START to END as input to an inferior shell running COMMAND.
+Delete the text if fourth arg DELETE is non-nil.
+
+Insert output in BUFFER before point; t means current buffer; nil for
+ BUFFER means discard it; 0 means discard and don't wait; and `(:file
+ FILE)', where FILE is a file name string, means that it should be
+ written to that file (if the file already exists it is overwritten).
+BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case,
+REAL-BUFFER says what to do with standard output, as above,
+while STDERR-FILE says what to do with standard error in the child.
+STDERR-FILE may be nil (discard standard error output),
+t (mix it with ordinary output), or a file name string.
+
+If BUFFER is 0, `call-shell-region' returns immediately with value nil.
+Otherwise it waits for COMMAND to terminate
+and returns a numeric exit status or a signal description string.
+If you quit, the process is killed with SIGINT, or SIGKILL if you quit again."
+ (call-process-region start end
+ shell-file-name delete buffer nil
+ shell-command-switch command))
;;;; Lisp macros to do various things temporarily.