diff options
| author | Richard M. Stallman | 1997-08-15 23:41:50 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1997-08-15 23:41:50 +0000 |
| commit | cce1c318c06a91e3c099a1e9d34d9c997d8a538c (patch) | |
| tree | d925246c4be98a92471361622d1a0bcec3d409f0 | |
| parent | e6a17ab5e3d61cfdcfcfddfce48bd0a9fc0db782 (diff) | |
| download | emacs-cce1c318c06a91e3c099a1e9d34d9c997d8a538c.tar.gz emacs-cce1c318c06a91e3c099a1e9d34d9c997d8a538c.zip | |
(shell-command-on-region): New argument ERROR-BUFFER.
| -rw-r--r-- | lisp/simple.el | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 2f5562b5faf..aa9fa97aeaa 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -917,7 +917,8 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 917 | (substring signal 0 -1)))) | 917 | (substring signal 0 -1)))) |
| 918 | 918 | ||
| 919 | (defun shell-command-on-region (start end command | 919 | (defun shell-command-on-region (start end command |
| 920 | &optional output-buffer replace) | 920 | &optional output-buffer replace |
| 921 | error-buffer) | ||
| 921 | "Execute string COMMAND in inferior shell with region as input. | 922 | "Execute string COMMAND in inferior shell with region as input. |
| 922 | Normally display output (if any) in temp buffer `*Shell Command Output*'; | 923 | Normally display output (if any) in temp buffer `*Shell Command Output*'; |
| 923 | Prefix arg means replace the region with it. | 924 | Prefix arg means replace the region with it. |
| @@ -929,8 +930,8 @@ is encoded in the same coding system that will be used to save the file, | |||
| 929 | `buffer-file-coding-system'. If the output is going to replace the region, | 930 | `buffer-file-coding-system'. If the output is going to replace the region, |
| 930 | then it is decoded from that same coding system. | 931 | then it is decoded from that same coding system. |
| 931 | 932 | ||
| 932 | The noninteractive arguments are START, END, COMMAND, OUTPUT-BUFFER, REPLACE. | 933 | The noninteractive arguments are START, END, COMMAND, OUTPUT-BUFFER, REPLACE, |
| 933 | If REPLACE is non-nil, that means insert the output | 934 | ERROR-BUFFER. If REPLACE is non-nil, that means insert the output |
| 934 | in place of text from START to END, putting point and mark around it. | 935 | in place of text from START to END, putting point and mark around it. |
| 935 | Noninteractive callers can specify coding systems by binding | 936 | Noninteractive callers can specify coding systems by binding |
| 936 | `coding-system-for-read' and `coding-system-for-write'. | 937 | `coding-system-for-read' and `coding-system-for-write'. |
| @@ -946,7 +947,11 @@ that says to put the output in some other buffer. | |||
| 946 | If OUTPUT-BUFFER is a buffer or buffer name, put the output there. | 947 | If OUTPUT-BUFFER is a buffer or buffer name, put the output there. |
| 947 | If OUTPUT-BUFFER is not a buffer and not nil, | 948 | If OUTPUT-BUFFER is not a buffer and not nil, |
| 948 | insert output in the current buffer. | 949 | insert output in the current buffer. |
| 949 | In either case, the output is inserted after point (leaving mark after it)." | 950 | In either case, the output is inserted after point (leaving mark after it). |
| 951 | |||
| 952 | If optional fifth argument ERROR-BUFFER is non-nil, it is a buffer | ||
| 953 | or buffer name to which to direct the command's standard error output. | ||
| 954 | If it is nil, error output is mingled with regular output." | ||
| 950 | (interactive (let ((string | 955 | (interactive (let ((string |
| 951 | ;; Do this before calling region-beginning | 956 | ;; Do this before calling region-beginning |
| 952 | ;; and region-end, in case subprocess output | 957 | ;; and region-end, in case subprocess output |
| @@ -960,6 +965,11 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 960 | string | 965 | string |
| 961 | current-prefix-arg | 966 | current-prefix-arg |
| 962 | current-prefix-arg))) | 967 | current-prefix-arg))) |
| 968 | (let ((error-file | ||
| 969 | (if error-buffer | ||
| 970 | (concat (file-name-directory temp-file-name-pattern) | ||
| 971 | (make-temp-name "scor")) | ||
| 972 | nil))) | ||
| 963 | (if (or replace | 973 | (if (or replace |
| 964 | (and output-buffer | 974 | (and output-buffer |
| 965 | (not (or (bufferp output-buffer) (stringp output-buffer)))) | 975 | (not (or (bufferp output-buffer) (stringp output-buffer)))) |
| @@ -969,8 +979,11 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 969 | ;; Don't muck with mark unless REPLACE says we should. | 979 | ;; Don't muck with mark unless REPLACE says we should. |
| 970 | (goto-char start) | 980 | (goto-char start) |
| 971 | (and replace (push-mark)) | 981 | (and replace (push-mark)) |
| 972 | (call-process-region start end shell-file-name t t nil | 982 | (call-process-region start end shell-file-name t |
| 973 | shell-command-switch command) | 983 | (if error-file |
| 984 | (list t error-file) | ||
| 985 | t) | ||
| 986 | nil shell-command-switch command) | ||
| 974 | (let ((shell-buffer (get-buffer "*Shell Command Output*"))) | 987 | (let ((shell-buffer (get-buffer "*Shell Command Output*"))) |
| 975 | (and shell-buffer (not (eq shell-buffer (current-buffer))) | 988 | (and shell-buffer (not (eq shell-buffer (current-buffer))) |
| 976 | (kill-buffer shell-buffer))) | 989 | (kill-buffer shell-buffer))) |
| @@ -990,17 +1003,22 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 990 | (delete-region (max start end) (point-max)) | 1003 | (delete-region (max start end) (point-max)) |
| 991 | (delete-region (point-min) (min start end)) | 1004 | (delete-region (point-min) (min start end)) |
| 992 | (call-process-region (point-min) (point-max) | 1005 | (call-process-region (point-min) (point-max) |
| 993 | shell-file-name t t nil | 1006 | shell-file-name t |
| 994 | shell-command-switch command) | 1007 | (if error-file |
| 1008 | (list t error-file) | ||
| 1009 | t) | ||
| 1010 | nil shell-command-switch command) | ||
| 995 | (setq success t)) | 1011 | (setq success t)) |
| 996 | ;; Clear the output buffer, then run the command with output there. | 1012 | ;; Clear the output buffer, then run the command with output there. |
| 997 | (save-excursion | 1013 | (save-excursion |
| 998 | (set-buffer buffer) | 1014 | (set-buffer buffer) |
| 999 | (setq buffer-read-only nil) | 1015 | (setq buffer-read-only nil) |
| 1000 | (erase-buffer)) | 1016 | (erase-buffer)) |
| 1001 | (call-process-region start end shell-file-name | 1017 | (call-process-region start end shell-file-name nil |
| 1002 | nil buffer nil | 1018 | (if error-file |
| 1003 | shell-command-switch command) | 1019 | (list buffer error-file) |
| 1020 | buffer) | ||
| 1021 | nil shell-command-switch command) | ||
| 1004 | (setq success t)) | 1022 | (setq success t)) |
| 1005 | ;; Report the amount of output. | 1023 | ;; Report the amount of output. |
| 1006 | (let ((lines (save-excursion | 1024 | (let ((lines (save-excursion |
| @@ -1023,7 +1041,13 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 1023 | (save-excursion | 1041 | (save-excursion |
| 1024 | (set-buffer buffer) | 1042 | (set-buffer buffer) |
| 1025 | (goto-char (point-min))) | 1043 | (goto-char (point-min))) |
| 1026 | (display-buffer buffer)))))))) | 1044 | (display-buffer buffer))))))) |
| 1045 | (if (and error-file (file-exists-p error-file)) | ||
| 1046 | (save-excursion | ||
| 1047 | (set-buffer (get-buffer-create error-buffer)) | ||
| 1048 | ;; Do no formatting while reading error file, for fear of looping. | ||
| 1049 | (format-insert-file error-file nil) | ||
| 1050 | (delete-file error-file))))) | ||
| 1027 | 1051 | ||
| 1028 | (defun shell-command-to-string (command) | 1052 | (defun shell-command-to-string (command) |
| 1029 | "Execute shell command COMMAND and return its output as a string." | 1053 | "Execute shell command COMMAND and return its output as a string." |