diff options
| author | Lars Magne Ingebrigtsen | 2016-04-03 19:46:50 +0200 |
|---|---|---|
| committer | Lars Magne Ingebrigtsen | 2016-04-03 19:46:58 +0200 |
| commit | a32eea60ac90d367435860fe3a10bf843e6f497c (patch) | |
| tree | af270436d5b55079070f92e51dfa2b2f8b86e8fa /lisp | |
| parent | 1b33cd8e7e5c747afde29e10b5fe192c5a37b67a (diff) | |
| download | emacs-a32eea60ac90d367435860fe3a10bf843e6f497c.tar.gz emacs-a32eea60ac90d367435860fe3a10bf843e6f497c.zip | |
Add `r'/`l' grep command history commands
* doc/emacs/building.texi (Grep Searching): Mention the
`r'/`l' commands.
* lisp/progmodes/grep.el (grep-forward-history): New command.
(grep-backward-history): Ditto.
(grep--save-buffers): New function.
(grep): Use it to record the history.
(grep--command-history, grep--history-inhibit)
(grep--history-place): New internal variables for the grep
history (bug#22627).
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/progmodes/grep.el | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index 2b44b58f245..7ce787e7284 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el | |||
| @@ -271,6 +271,8 @@ See `compilation-error-screen-columns'" | |||
| 271 | (define-key map "{" 'compilation-previous-file) | 271 | (define-key map "{" 'compilation-previous-file) |
| 272 | (define-key map "}" 'compilation-next-file) | 272 | (define-key map "}" 'compilation-next-file) |
| 273 | (define-key map "\t" 'compilation-next-error) | 273 | (define-key map "\t" 'compilation-next-error) |
| 274 | (define-key map "r" 'grep-forward-history) | ||
| 275 | (define-key map "l" 'grep-backward-history) | ||
| 274 | (define-key map [backtab] 'compilation-previous-error) | 276 | (define-key map [backtab] 'compilation-previous-error) |
| 275 | 277 | ||
| 276 | ;; Set up the menu-bar | 278 | ;; Set up the menu-bar |
| @@ -309,6 +311,12 @@ See `compilation-error-screen-columns'" | |||
| 309 | (define-key map [menu-bar grep compilation-next-error] | 311 | (define-key map [menu-bar grep compilation-next-error] |
| 310 | '(menu-item "Next Match" next-error | 312 | '(menu-item "Next Match" next-error |
| 311 | :help "Visit the next match and corresponding location")) | 313 | :help "Visit the next match and corresponding location")) |
| 314 | (define-key map [menu-bar grep grep-backward-history] | ||
| 315 | '(menu-item "Previous Command" grep-backward-history | ||
| 316 | :help "Run the previous grep command from the command history")) | ||
| 317 | (define-key map [menu-bar grep grep-forward-history] | ||
| 318 | '(menu-item "Next Command" grep-forward-history | ||
| 319 | :help "Run the next grep command from the command history")) | ||
| 312 | map) | 320 | map) |
| 313 | "Keymap for grep buffers. | 321 | "Keymap for grep buffers. |
| 314 | `compilation-minor-mode-map' is a cdr of this.") | 322 | `compilation-minor-mode-map' is a cdr of this.") |
| @@ -744,6 +752,43 @@ This function is called from `compilation-filter-hook'." | |||
| 744 | grep-error-screen-columns) | 752 | grep-error-screen-columns) |
| 745 | (add-hook 'compilation-filter-hook 'grep-filter nil t)) | 753 | (add-hook 'compilation-filter-hook 'grep-filter nil t)) |
| 746 | 754 | ||
| 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) | ||
| 760 | (unless grep--history-inhibit | ||
| 761 | (push (cons default-directory command) grep--command-history) | ||
| 762 | (setq grep--history-place 0) | ||
| 763 | ;; Don't let the history grow without bounds. | ||
| 764 | (when (> (length grep--command-history) 100) | ||
| 765 | (setcdr (nthcdr 100 grep--command-history) nil)))) | ||
| 766 | |||
| 767 | (defun grep-forward-history () | ||
| 768 | "Go to the next result in the grep command history. | ||
| 769 | Also see `grep-backward-history'." | ||
| 770 | (interactive) | ||
| 771 | (let ((elem (and (> grep--history-place 0) | ||
| 772 | (nth (1- grep--history-place) grep--command-history))) | ||
| 773 | (grep--history-inhibit t)) | ||
| 774 | (unless elem | ||
| 775 | (error "Nothing further in the command history")) | ||
| 776 | (cl-decf grep--history-place) | ||
| 777 | (let ((default-directory (car elem))) | ||
| 778 | (grep (cdr elem))))) | ||
| 779 | |||
| 780 | (defun grep-backward-history () | ||
| 781 | "Go to the previous result in the grep command history. | ||
| 782 | Also see `grep-forward-history'." | ||
| 783 | (interactive) | ||
| 784 | (let ((elem (nth (1+ grep--history-place) grep--command-history)) | ||
| 785 | (grep--history-inhibit t)) | ||
| 786 | (unless elem | ||
| 787 | (error "Nothing further in the command history")) | ||
| 788 | (cl-incf grep--history-place) | ||
| 789 | (let ((default-directory (car elem))) | ||
| 790 | (grep (cdr elem))))) | ||
| 791 | |||
| 747 | (defun grep--save-buffers () | 792 | (defun grep--save-buffers () |
| 748 | (when grep-save-buffers | 793 | (when grep-save-buffers |
| 749 | (save-some-buffers (and (not (eq grep-save-buffers 'ask)) | 794 | (save-some-buffers (and (not (eq grep-save-buffers 'ask)) |
| @@ -780,7 +825,7 @@ list is empty)." | |||
| 780 | (if current-prefix-arg default grep-command) | 825 | (if current-prefix-arg default grep-command) |
| 781 | 'grep-history | 826 | 'grep-history |
| 782 | (if current-prefix-arg nil default)))))) | 827 | (if current-prefix-arg nil default)))))) |
| 783 | 828 | (grep--save-history command-args) | |
| 784 | (grep--save-buffers) | 829 | (grep--save-buffers) |
| 785 | ;; Setting process-setup-function makes exit-message-function work | 830 | ;; Setting process-setup-function makes exit-message-function work |
| 786 | ;; even when async processes aren't supported. | 831 | ;; even when async processes aren't supported. |