diff options
| author | Karl Heuer | 1996-02-21 21:25:30 +0000 |
|---|---|---|
| committer | Karl Heuer | 1996-02-21 21:25:30 +0000 |
| commit | c7edd03cbb0d99521bed05d6029998c7e0251124 (patch) | |
| tree | e8430f717a100aa3f8aa7125b9df0382db1aca2f | |
| parent | d8fc5f64984669b61f21bc7c14c442ea5d326ccd (diff) | |
| download | emacs-c7edd03cbb0d99521bed05d6029998c7e0251124.tar.gz emacs-c7edd03cbb0d99521bed05d6029998c7e0251124.zip | |
(shell-command): Call file name handler.
| -rw-r--r-- | lisp/simple.el | 102 |
1 files changed, 54 insertions, 48 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index 6d8686bfbb6..f42c8d860f7 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -772,54 +772,60 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 772 | (interactive (list (read-from-minibuffer "Shell command: " | 772 | (interactive (list (read-from-minibuffer "Shell command: " |
| 773 | nil nil nil 'shell-command-history) | 773 | nil nil nil 'shell-command-history) |
| 774 | current-prefix-arg)) | 774 | current-prefix-arg)) |
| 775 | (if (and output-buffer | 775 | ;; Look for a handler in case default-directory is a remote file name. |
| 776 | (not (or (bufferp output-buffer) (stringp output-buffer)))) | 776 | (let ((handler |
| 777 | (progn (barf-if-buffer-read-only) | 777 | (find-file-name-handler (directory-file-name default-directory) |
| 778 | (push-mark) | 778 | 'shell-command))) |
| 779 | ;; We do not use -f for csh; we will not support broken use of | 779 | (if handler |
| 780 | ;; .cshrcs. Even the BSD csh manual says to use | 780 | (funcall handler 'shell-command command output-buffer) |
| 781 | ;; "if ($?prompt) exit" before things which are not useful | 781 | (if (and output-buffer |
| 782 | ;; non-interactively. Besides, if someone wants their other | 782 | (not (or (bufferp output-buffer) (stringp output-buffer)))) |
| 783 | ;; aliases for shell commands then they can still have them. | 783 | (progn (barf-if-buffer-read-only) |
| 784 | (call-process shell-file-name nil t nil | 784 | (push-mark) |
| 785 | shell-command-switch command) | 785 | ;; We do not use -f for csh; we will not support broken use of |
| 786 | ;; This is like exchange-point-and-mark, but doesn't | 786 | ;; .cshrcs. Even the BSD csh manual says to use |
| 787 | ;; activate the mark. It is cleaner to avoid activation, | 787 | ;; "if ($?prompt) exit" before things which are not useful |
| 788 | ;; even though the command loop would deactivate the mark | 788 | ;; non-interactively. Besides, if someone wants their other |
| 789 | ;; because we inserted text. | 789 | ;; aliases for shell commands then they can still have them. |
| 790 | (goto-char (prog1 (mark t) | 790 | (call-process shell-file-name nil t nil |
| 791 | (set-marker (mark-marker) (point) | 791 | shell-command-switch command) |
| 792 | (current-buffer))))) | 792 | ;; This is like exchange-point-and-mark, but doesn't |
| 793 | ;; Preserve the match data in case called from a program. | 793 | ;; activate the mark. It is cleaner to avoid activation, |
| 794 | (save-match-data | 794 | ;; even though the command loop would deactivate the mark |
| 795 | (if (string-match "[ \t]*&[ \t]*$" command) | 795 | ;; because we inserted text. |
| 796 | ;; Command ending with ampersand means asynchronous. | 796 | (goto-char (prog1 (mark t) |
| 797 | (let ((buffer (get-buffer-create | 797 | (set-marker (mark-marker) (point) |
| 798 | (or output-buffer "*Async Shell Command*"))) | 798 | (current-buffer))))) |
| 799 | (directory default-directory) | 799 | ;; Preserve the match data in case called from a program. |
| 800 | proc) | 800 | (save-match-data |
| 801 | ;; Remove the ampersand. | 801 | (if (string-match "[ \t]*&[ \t]*$" command) |
| 802 | (setq command (substring command 0 (match-beginning 0))) | 802 | ;; Command ending with ampersand means asynchronous. |
| 803 | ;; If will kill a process, query first. | 803 | (let ((buffer (get-buffer-create |
| 804 | (setq proc (get-buffer-process buffer)) | 804 | (or output-buffer "*Async Shell Command*"))) |
| 805 | (if proc | 805 | (directory default-directory) |
| 806 | (if (yes-or-no-p "A command is running. Kill it? ") | 806 | proc) |
| 807 | (kill-process proc) | 807 | ;; Remove the ampersand. |
| 808 | (error "Shell command in progress"))) | 808 | (setq command (substring command 0 (match-beginning 0))) |
| 809 | (save-excursion | 809 | ;; If will kill a process, query first. |
| 810 | (set-buffer buffer) | 810 | (setq proc (get-buffer-process buffer)) |
| 811 | (setq buffer-read-only nil) | 811 | (if proc |
| 812 | (erase-buffer) | 812 | (if (yes-or-no-p "A command is running. Kill it? ") |
| 813 | (display-buffer buffer) | 813 | (kill-process proc) |
| 814 | (setq default-directory directory) | 814 | (error "Shell command in progress"))) |
| 815 | (setq proc (start-process "Shell" buffer shell-file-name | 815 | (save-excursion |
| 816 | shell-command-switch command)) | 816 | (set-buffer buffer) |
| 817 | (setq mode-line-process '(":%s")) | 817 | (setq buffer-read-only nil) |
| 818 | (require 'shell) (shell-mode) | 818 | (erase-buffer) |
| 819 | (set-process-sentinel proc 'shell-command-sentinel) | 819 | (display-buffer buffer) |
| 820 | )) | 820 | (setq default-directory directory) |
| 821 | (shell-command-on-region (point) (point) command nil) | 821 | (setq proc (start-process "Shell" buffer shell-file-name |
| 822 | )))) | 822 | shell-command-switch command)) |
| 823 | (setq mode-line-process '(":%s")) | ||
| 824 | (require 'shell) (shell-mode) | ||
| 825 | (set-process-sentinel proc 'shell-command-sentinel) | ||
| 826 | )) | ||
| 827 | (shell-command-on-region (point) (point) command nil) | ||
| 828 | )))))) | ||
| 823 | 829 | ||
| 824 | ;; We have a sentinel to prevent insertion of a termination message | 830 | ;; We have a sentinel to prevent insertion of a termination message |
| 825 | ;; in the buffer itself. | 831 | ;; in the buffer itself. |