aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Love1999-01-23 21:50:18 +0000
committerDave Love1999-01-23 21:50:18 +0000
commita0184aeb8f58ec6249e1d15bfb272fea00bab2d1 (patch)
tree754d6fb575ab24e4b2af0635a3dc915788266c35
parent8afc622bcf8ab318891a31d721cfbd0363632a6e (diff)
downloademacs-a0184aeb8f58ec6249e1d15bfb272fea00bab2d1.tar.gz
emacs-a0184aeb8f58ec6249e1d15bfb272fea00bab2d1.zip
(shell-command-on-region): Return command's exit
status.
-rw-r--r--lisp/simple.el36
1 files changed, 20 insertions, 16 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index ab4fa875137..d2d6e41d063 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1,6 +1,6 @@
1;;; simple.el --- basic editing commands for Emacs 1;;; simple.el --- basic editing commands for Emacs
2 2
3;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 1998 3;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 1999
4;; Free Software Foundation, Inc. 4;; Free Software Foundation, Inc.
5 5
6;; This file is part of GNU Emacs. 6;; This file is part of GNU Emacs.
@@ -1184,7 +1184,8 @@ will be intermixed in the output stream.")
1184 error-buffer) 1184 error-buffer)
1185 "Execute string COMMAND in inferior shell with region as input. 1185 "Execute string COMMAND in inferior shell with region as input.
1186Normally display output (if any) in temp buffer `*Shell Command Output*'; 1186Normally display output (if any) in temp buffer `*Shell Command Output*';
1187Prefix arg means replace the region with it. 1187Prefix arg means replace the region with it. Return the exit code of
1188COMMAND.
1188 1189
1189To specify a coding system for converting non-ASCII characters 1190To specify a coding system for converting non-ASCII characters
1190in the input and output to the shell command, use \\[universal-coding-system-argument] 1191in the input and output to the shell command, use \\[universal-coding-system-argument]
@@ -1239,7 +1240,8 @@ of ERROR-BUFFER."
1239 (if error-buffer 1240 (if error-buffer
1240 (concat (file-name-directory temp-file-name-pattern) 1241 (concat (file-name-directory temp-file-name-pattern)
1241 (make-temp-name "scor")) 1242 (make-temp-name "scor"))
1242 nil))) 1243 nil))
1244 exit-status)
1243 (if (or replace 1245 (if (or replace
1244 (and output-buffer 1246 (and output-buffer
1245 (not (or (bufferp output-buffer) (stringp output-buffer)))) 1247 (not (or (bufferp output-buffer) (stringp output-buffer))))
@@ -1249,11 +1251,12 @@ of ERROR-BUFFER."
1249 ;; Don't muck with mark unless REPLACE says we should. 1251 ;; Don't muck with mark unless REPLACE says we should.
1250 (goto-char start) 1252 (goto-char start)
1251 (and replace (push-mark)) 1253 (and replace (push-mark))
1252 (call-process-region start end shell-file-name t 1254 (setq exit-status
1253 (if error-file 1255 (call-process-region start end shell-file-name t
1254 (list t error-file) 1256 (if error-file
1255 t) 1257 (list t error-file)
1256 nil shell-command-switch command) 1258 t)
1259 nil shell-command-switch command))
1257 (let ((shell-buffer (get-buffer "*Shell Command Output*"))) 1260 (let ((shell-buffer (get-buffer "*Shell Command Output*")))
1258 (and shell-buffer (not (eq shell-buffer (current-buffer))) 1261 (and shell-buffer (not (eq shell-buffer (current-buffer)))
1259 (kill-buffer shell-buffer))) 1262 (kill-buffer shell-buffer)))
@@ -1263,8 +1266,7 @@ of ERROR-BUFFER."
1263 ;; replacing its entire contents. 1266 ;; replacing its entire contents.
1264 (let ((buffer (get-buffer-create 1267 (let ((buffer (get-buffer-create
1265 (or output-buffer "*Shell Command Output*"))) 1268 (or output-buffer "*Shell Command Output*")))
1266 (success nil) 1269 (success nil))
1267 (exit-status nil))
1268 (unwind-protect 1270 (unwind-protect
1269 (if (eq buffer (current-buffer)) 1271 (if (eq buffer (current-buffer))
1270 ;; If the input is the same buffer as the output, 1272 ;; If the input is the same buffer as the output,
@@ -1279,9 +1281,10 @@ of ERROR-BUFFER."
1279 (if error-file 1281 (if error-file
1280 (list t error-file) 1282 (list t error-file)
1281 t) 1283 t)
1282 nil shell-command-switch command)) 1284 nil shell-command-switch
1283 (setq success t)) 1285 command)))
1284 ;; Clear the output buffer, then run the command with output there. 1286 ;; Clear the output buffer, then run the command with
1287 ;; output there.
1285 (save-excursion 1288 (save-excursion
1286 (set-buffer buffer) 1289 (set-buffer buffer)
1287 (setq buffer-read-only nil) 1290 (setq buffer-read-only nil)
@@ -1291,8 +1294,8 @@ of ERROR-BUFFER."
1291 (if error-file 1294 (if error-file
1292 (list buffer error-file) 1295 (list buffer error-file)
1293 buffer) 1296 buffer)
1294 nil shell-command-switch command)) 1297 nil shell-command-switch command)))
1295 (setq success t)) 1298 (setq success (zerop exit-status))
1296 ;; Report the amount of output. 1299 ;; Report the amount of output.
1297 (let ((lines (save-excursion 1300 (let ((lines (save-excursion
1298 (set-buffer buffer) 1301 (set-buffer buffer)
@@ -1323,7 +1326,8 @@ of ERROR-BUFFER."
1323 (set-buffer (get-buffer-create error-buffer)) 1326 (set-buffer (get-buffer-create error-buffer))
1324 ;; Do no formatting while reading error file, for fear of looping. 1327 ;; Do no formatting while reading error file, for fear of looping.
1325 (format-insert-file error-file nil) 1328 (format-insert-file error-file nil)
1326 (delete-file error-file))))) 1329 (delete-file error-file)))
1330 exit-status))
1327 1331
1328(defun shell-command-to-string (command) 1332(defun shell-command-to-string (command)
1329 "Execute shell command COMMAND and return its output as a string." 1333 "Execute shell command COMMAND and return its output as a string."