aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorRichard M. Stallman1999-01-18 00:25:23 +0000
committerRichard M. Stallman1999-01-18 00:25:23 +0000
commit7fd4783900718ddcc13d6df17c1da5ae62f13edd (patch)
tree3e4382e10a34a3d0389b96dcd2a310120f66b812 /lisp
parenta7325b562fb6b1b6fe29fad6ca1445efc0c42a10 (diff)
downloademacs-7fd4783900718ddcc13d6df17c1da5ae62f13edd.tar.gz
emacs-7fd4783900718ddcc13d6df17c1da5ae62f13edd.zip
(shell-command-on-region-default-error-buffer): New var.
(shell-command-on-region): Use that variable as interactive value of ERROR-BUFFER argument.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/simple.el182
1 files changed, 96 insertions, 86 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 94cff99ee57..ab4fa875137 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1173,6 +1173,12 @@ In either case, the output is inserted after point (leaving mark after it)."
1173 (car (cdr (cdr (process-command process)))) 1173 (car (cdr (cdr (process-command process))))
1174 (substring signal 0 -1)))) 1174 (substring signal 0 -1))))
1175 1175
1176(defvar shell-command-on-region-default-error-buffer nil
1177 "*Name of buffer that `shell-command-on-region' uses for stderr.
1178This buffer is used when `shell-command-on-region' is run interactively.
1179A nil value for this variable means that output to stderr and stdout
1180will be intermixed in the output stream.")
1181
1176(defun shell-command-on-region (start end command 1182(defun shell-command-on-region (start end command
1177 &optional output-buffer replace 1183 &optional output-buffer replace
1178 error-buffer) 1184 error-buffer)
@@ -1211,7 +1217,10 @@ around it.
1211 1217
1212If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer 1218If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer
1213or buffer name to which to direct the command's standard error output. 1219or buffer name to which to direct the command's standard error output.
1214If it is nil, error output is mingled with regular output." 1220If it is nil, error output is mingled with regular output.
1221In an interactive call, the variable
1222`shell-command-on-region-default-error-buffer' specifies the value
1223of ERROR-BUFFER."
1215 (interactive (let ((string 1224 (interactive (let ((string
1216 ;; Do this before calling region-beginning 1225 ;; Do this before calling region-beginning
1217 ;; and region-end, in case subprocess output 1226 ;; and region-end, in case subprocess output
@@ -1224,96 +1233,97 @@ If it is nil, error output is mingled with regular output."
1224 (list (region-beginning) (region-end) 1233 (list (region-beginning) (region-end)
1225 string 1234 string
1226 current-prefix-arg 1235 current-prefix-arg
1227 current-prefix-arg))) 1236 current-prefix-arg
1237 shell-command-on-region-default-error-buffer)))
1228 (let ((error-file 1238 (let ((error-file
1229 (if error-buffer 1239 (if error-buffer
1230 (concat (file-name-directory temp-file-name-pattern) 1240 (concat (file-name-directory temp-file-name-pattern)
1231 (make-temp-name "scor")) 1241 (make-temp-name "scor"))
1232 nil))) 1242 nil)))
1233 (if (or replace 1243 (if (or replace
1234 (and output-buffer 1244 (and output-buffer
1235 (not (or (bufferp output-buffer) (stringp output-buffer)))) 1245 (not (or (bufferp output-buffer) (stringp output-buffer))))
1236 (equal (buffer-name (current-buffer)) "*Shell Command Output*")) 1246 (equal (buffer-name (current-buffer)) "*Shell Command Output*"))
1237 ;; Replace specified region with output from command. 1247 ;; Replace specified region with output from command.
1238 (let ((swap (and replace (< start end)))) 1248 (let ((swap (and replace (< start end))))
1239 ;; Don't muck with mark unless REPLACE says we should. 1249 ;; Don't muck with mark unless REPLACE says we should.
1240 (goto-char start) 1250 (goto-char start)
1241 (and replace (push-mark)) 1251 (and replace (push-mark))
1242 (call-process-region start end shell-file-name t 1252 (call-process-region start end shell-file-name t
1243 (if error-file 1253 (if error-file
1244 (list t error-file) 1254 (list t error-file)
1245 t) 1255 t)
1246 nil shell-command-switch command) 1256 nil shell-command-switch command)
1247 (let ((shell-buffer (get-buffer "*Shell Command Output*"))) 1257 (let ((shell-buffer (get-buffer "*Shell Command Output*")))
1248 (and shell-buffer (not (eq shell-buffer (current-buffer))) 1258 (and shell-buffer (not (eq shell-buffer (current-buffer)))
1249 (kill-buffer shell-buffer))) 1259 (kill-buffer shell-buffer)))
1250 ;; Don't muck with mark unless REPLACE says we should. 1260 ;; Don't muck with mark unless REPLACE says we should.
1251 (and replace swap (exchange-point-and-mark))) 1261 (and replace swap (exchange-point-and-mark)))
1252 ;; No prefix argument: put the output in a temp buffer, 1262 ;; No prefix argument: put the output in a temp buffer,
1253 ;; replacing its entire contents. 1263 ;; replacing its entire contents.
1254 (let ((buffer (get-buffer-create 1264 (let ((buffer (get-buffer-create
1255 (or output-buffer "*Shell Command Output*"))) 1265 (or output-buffer "*Shell Command Output*")))
1256 (success nil) 1266 (success nil)
1257 (exit-status nil)) 1267 (exit-status nil))
1258 (unwind-protect 1268 (unwind-protect
1259 (if (eq buffer (current-buffer)) 1269 (if (eq buffer (current-buffer))
1260 ;; If the input is the same buffer as the output, 1270 ;; If the input is the same buffer as the output,
1261 ;; delete everything but the specified region, 1271 ;; delete everything but the specified region,
1262 ;; then replace that region with the output. 1272 ;; then replace that region with the output.
1263 (progn (setq buffer-read-only nil) 1273 (progn (setq buffer-read-only nil)
1264 (delete-region (max start end) (point-max)) 1274 (delete-region (max start end) (point-max))
1265 (delete-region (point-min) (min start end)) 1275 (delete-region (point-min) (min start end))
1266 (setq exit-status 1276 (setq exit-status
1267 (call-process-region (point-min) (point-max) 1277 (call-process-region (point-min) (point-max)
1268 shell-file-name t 1278 shell-file-name t
1269 (if error-file 1279 (if error-file
1270 (list t error-file) 1280 (list t error-file)
1271 t) 1281 t)
1272 nil shell-command-switch command)) 1282 nil shell-command-switch command))
1273 (setq success t)) 1283 (setq success t))
1274 ;; Clear the output buffer, then run the command with output there. 1284 ;; Clear the output buffer, then run the command with output there.
1275 (save-excursion 1285 (save-excursion
1276 (set-buffer buffer) 1286 (set-buffer buffer)
1277 (setq buffer-read-only nil) 1287 (setq buffer-read-only nil)
1278 (erase-buffer)) 1288 (erase-buffer))
1279 (setq exit-status 1289 (setq exit-status
1280 (call-process-region start end shell-file-name nil 1290 (call-process-region start end shell-file-name nil
1281 (if error-file 1291 (if error-file
1282 (list buffer error-file) 1292 (list buffer error-file)
1283 buffer) 1293 buffer)
1284 nil shell-command-switch command)) 1294 nil shell-command-switch command))
1285 (setq success t)) 1295 (setq success t))
1286 ;; Report the amount of output. 1296 ;; Report the amount of output.
1287 (let ((lines (save-excursion 1297 (let ((lines (save-excursion
1288 (set-buffer buffer) 1298 (set-buffer buffer)
1289 (if (= (buffer-size) 0) 1299 (if (= (buffer-size) 0)
1290 0 1300 0
1291 (count-lines (point-min) (point-max)))))) 1301 (count-lines (point-min) (point-max))))))
1292 (cond ((= lines 0) 1302 (cond ((= lines 0)
1293 (if success 1303 (if success
1294 (message "(Shell command %sed with no output)" 1304 (message "(Shell command %sed with no output)"
1295 (if (equal 0 exit-status) 1305 (if (equal 0 exit-status)
1296 "succeed" 1306 "succeed"
1297 "fail"))) 1307 "fail")))
1298 (kill-buffer buffer)) 1308 (kill-buffer buffer))
1299 ((and success (= lines 1)) 1309 ((and success (= lines 1))
1300 (message "%s" 1310 (message "%s"
1301 (save-excursion 1311 (save-excursion
1302 (set-buffer buffer) 1312 (set-buffer buffer)
1303 (goto-char (point-min)) 1313 (goto-char (point-min))
1304 (buffer-substring (point) 1314 (buffer-substring (point)
1305 (progn (end-of-line) (point)))))) 1315 (progn (end-of-line) (point))))))
1306 (t 1316 (t
1307 (save-excursion 1317 (save-excursion
1308 (set-buffer buffer) 1318 (set-buffer buffer)
1309 (goto-char (point-min))) 1319 (goto-char (point-min)))
1310 (display-buffer buffer))))))) 1320 (display-buffer buffer)))))))
1311 (if (and error-file (file-exists-p error-file)) 1321 (if (and error-file (file-exists-p error-file))
1312 (save-excursion 1322 (save-excursion
1313 (set-buffer (get-buffer-create error-buffer)) 1323 (set-buffer (get-buffer-create error-buffer))
1314 ;; Do no formatting while reading error file, for fear of looping. 1324 ;; Do no formatting while reading error file, for fear of looping.
1315 (format-insert-file error-file nil) 1325 (format-insert-file error-file nil)
1316 (delete-file error-file))))) 1326 (delete-file error-file)))))
1317 1327
1318(defun shell-command-to-string (command) 1328(defun shell-command-to-string (command)
1319 "Execute shell command COMMAND and return its output as a string." 1329 "Execute shell command COMMAND and return its output as a string."