diff options
| -rw-r--r-- | lisp/progmodes/grep.el | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 7ce787e7284..fd55576e135 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el | |||
| @@ -472,9 +472,12 @@ This variable's value takes effect when `grep-compute-defaults' is called.") | |||
| 472 | (defvar grep-files-history nil) | 472 | (defvar grep-files-history nil) |
| 473 | 473 | ||
| 474 | ;;;###autoload | 474 | ;;;###autoload |
| 475 | (defun grep-process-setup () | 475 | (defun grep-process-setup (&optional point) |
| 476 | "Setup compilation variables and buffer for `grep'. | 476 | "Setup compilation variables and buffer for `grep'. |
| 477 | Set up `compilation-exit-message-function' and run `grep-setup-hook'." | 477 | Set up `compilation-exit-message-function' and run |
| 478 | `grep-setup-hook'. If the optional parameter POINT is given, | ||
| 479 | point will be moved to this vicinity when the grep command has | ||
| 480 | finished." | ||
| 478 | (when (eq grep-highlight-matches 'auto-detect) | 481 | (when (eq grep-highlight-matches 'auto-detect) |
| 479 | (grep-compute-defaults)) | 482 | (grep-compute-defaults)) |
| 480 | (unless (or (eq grep-highlight-matches 'auto-detect) | 483 | (unless (or (eq grep-highlight-matches 'auto-detect) |
| @@ -495,12 +498,14 @@ Set up `compilation-exit-message-function' and run `grep-setup-hook'." | |||
| 495 | ;; This relies on the fact that `compilation-start' | 498 | ;; This relies on the fact that `compilation-start' |
| 496 | ;; sets buffer-modified to nil before running the command, | 499 | ;; sets buffer-modified to nil before running the command, |
| 497 | ;; so the buffer is still unmodified if there is no output. | 500 | ;; so the buffer is still unmodified if there is no output. |
| 498 | (cond ((and (zerop code) (buffer-modified-p)) | 501 | (progn |
| 499 | '("finished (matches found)\n" . "matched")) | 502 | (goto-char (min point (point-max))) |
| 500 | ((not (buffer-modified-p)) | 503 | (cond ((and (zerop code) (buffer-modified-p)) |
| 501 | '("finished with no matches found\n" . "no match")) | 504 | '("finished (matches found)\n" . "matched")) |
| 502 | (t | 505 | ((not (buffer-modified-p)) |
| 503 | (cons msg code))) | 506 | '("finished with no matches found\n" . "no match")) |
| 507 | (t | ||
| 508 | (cons msg code)))) | ||
| 504 | (cons msg code)))) | 509 | (cons msg code)))) |
| 505 | (run-hooks 'grep-setup-hook)) | 510 | (run-hooks 'grep-setup-hook)) |
| 506 | 511 | ||
| @@ -732,6 +737,10 @@ This function is called from `compilation-filter-hook'." | |||
| 732 | ;; Now replace the pattern with the default tag. | 737 | ;; Now replace the pattern with the default tag. |
| 733 | (replace-match tag-default t t grep-default 1)))) | 738 | (replace-match tag-default t t grep-default 1)))) |
| 734 | 739 | ||
| 740 | (defvar grep--command-history nil) | ||
| 741 | (defvar grep--history-inhibit nil) | ||
| 742 | (defvar grep--history-place 0) | ||
| 743 | (defvar grep--history-point 0) | ||
| 735 | 744 | ||
| 736 | ;;;###autoload | 745 | ;;;###autoload |
| 737 | (define-compilation-mode grep-mode "Grep" | 746 | (define-compilation-mode grep-mode "Grep" |
| @@ -746,19 +755,19 @@ This function is called from `compilation-filter-hook'." | |||
| 746 | ;; can never match. | 755 | ;; can never match. |
| 747 | (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`")) | 756 | (set (make-local-variable 'compilation-directory-matcher) '("\\`a\\`")) |
| 748 | (set (make-local-variable 'compilation-process-setup-function) | 757 | (set (make-local-variable 'compilation-process-setup-function) |
| 749 | 'grep-process-setup) | 758 | (lambda () |
| 759 | (grep-process-setup grep--history-point))) | ||
| 750 | (set (make-local-variable 'compilation-disable-input) t) | 760 | (set (make-local-variable 'compilation-disable-input) t) |
| 751 | (set (make-local-variable 'compilation-error-screen-columns) | 761 | (set (make-local-variable 'compilation-error-screen-columns) |
| 752 | grep-error-screen-columns) | 762 | grep-error-screen-columns) |
| 753 | (add-hook 'compilation-filter-hook 'grep-filter nil t)) | 763 | (add-hook 'compilation-filter-hook 'grep-filter nil t)) |
| 754 | 764 | ||
| 755 | (defvar grep--command-history nil) | ||
| 756 | (defvar grep--history-inhibit nil) | ||
| 757 | (defvar grep--history-place 0) | ||
| 758 | |||
| 759 | (defun grep--save-history (command) | 765 | (defun grep--save-history (command) |
| 760 | (unless grep--history-inhibit | 766 | (unless grep--history-inhibit |
| 761 | (push (cons default-directory command) grep--command-history) | 767 | (when grep--command-history |
| 768 | (setcar (cdr (car grep--command-history)) (point))) | ||
| 769 | (push (list default-directory 0 command) | ||
| 770 | grep--command-history) | ||
| 762 | (setq grep--history-place 0) | 771 | (setq grep--history-place 0) |
| 763 | ;; Don't let the history grow without bounds. | 772 | ;; Don't let the history grow without bounds. |
| 764 | (when (> (length grep--command-history) 100) | 773 | (when (> (length grep--command-history) 100) |
| @@ -773,9 +782,11 @@ Also see `grep-backward-history'." | |||
| 773 | (grep--history-inhibit t)) | 782 | (grep--history-inhibit t)) |
| 774 | (unless elem | 783 | (unless elem |
| 775 | (error "Nothing further in the command history")) | 784 | (error "Nothing further in the command history")) |
| 785 | (setcar (cdr (nth grep--history-place grep--command-history)) (point)) | ||
| 776 | (cl-decf grep--history-place) | 786 | (cl-decf grep--history-place) |
| 777 | (let ((default-directory (car elem))) | 787 | (let ((default-directory (car elem)) |
| 778 | (grep (cdr elem))))) | 788 | (grep--history-point (nth 1 elem))) |
| 789 | (grep (nth 2 elem))))) | ||
| 779 | 790 | ||
| 780 | (defun grep-backward-history () | 791 | (defun grep-backward-history () |
| 781 | "Go to the previous result in the grep command history. | 792 | "Go to the previous result in the grep command history. |
| @@ -785,9 +796,11 @@ Also see `grep-forward-history'." | |||
| 785 | (grep--history-inhibit t)) | 796 | (grep--history-inhibit t)) |
| 786 | (unless elem | 797 | (unless elem |
| 787 | (error "Nothing further in the command history")) | 798 | (error "Nothing further in the command history")) |
| 799 | (setcar (cdr (nth grep--history-place grep--command-history)) (point)) | ||
| 788 | (cl-incf grep--history-place) | 800 | (cl-incf grep--history-place) |
| 789 | (let ((default-directory (car elem))) | 801 | (let ((default-directory (car elem)) |
| 790 | (grep (cdr elem))))) | 802 | (grep--history-point (nth 1 elem))) |
| 803 | (grep (nth 2 elem))))) | ||
| 791 | 804 | ||
| 792 | (defun grep--save-buffers () | 805 | (defun grep--save-buffers () |
| 793 | (when grep-save-buffers | 806 | (when grep-save-buffers |