branch: externals/consult
commit eae64815fbfa74327dcda9de3cb1b9a725d59b2d
Author: Daniel Mendler <m...@daniel-mendler.de>
Commit: Daniel Mendler <m...@daniel-mendler.de>

    consult-compile: Add g narrow key for grep locations
    
    I find it a little inconvenient that grep and compile errors are treated the
    same way. This is a result of grep-mode deriving from compilation-mode.
    Therefore provide at least a separate narrow key and group title for the
    completion candidates.
---
 CHANGELOG.org      |  1 +
 README.org         |  4 ++--
 consult-compile.el | 15 +++++++--------
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 2a0ec21387..693931cf6f 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -6,6 +6,7 @@
 
 - ~consult-register-store~: Add =M-b= action to store the buffer in a register.
 - ~consult-compile~: Ignore messages without a location.
+- ~consult-compile~: Introduce key =g= for grep locations.
 
 * Version 2.3 (2025-04-19)
 
diff --git a/README.org b/README.org
index cda9d1bd3f..9860b5ac7c 100644
--- a/README.org
+++ b/README.org
@@ -283,8 +283,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 or grep search result.
+  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.
diff --git a/consult-compile.el b/consult-compile.el
index fba09d4e99..5c73505c16 100644
--- a/consult-compile.el
+++ b/consult-compile.el
@@ -31,7 +31,8 @@
 (defvar consult-compile--history nil)
 
 (defconst consult-compile--narrow
-  '((?e . "Error")
+  '((?g . "Grep")
+    (?e . "Error")
     (?w . "Warning")
     (?i . "Info")))
 
@@ -49,6 +50,7 @@
   "Return alist of errors and positions in BUFFER, a compilation buffer."
   (with-current-buffer buffer
     (let ((candidates)
+          (grep (and (derived-mode-p 'grep-mode) ?g))
           (pos (point-min)))
       (save-excursion
         (while (setq pos (compilation-next-single-property-change pos 
'compilation-message))
@@ -57,10 +59,8 @@
             (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 (or grep (pcase (compilation--message->type 
msg)
+                                             (0 ?i) (1 ?w) (_ ?e)))
                    'consult--candidate (point-marker))
                   candidates))))
       (nreverse candidates))))
@@ -82,9 +82,8 @@
   (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))))))
 
 (defun consult-compile--state ()
   "Like `consult--jump-state', also setting the current compilation error."

Reply via email to