1466 |
;; No prefix argument: put the output in a temp buffer, |
;; No prefix argument: put the output in a temp buffer, |
1467 |
;; replacing its entire contents. |
;; replacing its entire contents. |
1468 |
(let ((buffer (get-buffer-create |
(let ((buffer (get-buffer-create |
1469 |
(or output-buffer "*Shell Command Output*"))) |
(or output-buffer "*Shell Command Output*")))) |
|
(success nil)) |
|
1470 |
(unwind-protect |
(unwind-protect |
1471 |
(if (eq buffer (current-buffer)) |
(if (eq buffer (current-buffer)) |
1472 |
;; If the input is the same buffer as the output, |
;; If the input is the same buffer as the output, |
1498 |
(list buffer error-file) |
(list buffer error-file) |
1499 |
buffer) |
buffer) |
1500 |
nil shell-command-switch command))) |
nil shell-command-switch command))) |
|
(setq success (and exit-status (equal 0 exit-status))) |
|
1501 |
;; Report the output. |
;; Report the output. |
1502 |
(with-current-buffer buffer |
(with-current-buffer buffer |
1503 |
(setq mode-line-process |
(setq mode-line-process |
1504 |
(if (not success) |
(cond ((null exit-status) |
1505 |
(concat (format " - Exit [%d]" exit-status))))) |
" - Error") |
1506 |
|
((stringp exit-status) |
1507 |
|
(format " - Signal [%s]" exit-status)) |
1508 |
|
((not (equal 0 exit-status)) |
1509 |
|
(format " - Exit [%d]" exit-status))))) |
1510 |
(if (with-current-buffer buffer (> (point-max) (point-min))) |
(if (with-current-buffer buffer (> (point-max) (point-min))) |
1511 |
;; There's some output, display it |
;; There's some output, display it |
1512 |
(display-message-or-buffer buffer) |
(display-message-or-buffer buffer) |
1516 |
(< 0 (nth 7 (file-attributes error-file)))) |
(< 0 (nth 7 (file-attributes error-file)))) |
1517 |
"some error output" |
"some error output" |
1518 |
"no output"))) |
"no output"))) |
1519 |
(if (equal 0 exit-status) |
(cond ((null exit-status) |
1520 |
(message "(Shell command succeeded with %s)" |
(message "(Shell command failed with error)")) |
1521 |
output) |
((equal 0 exit-status) |
1522 |
(message "(Shell command failed with code %d and %s)" |
(message "(Shell command succeeded with %s)" |
1523 |
exit-status output))) |
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)))) |
1530 |
;; Don't kill: there might be useful info in the undo-log. |
;; Don't kill: there might be useful info in the undo-log. |
1531 |
;; (kill-buffer buffer) |
;; (kill-buffer buffer) |
1532 |
)))) |
)))) |