branch: externals/consult commit 1f0ae1ee8b96b7050b3995d2942c5d6b4eaa08f4 Author: Daniel Mendler <m...@daniel-mendler.de> Commit: Daniel Mendler <m...@daniel-mendler.de>
Add new command consult-grep-match consult-compile-error: Stop showing grep matches. --- CHANGELOG.org | 8 ++++++++ README.org | 8 ++++++-- consult-compile.el | 49 ++++++++++++++++++++++++++----------------------- consult.el | 13 +++++++++++++ 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.org b/CHANGELOG.org index 0dab3eb1f5..915d6c23d6 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -2,6 +2,14 @@ #+author: Daniel Mendler #+language: en +* Development + +- New command =consult-grep-match= based on =consult-compile-error=, which shows + Grep matches of related Grep buffers. +- =consult-compile-error=: Exclude Grep matches. Show only compilation errors from + compilation buffers. +- ~consult-compile-error~: Remove =g= narrow key. + * Version 2.7 (2025-08-05) - ~consult-buffer-list-function~: New customizable variable to support frame or diff --git a/README.org b/README.org index f6b30ac78a..040e5a714c 100644 --- a/README.org +++ b/README.org @@ -246,12 +246,15 @@ their descriptions. #+cindex: find #+cindex: locate +#+findex: consult-grep-match #+findex: consult-grep #+findex: consult-ripgrep #+findex: consult-git-grep #+findex: consult-find #+findex: consult-fd #+findex: consult-locate +- =consult-grep-match=: Jump to a Grep match in related Grep buffers. Supports + live preview narrowing and recursive editing. - =consult-grep=, =consult-ripgrep=, =consult-git-grep=: Search for regular expression in files. Consult invokes Grep asynchronously, while you enter the search term. After at least =consult-async-min-input= characters, the search gets @@ -287,8 +290,8 @@ their descriptions. #+findex: consult-compile-error #+findex: consult-flymake #+findex: consult-xref -- =consult-compile-error=: Jump to a compilation error. Supports live preview - narrowing and recursive editing. +- =consult-compile-error=: Jump to a compilation error in related compilation + buffers. Supports live preview narrowing and recursive editing. - =consult-flymake=: Jump to Flymake diagnostic. Supports live preview and recursive editing. The command supports narrowing. Press =e SPC=, =w SPC=, =n SPC= to only show errors, warnings and notes respectively. @@ -795,6 +798,7 @@ configuration examples. ("M-y" . consult-yank-pop) ;; orig. yank-pop ;; M-g bindings in `goto-map' ("M-g e" . consult-compile-error) + ("M-g r" . consult-grep-match) ("M-g f" . consult-flymake) ;; Alternative: consult-flycheck ("M-g g" . consult-goto-line) ;; orig. goto-line ("M-g M-g" . consult-goto-line) ;; orig. goto-line diff --git a/consult-compile.el b/consult-compile.el index 6b1f8aae26..0342261bf8 100644 --- a/consult-compile.el +++ b/consult-compile.el @@ -45,10 +45,11 @@ (setq pos end))) str)) -(defun consult-compile--error-candidates (buffer) +(defun consult-compile--candidates (buffer) "Return alist of errors and positions in BUFFER, a compilation buffer." (with-current-buffer buffer (let ((candidates) + (grep (derived-mode-p 'grep-mode 'grep-edit-mode)) (pos (point-min))) (save-excursion (while (setq pos (compilation-next-single-property-change pos 'compilation-message)) @@ -57,10 +58,9 @@ (goto-char pos) (push (propertize (consult-compile--font-lock (consult--buffer-substring pos (pos-eol))) - 'consult--type (pcase (compilation--message->type msg) - (0 ?i) - (1 ?w) - (_ ?e)) + 'consult--type (and (not grep) + (pcase (compilation--message->type msg) + (0 ?i) (1 ?w) (_ ?e))) 'consult--candidate (point-marker)) candidates)))) (nreverse candidates)))) @@ -77,14 +77,16 @@ (compilation-next-error-function 0) (point-marker))))))) -(defun consult-compile--compilation-buffers (file) - "Return a list of compilation buffers relevant to FILE." +(defun consult-compile--buffers (grep file) + "List of compilation buffers relevant to FILE. +If GREP is non-nil, search Grep buffers." (consult--buffer-query :sort 'alpha :predicate (lambda (buffer) - (with-current-buffer buffer - (and (compilation-buffer-internal-p) - (file-in-directory-p file default-directory)))))) + (and (buffer-local-value 'compilation-locs buffer) + (file-in-directory-p file (buffer-local-value 'default-directory buffer)) + (with-current-buffer buffer + (eq (not grep) (not (derived-mode-p 'grep-mode 'grep-edit-mode)))))))) (defun consult-compile--state () "Like `consult--jump-state', also setting the current compilation error." @@ -100,21 +102,22 @@ (funcall jump action pos))))) ;;;###autoload -(defun consult-compile-error (&optional arg) - "Jump to a compilation error in the current buffer. - -This command collects entries from compilation buffers and grep buffers -related to the current buffer. The command supports preview of the -currently selected error. With prefix ARG, jump to the error message in -the compilation buffer, instead of to the actual location of the error." +(defun consult-compile-error (&optional arg grep) + "Jump to a compilation error related to the current project or file. + +This command collects entries from all related compilation buffers. The +command supports preview of the currently selected error. With prefix +ARG, jump to the error message in the compilation buffer, instead of to +the actual location of the error. If GREP is non-nil, Grep buffers are +searched." (interactive "P") (consult--read - (or (mapcan #'consult-compile--error-candidates - (or (consult-compile--compilation-buffers - default-directory) - (user-error "No compilation buffers found for the current buffer"))) - (user-error "No compilation errors found")) - :prompt "Go to error: " + (or (mapcan #'consult-compile--candidates + (or (consult-compile--buffers + grep (or (consult--project-root) default-directory)) + (user-error "No related buffers"))) + (user-error "No %s" (if grep "matches" "errors"))) + :prompt (format "Go to %s: " (if grep "match" "error")) :category 'consult-compile-error :sort nil :require-match t diff --git a/consult.el b/consult.el index 2723a9e3ce..64974ede69 100644 --- a/consult.el +++ b/consult.el @@ -5230,6 +5230,19 @@ input." opts paths) hl)))))))) +(autoload 'consult-compile-error "consult-compile") + +;;;###autoload +(defun consult-grep-match (&optional arg) + "Jump to grep matches related to the current project or file. + +This command collects entries from all related Grep buffers. The +command supports preview of the currently selected match. With prefix +ARG, jump to the match in the Grep buffer, instead of to the actual +location of the match." + (interactive "P") + (consult-compile-error arg t)) + ;;;###autoload (defun consult-grep (&optional dir initial) "Search with `grep' for files in DIR where the content matches a regexp.