call-shell-region: New defun
authorTino Calancha <tino.calancha@gmail.com>
Thu, 25 Aug 2016 13:17:56 +0000 (22:17 +0900)
committerTino Calancha <tino.calancha@gmail.com>
Thu, 25 Aug 2016 13:17:56 +0000 (22:17 +0900)
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.

doc/lispref/processes.texi
etc/NEWS
lisp/gnus/message.el
lisp/simple.el
lisp/subr.el

index cd1201276e29586a2a3309fa1961639821e0a4e4..e043578e298ca4e119acb93c77ab4f156bf35cc7 100644 (file)
@@ -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.
index 494a091a3616a7a6e92222aed84dc2db802cafa4..d30d1faf7ab55bd4c9082bf9114cd01406aeb0f8 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -55,6 +55,10 @@ affected by this, as SGI stopped supporting IRIX in December 2013.
 \f
 * 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,
index cb4843e14628f3ab0b65f43ebc318bab2b1540af..e4e42df74bc8959ed0cbae5bce24a9ba5608b647 100644 (file)
@@ -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))
index 6105f016b90f5087d3cbcb10782a5267291bf5bf..de8883a937632e73a5c75e2d51805f2a85b549f8 100644 (file)
@@ -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
index 8ab1178f4c5df414598a9864c5eb90fc82a56f28..96917b9ea96290c206b29ab0b545c18d67055ea5 100644 (file)
@@ -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))
 \f
 ;;;; Lisp macros to do various things temporarily.