comparison lisp/process.el @ 377:d883f39b8495 r21-2b4

Import from CVS: tag r21-2b4
author cvs
date Mon, 13 Aug 2007 11:05:42 +0200
parents cc15677e0335
children 8626e4521993
comparison
equal deleted inserted replaced
376:e2295b4d9f2e 377:d883f39b8495
243 ;; No prefix argument: put the output in a temp buffer, 243 ;; No prefix argument: put the output in a temp buffer,
244 ;; replacing its entire contents. 244 ;; replacing its entire contents.
245 (let ((buffer (get-buffer-create 245 (let ((buffer (get-buffer-create
246 (or output-buffer "*Shell Command Output*"))) 246 (or output-buffer "*Shell Command Output*")))
247 (success nil) 247 (success nil)
248 (exit-status nil)
248 (directory default-directory)) 249 (directory default-directory))
249 (unwind-protect 250 (unwind-protect
250 (if (eq buffer (current-buffer)) 251 (if (eq buffer (current-buffer))
251 ;; If the input is the same buffer as the output, 252 ;; If the input is the same buffer as the output,
252 ;; delete everything but the specified region, 253 ;; delete everything but the specified region,
253 ;; then replace that region with the output. 254 ;; then replace that region with the output.
254 (progn (setq buffer-read-only nil) 255 (progn (setq buffer-read-only nil)
255 (delete-region (max start end) (point-max)) 256 (delete-region (max start end) (point-max))
256 (delete-region (point-min) (max start end)) 257 (delete-region (point-min) (max start end))
257 (call-process-region (point-min) (point-max) 258 (setq exit-status
258 shell-file-name t t nil 259 (call-process-region (point-min) (point-max)
259 shell-command-switch command) 260 shell-file-name t t nil
261 shell-command-switch command))
260 (setq success t)) 262 (setq success t))
261 ;; Clear the output buffer, 263 ;; Clear the output buffer,
262 ;; then run the command with output there. 264 ;; then run the command with output there.
263 (save-excursion 265 (save-excursion
264 (set-buffer buffer) 266 (set-buffer buffer)
265 (setq buffer-read-only nil) 267 (setq buffer-read-only nil)
266 ;; XEmacs change 268 ;; XEmacs change
267 (setq default-directory directory) 269 (setq default-directory directory)
268 (erase-buffer)) 270 (erase-buffer))
269 (call-process-region start end shell-file-name 271 (setq exit-status
270 nil buffer nil 272 (call-process-region start end shell-file-name
271 shell-command-switch command) 273 nil buffer nil
274 shell-command-switch command))
272 (setq success t)) 275 (setq success t))
273 ;; Report the amount of output. 276 ;; Report the amount of output.
274 (let ((lines (save-excursion 277 (let ((lines (save-excursion
275 (set-buffer buffer) 278 (set-buffer buffer)
276 (if (= (buffer-size) 0) 279 (if (= (buffer-size) 0)
278 (count-lines (point-min) (point-max)))))) 281 (count-lines (point-min) (point-max))))))
279 (cond ((= lines 0) 282 (cond ((= lines 0)
280 (if success 283 (if success
281 (display-message 284 (display-message
282 'command 285 'command
283 "(Shell command completed with no output)")) 286 (if (eql exit-status 0)
287 "(Shell command succeeded with no output)"
288 "(Shell command failed with no output)")))
284 (kill-buffer buffer)) 289 (kill-buffer buffer))
285 ((and success (= lines 1)) 290 ((and success (= lines 1))
286 (message "%s" 291 (message "%s"
287 (save-excursion 292 (save-excursion
288 (set-buffer buffer) 293 (set-buffer buffer)