Mercurial > emacs
comparison lisp/simple.el @ 46088:9d9568a15aa3
(shell-command-on-region): Handle errors and signals
from shell command execution.
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Sat, 29 Jun 2002 18:08:22 +0000 |
parents | 312f417a8513 |
children | f52b57f5e2a4 |
comparison
equal
deleted
inserted
replaced
46087:393e6d989d19 | 46088:9d9568a15aa3 |
---|---|
1464 ;; Don't muck with mark unless REPLACE says we should. | 1464 ;; Don't muck with mark unless REPLACE says we should. |
1465 (and replace swap (exchange-point-and-mark))) | 1465 (and replace swap (exchange-point-and-mark))) |
1466 ;; No prefix argument: put the output in a temp buffer, | 1466 ;; No prefix argument: put the output in a temp buffer, |
1467 ;; replacing its entire contents. | 1467 ;; replacing its entire contents. |
1468 (let ((buffer (get-buffer-create | 1468 (let ((buffer (get-buffer-create |
1469 (or output-buffer "*Shell Command Output*"))) | 1469 (or output-buffer "*Shell Command Output*")))) |
1470 (success nil)) | |
1471 (unwind-protect | 1470 (unwind-protect |
1472 (if (eq buffer (current-buffer)) | 1471 (if (eq buffer (current-buffer)) |
1473 ;; If the input is the same buffer as the output, | 1472 ;; If the input is the same buffer as the output, |
1474 ;; delete everything but the specified region, | 1473 ;; delete everything but the specified region, |
1475 ;; then replace that region with the output. | 1474 ;; then replace that region with the output. |
1497 (call-process-region start end shell-file-name nil | 1496 (call-process-region start end shell-file-name nil |
1498 (if error-file | 1497 (if error-file |
1499 (list buffer error-file) | 1498 (list buffer error-file) |
1500 buffer) | 1499 buffer) |
1501 nil shell-command-switch command))) | 1500 nil shell-command-switch command))) |
1502 (setq success (and exit-status (equal 0 exit-status))) | |
1503 ;; Report the output. | 1501 ;; Report the output. |
1504 (with-current-buffer buffer | 1502 (with-current-buffer buffer |
1505 (setq mode-line-process | 1503 (setq mode-line-process |
1506 (if (not success) | 1504 (cond ((null exit-status) |
1507 (concat (format " - Exit [%d]" exit-status))))) | 1505 " - Error") |
1506 ((stringp exit-status) | |
1507 (format " - Signal [%s]" exit-status)) | |
1508 ((not (equal 0 exit-status)) | |
1509 (format " - Exit [%d]" exit-status))))) | |
1508 (if (with-current-buffer buffer (> (point-max) (point-min))) | 1510 (if (with-current-buffer buffer (> (point-max) (point-min))) |
1509 ;; There's some output, display it | 1511 ;; There's some output, display it |
1510 (display-message-or-buffer buffer) | 1512 (display-message-or-buffer buffer) |
1511 ;; No output; error? | 1513 ;; No output; error? |
1512 (let ((output | 1514 (let ((output |
1513 (if (and error-file | 1515 (if (and error-file |
1514 (< 0 (nth 7 (file-attributes error-file)))) | 1516 (< 0 (nth 7 (file-attributes error-file)))) |
1515 "some error output" | 1517 "some error output" |
1516 "no output"))) | 1518 "no output"))) |
1517 (if (equal 0 exit-status) | 1519 (cond ((null exit-status) |
1518 (message "(Shell command succeeded with %s)" | 1520 (message "(Shell command failed with error)")) |
1519 output) | 1521 ((equal 0 exit-status) |
1520 (message "(Shell command failed with code %d and %s)" | 1522 (message "(Shell command succeeded with %s)" |
1521 exit-status output))) | 1523 output)) |
1524 ((stringp exit-status) | |
1525 (message "(Shell command killed by signal %s)" | |
1526 exit-status)) | |
1527 (t | |
1528 (message "(Shell command failed with code %d and %s)" | |
1529 exit-status output)))) | |
1522 ;; Don't kill: there might be useful info in the undo-log. | 1530 ;; Don't kill: there might be useful info in the undo-log. |
1523 ;; (kill-buffer buffer) | 1531 ;; (kill-buffer buffer) |
1524 )))) | 1532 )))) |
1525 | 1533 |
1526 (when (and error-file (file-exists-p error-file)) | 1534 (when (and error-file (file-exists-p error-file)) |