diff options
| -rw-r--r-- | lisp/progmodes/compile.el | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index 9114266570e..53237cafb13 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el | |||
| @@ -553,10 +553,28 @@ While grep runs asynchronously, you can use the \\[next-error] command | |||
| 553 | to find the text that grep hits refer to. | 553 | to find the text that grep hits refer to. |
| 554 | 554 | ||
| 555 | This command uses a special history list for its arguments, so you can | 555 | This command uses a special history list for its arguments, so you can |
| 556 | easily repeat a grep command." | 556 | easily repeat a grep command. |
| 557 | |||
| 558 | A prefix argument says to default the argument based upon the current | ||
| 559 | tag the cursor is over." | ||
| 557 | (interactive | 560 | (interactive |
| 558 | (list (read-from-minibuffer "Run grep (like this): " | 561 | (let (grep-default) |
| 559 | grep-command nil nil 'grep-history))) | 562 | (when (and current-prefix-arg grep-history) |
| 563 | (let* ((tag-default | ||
| 564 | (funcall (or find-tag-default-function | ||
| 565 | (get major-mode 'find-tag-default-function) | ||
| 566 | ;; We use grep-tag-default instead of | ||
| 567 | ;; find-tag-default, to avoid loading etags. | ||
| 568 | 'grep-tag-default)))) | ||
| 569 | (setq grep-default (car grep-history)) | ||
| 570 | ;; Replace the thing matching for with that around cursor | ||
| 571 | (if (string-match "[^ ]+\\s +\\(-[^ ]+\\)*\\s *\\(\"[^\"]+\"\\|[^ ]+\\)" grep-default) | ||
| 572 | (setq grep-default (replace-match tag-default t t | ||
| 573 | grep-default 2))))) | ||
| 574 | (list (read-from-minibuffer "Run grep (like this): " | ||
| 575 | (or grep-default grep-command) | ||
| 576 | nil nil 'grep-history)))) | ||
| 577 | |||
| 560 | ;; Setting process-setup-function makes exit-message-function work | 578 | ;; Setting process-setup-function makes exit-message-function work |
| 561 | ;; even when async processes aren't supported. | 579 | ;; even when async processes aren't supported. |
| 562 | (let* ((compilation-process-setup-function 'grep-process-setup) | 580 | (let* ((compilation-process-setup-function 'grep-process-setup) |
| @@ -567,6 +585,23 @@ easily repeat a grep command." | |||
| 567 | ;; Give it a simpler regexp to match. | 585 | ;; Give it a simpler regexp to match. |
| 568 | nil grep-regexp-alist))))) | 586 | nil grep-regexp-alist))))) |
| 569 | 587 | ||
| 588 | ;; This is a copy of find-tag-default from etags.el. | ||
| 589 | (defun grep-tag-default () | ||
| 590 | (save-excursion | ||
| 591 | (while (looking-at "\\sw\\|\\s_") | ||
| 592 | (forward-char 1)) | ||
| 593 | (when (or (re-search-backward "\\sw\\|\\s_" | ||
| 594 | (save-excursion (beginning-of-line) (point)) | ||
| 595 | t) | ||
| 596 | (re-search-forward "\\(\\sw\\|\\s_\\)+" | ||
| 597 | (save-excursion (end-of-line) (point)) | ||
| 598 | t)) | ||
| 599 | (goto-char (match-end 0)) | ||
| 600 | (buffer-substring (point) | ||
| 601 | (progn (forward-sexp -1) | ||
| 602 | (while (looking-at "\\s'") | ||
| 603 | (forward-char 1)) | ||
| 604 | (point)))))) | ||
| 570 | 605 | ||
| 571 | ;;;###autoload | 606 | ;;;###autoload |
| 572 | (defun grep-find (command-args) | 607 | (defun grep-find (command-args) |