[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master 5e84dce: call-shell-region: New defun
From: |
Tino Calancha |
Subject: |
[Emacs-diffs] master 5e84dce: call-shell-region: New defun |
Date: |
Thu, 25 Aug 2016 13:24:32 +0000 (UTC) |
branch: master
commit 5e84dcefb4b7fcf3b5af985345ed1ee5ef5df135
Author: Tino Calancha <address@hidden>
Commit: Tino Calancha <address@hidden>
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.
---
doc/lispref/processes.texi | 20 +++++++++++++-------
etc/NEWS | 4 ++++
lisp/gnus/message.el | 4 +---
lisp/simple.el | 10 ++++------
lisp/subr.el | 22 ++++++++++++++++++++++
5 files changed, 44 insertions(+), 16 deletions(-)
diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi
index cd12012..e043578 100644
--- a/doc/lispref/processes.texi
+++ b/doc/lispref/processes.texi
@@ -492,20 +492,17 @@ address@hidden
@end smallexample
For example, the @code{shell-command-on-region} command uses
address@hidden in a manner similar to this:
address@hidden 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
address@hidden 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
address@hidden 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.
address@hidden 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 494a091..d30d1fa 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 cb4843e..e4e42df 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 6105f01..de8883a 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 8ab1178..96917b9 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.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master 5e84dce: call-shell-region: New defun,
Tino Calancha <=