comparison lisp/simple.el @ 21222:4824e5e6d88a

(shell-command-on-region): Amend message to report success or failure when no process output.
author Dave Love <fx@gnu.org>
date Thu, 19 Mar 1998 10:30:55 +0000
parents 20bba919ec72
children b787b88cc575
comparison
equal deleted inserted replaced
21221:cb6ab6de7548 21222:4824e5e6d88a
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, 1997 3 ;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 1998
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.
7 7
8 ;; GNU Emacs is free software; you can redistribute it and/or modify 8 ;; GNU Emacs is free software; you can redistribute it and/or modify
1179 (and replace swap (exchange-point-and-mark))) 1179 (and replace swap (exchange-point-and-mark)))
1180 ;; No prefix argument: put the output in a temp buffer, 1180 ;; No prefix argument: put the output in a temp buffer,
1181 ;; replacing its entire contents. 1181 ;; replacing its entire contents.
1182 (let ((buffer (get-buffer-create 1182 (let ((buffer (get-buffer-create
1183 (or output-buffer "*Shell Command Output*"))) 1183 (or output-buffer "*Shell Command Output*")))
1184 (success nil)) 1184 (success nil)
1185 (exit-status nil))
1185 (unwind-protect 1186 (unwind-protect
1186 (if (eq buffer (current-buffer)) 1187 (if (eq buffer (current-buffer))
1187 ;; If the input is the same buffer as the output, 1188 ;; If the input is the same buffer as the output,
1188 ;; delete everything but the specified region, 1189 ;; delete everything but the specified region,
1189 ;; then replace that region with the output. 1190 ;; then replace that region with the output.
1190 (progn (setq buffer-read-only nil) 1191 (progn (setq buffer-read-only nil)
1191 (delete-region (max start end) (point-max)) 1192 (delete-region (max start end) (point-max))
1192 (delete-region (point-min) (min start end)) 1193 (delete-region (point-min) (min start end))
1193 (call-process-region (point-min) (point-max) 1194 (setq exit-status
1194 shell-file-name t 1195 (call-process-region (point-min) (point-max)
1195 (if error-file 1196 shell-file-name t
1196 (list t error-file) 1197 (if error-file
1197 t) 1198 (list t error-file)
1198 nil shell-command-switch command) 1199 t)
1200 nil shell-command-switch command))
1199 (setq success t)) 1201 (setq success t))
1200 ;; Clear the output buffer, then run the command with output there. 1202 ;; Clear the output buffer, then run the command with output there.
1201 (save-excursion 1203 (save-excursion
1202 (set-buffer buffer) 1204 (set-buffer buffer)
1203 (setq buffer-read-only nil) 1205 (setq buffer-read-only nil)
1204 (erase-buffer)) 1206 (erase-buffer))
1205 (call-process-region start end shell-file-name nil 1207 (setq exit-status
1206 (if error-file 1208 (call-process-region start end shell-file-name nil
1207 (list buffer error-file) 1209 (if error-file
1208 buffer) 1210 (list buffer error-file)
1209 nil shell-command-switch command) 1211 buffer)
1212 nil shell-command-switch command))
1210 (setq success t)) 1213 (setq success t))
1211 ;; Report the amount of output. 1214 ;; Report the amount of output.
1212 (let ((lines (save-excursion 1215 (let ((lines (save-excursion
1213 (set-buffer buffer) 1216 (set-buffer buffer)
1214 (if (= (buffer-size) 0) 1217 (if (= (buffer-size) 0)
1215 0 1218 0
1216 (count-lines (point-min) (point-max)))))) 1219 (count-lines (point-min) (point-max))))))
1217 (cond ((= lines 0) 1220 (cond ((= lines 0)
1218 (if success 1221 (if success
1219 (message "(Shell command completed with no output)")) 1222 (message "(Shell command %sed with no output)"
1223 (if (equal 0 exit-status)
1224 "succeed"
1225 "fail")))
1220 (kill-buffer buffer)) 1226 (kill-buffer buffer))
1221 ((and success (= lines 1)) 1227 ((and success (= lines 1))
1222 (message "%s" 1228 (message "%s"
1223 (save-excursion 1229 (save-excursion
1224 (set-buffer buffer) 1230 (set-buffer buffer)