diff options
| author | Tino Calancha | 2016-08-25 22:17:56 +0900 |
|---|---|---|
| committer | Tino Calancha | 2016-08-25 22:17:56 +0900 |
| commit | 5e84dcefb4b7fcf3b5af985345ed1ee5ef5df135 (patch) | |
| tree | 872bead49b7bcb8494df444d2f7448af4e45e932 | |
| parent | 95c82efdb141029de89d9136a9ce4fe907de7c5e (diff) | |
| download | emacs-5e84dcefb4b7fcf3b5af985345ed1ee5ef5df135.tar.gz emacs-5e84dcefb4b7fcf3b5af985345ed1ee5ef5df135.zip | |
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.texi | 20 | ||||
| -rw-r--r-- | etc/NEWS | 4 | ||||
| -rw-r--r-- | lisp/gnus/message.el | 4 | ||||
| -rw-r--r-- | lisp/simple.el | 10 | ||||
| -rw-r--r-- | lisp/subr.el | 22 |
5 files changed, 44 insertions, 16 deletions
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index cd1201276e2..e043578e298 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi | |||
| @@ -492,20 +492,17 @@ inputinput@point{} | |||
| 492 | @end smallexample | 492 | @end smallexample |
| 493 | 493 | ||
| 494 | For example, the @code{shell-command-on-region} command uses | 494 | For example, the @code{shell-command-on-region} command uses |
| 495 | @code{call-process-region} in a manner similar to this: | 495 | @code{call-shell-region} in a manner similar to this: |
| 496 | 496 | ||
| 497 | @smallexample | 497 | @smallexample |
| 498 | @group | 498 | @group |
| 499 | (call-process-region | 499 | (call-shell-region |
| 500 | start end | 500 | start end |
| 501 | shell-file-name ; @r{name of program} | 501 | command ; @r{shell command} |
| 502 | nil ; @r{do not delete region} | 502 | nil ; @r{do not delete region} |
| 503 | buffer ; @r{send output to @code{buffer}} | 503 | buffer) ; @r{send output to @code{buffer}} |
| 504 | nil ; @r{no redisplay during output} | ||
| 505 | "-c" command) ; @r{arguments for the shell} | ||
| 506 | @end group | 504 | @end group |
| 507 | @end smallexample | 505 | @end smallexample |
| 508 | @c It actually uses shell-command-switch, but no need to mention that here. | ||
| 509 | @end defun | 506 | @end defun |
| 510 | 507 | ||
| 511 | @defun call-process-shell-command command &optional infile destination display | 508 | @defun call-process-shell-command command &optional infile destination display |
| @@ -525,6 +522,15 @@ convention allowed passing any number of additional arguments after | |||
| 525 | supported, but strongly discouraged. | 522 | supported, but strongly discouraged. |
| 526 | @end defun | 523 | @end defun |
| 527 | 524 | ||
| 525 | @defun call-shell-region start end command &optional delete destination | ||
| 526 | This function sends the text from @var{start} to @var{end} as | ||
| 527 | standard input to an inferior shell running @var{command}. This function | ||
| 528 | is similar than @code{call-process-region}, with process being a shell. | ||
| 529 | The arguments @code{delete}, @code{destination} and the return value | ||
| 530 | are like in @code{call-process-region}. | ||
| 531 | Note that this funtion doesn't accept additional arguments. | ||
| 532 | @end defun | ||
| 533 | |||
| 528 | @defun shell-command-to-string command | 534 | @defun shell-command-to-string command |
| 529 | This function executes @var{command} (a string) as a shell command, | 535 | This function executes @var{command} (a string) as a shell command, |
| 530 | then returns the command's output as a string. | 536 | then returns the command's output as a string. |
| @@ -56,6 +56,10 @@ affected by this, as SGI stopped supporting IRIX in December 2013. | |||
| 56 | * Changes in Emacs 25.2 | 56 | * Changes in Emacs 25.2 |
| 57 | 57 | ||
| 58 | +++ | 58 | +++ |
| 59 | ** The new funtion 'call-shell-region' executes a command in an | ||
| 60 | inferior shell with the buffer region as input. | ||
| 61 | |||
| 62 | +++ | ||
| 59 | ** The new user option 'shell-command-not-erase-buffer' controls | 63 | ** The new user option 'shell-command-not-erase-buffer' controls |
| 60 | if the output buffer is erased between shell commands; if non-nil, | 64 | if the output buffer is erased between shell commands; if non-nil, |
| 61 | the output buffer is not erased; this variable also controls where | 65 | the output buffer is not erased; this variable also controls where |
diff --git a/lisp/gnus/message.el b/lisp/gnus/message.el index cb4843e1462..e4e42df74bc 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." | |||
| 5409 | (setq file (pop list)) | 5409 | (setq file (pop list)) |
| 5410 | (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file) | 5410 | (if (string-match "^[ \t]*|[ \t]*\\(.*\\)[ \t]*$" file) |
| 5411 | ;; Pipe the article to the program in question. | 5411 | ;; Pipe the article to the program in question. |
| 5412 | (call-process-region (point-min) (point-max) shell-file-name | 5412 | (call-shell-region (point-min) (point-max) (match-string 1 file)) |
| 5413 | nil nil nil shell-command-switch | ||
| 5414 | (match-string 1 file)) | ||
| 5415 | ;; Save the article. | 5413 | ;; Save the article. |
| 5416 | (setq file (expand-file-name file)) | 5414 | (setq file (expand-file-name file)) |
| 5417 | (unless (file-exists-p (file-name-directory file)) | 5415 | (unless (file-exists-p (file-name-directory file)) |
diff --git a/lisp/simple.el b/lisp/simple.el index 6105f016b90..de8883a9376 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -3667,11 +3667,10 @@ interactively, this is t." | |||
| 3667 | (goto-char start) | 3667 | (goto-char start) |
| 3668 | (and replace (push-mark (point) 'nomsg)) | 3668 | (and replace (push-mark (point) 'nomsg)) |
| 3669 | (setq exit-status | 3669 | (setq exit-status |
| 3670 | (call-process-region start end shell-file-name replace | 3670 | (call-shell-region start end command replace |
| 3671 | (if error-file | 3671 | (if error-file |
| 3672 | (list t error-file) | 3672 | (list t error-file) |
| 3673 | t) | 3673 | t))) |
| 3674 | nil shell-command-switch command)) | ||
| 3675 | ;; It is rude to delete a buffer which the command is not using. | 3674 | ;; It is rude to delete a buffer which the command is not using. |
| 3676 | ;; (let ((shell-buffer (get-buffer "*Shell Command Output*"))) | 3675 | ;; (let ((shell-buffer (get-buffer "*Shell Command Output*"))) |
| 3677 | ;; (and shell-buffer (not (eq shell-buffer (current-buffer))) | 3676 | ;; (and shell-buffer (not (eq shell-buffer (current-buffer))) |
| @@ -3709,11 +3708,10 @@ interactively, this is t." | |||
| 3709 | (setq default-directory directory)) | 3708 | (setq default-directory directory)) |
| 3710 | (shell-command--save-pos-or-erase))) | 3709 | (shell-command--save-pos-or-erase))) |
| 3711 | (setq exit-status | 3710 | (setq exit-status |
| 3712 | (call-process-region start end shell-file-name nil | 3711 | (call-shell-region start end command nil |
| 3713 | (if error-file | 3712 | (if error-file |
| 3714 | (list buffer error-file) | 3713 | (list buffer error-file) |
| 3715 | buffer) | 3714 | buffer)))) |
| 3716 | nil shell-command-switch command))) | ||
| 3717 | ;; Report the output. | 3715 | ;; Report the output. |
| 3718 | (with-current-buffer buffer | 3716 | (with-current-buffer buffer |
| 3719 | (setq mode-line-process | 3717 | (setq mode-line-process |
diff --git a/lisp/subr.el b/lisp/subr.el index 8ab1178f4c5..96917b9ea96 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -3078,6 +3078,28 @@ Similar to `call-process-shell-command', but calls `process-file'." | |||
| 3078 | infile buffer display | 3078 | infile buffer display |
| 3079 | (if (file-remote-p default-directory) "-c" shell-command-switch) | 3079 | (if (file-remote-p default-directory) "-c" shell-command-switch) |
| 3080 | (mapconcat 'identity (cons command args) " "))) | 3080 | (mapconcat 'identity (cons command args) " "))) |
| 3081 | |||
| 3082 | (defun call-shell-region (start end command &optional delete buffer) | ||
| 3083 | "Send text from START to END as input to an inferior shell running COMMAND. | ||
| 3084 | Delete the text if fourth arg DELETE is non-nil. | ||
| 3085 | |||
| 3086 | Insert output in BUFFER before point; t means current buffer; nil for | ||
| 3087 | BUFFER means discard it; 0 means discard and don't wait; and `(:file | ||
| 3088 | FILE)', where FILE is a file name string, means that it should be | ||
| 3089 | written to that file (if the file already exists it is overwritten). | ||
| 3090 | BUFFER can also have the form (REAL-BUFFER STDERR-FILE); in that case, | ||
| 3091 | REAL-BUFFER says what to do with standard output, as above, | ||
| 3092 | while STDERR-FILE says what to do with standard error in the child. | ||
| 3093 | STDERR-FILE may be nil (discard standard error output), | ||
| 3094 | t (mix it with ordinary output), or a file name string. | ||
| 3095 | |||
| 3096 | If BUFFER is 0, `call-shell-region' returns immediately with value nil. | ||
| 3097 | Otherwise it waits for COMMAND to terminate | ||
| 3098 | and returns a numeric exit status or a signal description string. | ||
| 3099 | If you quit, the process is killed with SIGINT, or SIGKILL if you quit again." | ||
| 3100 | (call-process-region start end | ||
| 3101 | shell-file-name delete buffer nil | ||
| 3102 | shell-command-switch command)) | ||
| 3081 | 3103 | ||
| 3082 | ;;;; Lisp macros to do various things temporarily. | 3104 | ;;;; Lisp macros to do various things temporarily. |
| 3083 | 3105 | ||