diff options
| author | Karl Heuer | 1995-07-17 23:03:53 +0000 |
|---|---|---|
| committer | Karl Heuer | 1995-07-17 23:03:53 +0000 |
| commit | bcad498517424aae31e52e6cbda4f7ac553eb503 (patch) | |
| tree | a9bc3b8d4a5ef73dfa0cdf908368fd3638cec642 | |
| parent | 8b262cbcd53b15b1159e5df62f2a5525cdba5bc6 (diff) | |
| download | emacs-bcad498517424aae31e52e6cbda4f7ac553eb503.tar.gz emacs-bcad498517424aae31e52e6cbda4f7ac553eb503.zip | |
(shell-command): Use save-match-data.
Put the buffer in shell mode, don't use shell-command-filter.
(shell-command-filter): Deleted.
(shell-command-sentinel): Don't reset the mode line.
Don't test the buffer name--what was that for, anyway?.
(column-number-mode): New variable and new command.
| -rw-r--r-- | lisp/simple.el | 122 |
1 files changed, 54 insertions, 68 deletions
diff --git a/lisp/simple.el b/lisp/simple.el index e1d9b012cfc..0b69cf6ed68 100644 --- a/lisp/simple.el +++ b/lisp/simple.el | |||
| @@ -742,9 +742,10 @@ then call `undo-more' one or more times to undo them." | |||
| 742 | 742 | ||
| 743 | If COMMAND ends in ampersand, execute it asynchronously. | 743 | If COMMAND ends in ampersand, execute it asynchronously. |
| 744 | The output appears in the buffer `*Async Shell Command*'. | 744 | The output appears in the buffer `*Async Shell Command*'. |
| 745 | That buffer is in shell mode. | ||
| 745 | 746 | ||
| 746 | Otherwise, COMMAND is executed synchronously. The output appears | 747 | Otherwise, COMMAND is executed synchronously. The output appears in the |
| 747 | in the buffer `*Shell Command Output*'. | 748 | buffer `*Shell Command Output*'. |
| 748 | If the output is one line, it is displayed in the echo area *as well*, | 749 | If the output is one line, it is displayed in the echo area *as well*, |
| 749 | but it is nonetheless available in buffer `*Shell Command Output*', | 750 | but it is nonetheless available in buffer `*Shell Command Output*', |
| 750 | even though that buffer is not automatically displayed. | 751 | even though that buffer is not automatically displayed. |
| @@ -771,80 +772,51 @@ In either case, the output is inserted after point (leaving mark after it)." | |||
| 771 | ;; aliases for shell commands then they can still have them. | 772 | ;; aliases for shell commands then they can still have them. |
| 772 | (call-process shell-file-name nil t nil | 773 | (call-process shell-file-name nil t nil |
| 773 | shell-command-switch command) | 774 | shell-command-switch command) |
| 774 | ;; This is like exchange-point-and-mark, but doesn't activate the mark. | 775 | ;; This is like exchange-point-and-mark, but doesn't |
| 775 | ;; It is cleaner to avoid activation, even though the command | 776 | ;; activate the mark. It is cleaner to avoid activation, |
| 776 | ;; loop would deactivate the mark because we inserted text. | 777 | ;; even though the command loop would deactivate the mark |
| 778 | ;; because we inserted text. | ||
| 777 | (goto-char (prog1 (mark t) | 779 | (goto-char (prog1 (mark t) |
| 778 | (set-marker (mark-marker) (point) | 780 | (set-marker (mark-marker) (point) |
| 779 | (current-buffer))))) | 781 | (current-buffer))))) |
| 780 | ;; Preserve the match data in case called from a program. | 782 | ;; Preserve the match data in case called from a program. |
| 781 | (let ((data (match-data))) | 783 | (save-match-data |
| 782 | (unwind-protect | 784 | (if (string-match "[ \t]*&[ \t]*$" command) |
| 783 | (if (string-match "[ \t]*&[ \t]*$" command) | 785 | ;; Command ending with ampersand means asynchronous. |
| 784 | ;; Command ending with ampersand means asynchronous. | 786 | (let ((buffer (get-buffer-create |
| 785 | (let ((buffer (get-buffer-create | 787 | (or output-buffer "*Asynch Shell Command*"))) |
| 786 | (or output-buffer "*Asynch Shell Command*"))) | 788 | (directory default-directory) |
| 787 | (directory default-directory) | 789 | proc) |
| 788 | proc) | 790 | ;; Remove the ampersand. |
| 789 | ;; Remove the ampersand. | 791 | (setq command (substring command 0 (match-beginning 0))) |
| 790 | (setq command (substring command 0 (match-beginning 0))) | 792 | ;; If will kill a process, query first. |
| 791 | ;; If will kill a process, query first. | 793 | (setq proc (get-buffer-process buffer)) |
| 792 | (setq proc (get-buffer-process buffer)) | 794 | (if proc |
| 793 | (if proc | 795 | (if (yes-or-no-p "A command is running. Kill it? ") |
| 794 | (if (yes-or-no-p "A command is running. Kill it? ") | 796 | (kill-process proc) |
| 795 | (kill-process proc) | 797 | (error "Shell command in progress"))) |
| 796 | (error "Shell command in progress"))) | 798 | (save-excursion |
| 797 | (save-excursion | 799 | (set-buffer buffer) |
| 798 | (set-buffer buffer) | 800 | (setq buffer-read-only nil) |
| 799 | (setq buffer-read-only nil) | 801 | (erase-buffer) |
| 800 | (erase-buffer) | 802 | (display-buffer buffer) |
| 801 | (display-buffer buffer) | 803 | (setq default-directory directory) |
| 802 | (setq default-directory directory) | 804 | (setq proc (start-process "Shell" buffer shell-file-name |
| 803 | (setq proc (start-process "Shell" buffer | 805 | shell-command-switch command)) |
| 804 | shell-file-name | 806 | (setq mode-line-process '(":%s")) |
| 805 | shell-command-switch command)) | 807 | (require 'shell) (shell-mode) |
| 806 | (setq mode-line-process '(":%s")) | 808 | (set-process-sentinel proc 'shell-command-sentinel) |
| 807 | (set-process-sentinel proc 'shell-command-sentinel) | 809 | )) |
| 808 | (set-process-filter proc 'shell-command-filter) | 810 | (shell-command-on-region (point) (point) command nil) |
| 809 | )) | 811 | )))) |
| 810 | (shell-command-on-region (point) (point) command nil)) | ||
| 811 | (store-match-data data))))) | ||
| 812 | 812 | ||
| 813 | ;; We have a sentinel to prevent insertion of a termination message | 813 | ;; We have a sentinel to prevent insertion of a termination message |
| 814 | ;; in the buffer itself. | 814 | ;; in the buffer itself. |
| 815 | (defun shell-command-sentinel (process signal) | 815 | (defun shell-command-sentinel (process signal) |
| 816 | (if (and (memq (process-status process) '(exit signal)) | 816 | (if (memq (process-status process) '(exit signal)) |
| 817 | (buffer-name (process-buffer process))) | 817 | (message "%s: %s." |
| 818 | (progn | 818 | (car (cdr (cdr (process-command process)))) |
| 819 | (message "%s: %s." | 819 | (substring signal 0 -1)))) |
| 820 | (car (cdr (cdr (process-command process)))) | ||
| 821 | (substring signal 0 -1)) | ||
| 822 | (save-excursion | ||
| 823 | (set-buffer (process-buffer process)) | ||
| 824 | (setq mode-line-process nil)) | ||
| 825 | (delete-process process)))) | ||
| 826 | |||
| 827 | (defun shell-command-filter (proc string) | ||
| 828 | ;; Do save-excursion by hand so that we can leave point numerically unchanged | ||
| 829 | ;; despite an insertion immediately after it. | ||
| 830 | (let* ((obuf (current-buffer)) | ||
| 831 | (buffer (process-buffer proc)) | ||
| 832 | opoint | ||
| 833 | (window (get-buffer-window buffer)) | ||
| 834 | (pos (window-start window))) | ||
| 835 | (unwind-protect | ||
| 836 | (progn | ||
| 837 | (set-buffer buffer) | ||
| 838 | (or (= (point) (point-max)) | ||
| 839 | (setq opoint (point))) | ||
| 840 | (goto-char (point-max)) | ||
| 841 | (insert-before-markers string)) | ||
| 842 | ;; insert-before-markers moved this marker: set it back. | ||
| 843 | (set-window-start window pos) | ||
| 844 | ;; Finish our save-excursion. | ||
| 845 | (if opoint | ||
| 846 | (goto-char opoint)) | ||
| 847 | (set-buffer obuf)))) | ||
| 848 | 820 | ||
| 849 | (defun shell-command-on-region (start end command | 821 | (defun shell-command-on-region (start end command |
| 850 | &optional output-buffer replace) | 822 | &optional output-buffer replace) |
| @@ -2588,6 +2560,20 @@ in the mode line." | |||
| 2588 | (> (prefix-numeric-value arg) 0))) | 2560 | (> (prefix-numeric-value arg) 0))) |
| 2589 | (force-mode-line-update)) | 2561 | (force-mode-line-update)) |
| 2590 | 2562 | ||
| 2563 | (defvar column-number-mode nil | ||
| 2564 | "*Non-nil means display column number in mode line.") | ||
| 2565 | |||
| 2566 | (defun column-number-mode (arg) | ||
| 2567 | "Toggle Column Number mode. | ||
| 2568 | With arg, turn Column Number mode on iff arg is positive. | ||
| 2569 | When Column Number mode is enabled, the column number appears | ||
| 2570 | in the mode line." | ||
| 2571 | (interactive "P") | ||
| 2572 | (setq column-number-mode | ||
| 2573 | (if (null arg) (not column-number-mode) | ||
| 2574 | (> (prefix-numeric-value arg) 0))) | ||
| 2575 | (force-mode-line-update)) | ||
| 2576 | |||
| 2591 | (defvar blink-matching-paren t | 2577 | (defvar blink-matching-paren t |
| 2592 | "*Non-nil means show matching open-paren when close-paren is inserted.") | 2578 | "*Non-nil means show matching open-paren when close-paren is inserted.") |
| 2593 | 2579 | ||