emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/consult 4ae6862: consult-line-multi/consult-imenu-multi


From: ELPA Syncer
Subject: [elpa] externals/consult 4ae6862: consult-line-multi/consult-imenu-multi: Expose buffer query functionality
Date: Wed, 28 Jul 2021 06:57:08 -0400 (EDT)

branch: externals/consult
commit 4ae68628686b5a35b03aabd0063908763eb71da2
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    consult-line-multi/consult-imenu-multi: Expose buffer query functionality
---
 CHANGELOG.org    |  2 +-
 README.org       |  6 +++---
 consult-imenu.el | 44 ++++++++++++++++++++++++++++----------------
 consult.el       | 23 ++++++++++++++---------
 4 files changed, 46 insertions(+), 29 deletions(-)

diff --git a/CHANGELOG.org b/CHANGELOG.org
index 9b1afd0..ac40ad0 100644
--- a/CHANGELOG.org
+++ b/CHANGELOG.org
@@ -6,7 +6,7 @@
 
 - =consult-mark=, =consult-global-mark=: Add optional marker list argument
 - =consult-completing-read-multiple=: New function
-- Rename =consult-project-imenu= to =consult-imenu-project=
+- Rename =consult-project-imenu= to =consult-imenu-multi=
 - Add =consult-line-multi= to search multiple buffers
 
 * Version 0.9 (2021-06-22)
diff --git a/README.org b/README.org
index cc2ea76..078b8ad 100644
--- a/README.org
+++ b/README.org
@@ -174,7 +174,7 @@ their descriptions.
  #+findex: consult-global-mark
  #+findex: consult-outline
  #+findex: consult-imenu
- #+findex: consult-imenu-project
+ #+findex: consult-imenu-multi
  - =consult-goto-line=: Jump to line number enhanced with live preview.
    This is a drop-in replacement for =goto-line=.
  - =consult-mark=: Jump to a marker in the =mark-ring=. Supports live
@@ -185,7 +185,7 @@ their descriptions.
    to a heading level, live preview and recursive editing.
  - =consult-imenu=: Jump to imenu item in the current buffer. Supports
    live preview, recursive editing and narrowing.
- - =consult-imenu-project=: Jump to imenu item in project buffers, with
+ - =consult-imenu-multi=: Jump to imenu item in project buffers, with
    the same major mode as the current buffer. Supports live preview,
    recursive editing and narrowing. This feature has been inspired by
    [[https://github.com/vspinu/imenu-anywhere][imenu-anywhere]].
@@ -801,7 +801,7 @@ configuration examples.
             ("M-g m" . consult-mark)
             ("M-g k" . consult-global-mark)
             ("M-g i" . consult-imenu)
-            ("M-g I" . consult-imenu-project)
+            ("M-g I" . consult-imenu-multi)
             ;; M-s bindings (search-map)
             ("M-s f" . consult-find)
             ("M-s F" . consult-locate)
diff --git a/consult-imenu.el b/consult-imenu.el
index de53752..518affe 100644
--- a/consult-imenu.el
+++ b/consult-imenu.el
@@ -134,14 +134,24 @@ TYPES is the mode-specific types configuration."
         (puthash (car item) 0 ht)))))
 
 (defun consult-imenu--items ()
-  "Return cached imenu candidates."
+  "Return cached imenu candidates, may error."
   (unless (equal (car consult-imenu--cache) (buffer-modified-tick))
     (setq consult-imenu--cache (cons (buffer-modified-tick) 
(consult-imenu--compute))))
   (cdr consult-imenu--cache))
 
-(defun consult-imenu--all-items (buffers)
-  "Return all imenu items from each BUFFERS."
-  (apply #'append (consult--buffer-map buffers #'consult-imenu--items)))
+(defun consult-imenu--items-safe ()
+  "Return cached imenu candidates, will not error."
+  (condition-case err
+      (consult-imenu--items)
+    (t (message "Cannot create Imenu for buffer %s (%s)"
+                (buffer-name) (error-message-string err))
+       nil)))
+
+(defun consult-imenu--multi-items (query)
+  "Return all imenu items from buffers matching QUERY."
+  (apply #'append (consult--buffer-map
+                   (apply #'consult--buffer-query query)
+                   #'consult-imenu--items-safe)))
 
 (defun consult-imenu--jump (item)
   "Jump to imenu ITEM via `consult--jump'.
@@ -204,27 +214,29 @@ See also `consult-imenu-project'."
   (consult-imenu--select "Go to item: " (consult-imenu--items)))
 
 ;;;###autoload
-(defun consult-imenu-project ()
+(defun consult-imenu-multi (&optional query)
   "Select item from the imenus of all buffers from the same project.
 
 In order to determine the buffers belonging to the same project, the
 `consult-project-root-function' is used. Only the buffers with the
 same major mode as the current buffer are used. See also
-`consult-imenu' for more details."
+`consult-imenu' for more details. In order to search a subset of filters,
+QUERY can be set to a plist according to `consult--buffer-query'."
   (interactive)
-  (if-let* ((project (consult--project-root))
-            (buffers (consult--buffer-query :directory project
-                                            :mode major-mode
-                                            :sort 'alpha)))
-      (consult-imenu--select
-       (format "Go to item (Project %s): "
-               (consult--project-name project))
-       (consult-imenu--all-items buffers))
-    (consult-imenu)))
+  (let ((scope "Multiple buffers"))
+    (when-let (project (and (not (keywordp (car-safe query)))
+                            (consult--project-root)))
+      (setq scope (format "Project %s" (consult--project-name project))
+            query `(:directory ,project :mode ,major-mode :sort alpha)))
+    (if query
+        (consult-imenu--select
+         (format "Go to item (%s): " scope)
+         (consult-imenu--multi-items query))
+      (consult-imenu))))
 
 (define-obsolete-function-alias
   'consult-project-imenu
-  'consult-imenu-project
+  'consult-imenu-multi
   "0.9")
 
 (provide 'consult-imenu)
diff --git a/consult.el b/consult.el
index 28d841a..e9bb348 100644
--- a/consult.el
+++ b/consult.el
@@ -2658,7 +2658,7 @@ changed if the START prefix argument is set. The symbol 
at point and the last
      :prompt (if top "Go to line from top: " "Go to line: ")
      :initial initial)))
 
-(defun consult--line-multi-candidates (&rest query)
+(defun consult--line-multi-candidates (query)
   "Collect the line candidates from multiple buffers.
 QUERY is passed to `consult--buffer-query'."
   (or (apply #'nconc
@@ -2668,19 +2668,24 @@ QUERY is passed to `consult--buffer-query'."
       (user-error "No lines")))
 
 ;;;###autoload
-(defun consult-line-multi (all &optional initial)
+(defun consult-line-multi (query &optional initial)
   "Search for a matching line in multiple buffers.
 
-By default search across all project buffers. If the prefix argument ALL is
+By default search across all project buffers. If the prefix argument QUERY is
 non-nil, all buffers are searched. Optional INITIAL input can be provided. See
-`consult-line' for more information."
+`consult-line' for more information. In order to search a subset of filters,
+QUERY can be set to a plist according to `consult--buffer-query'."
   (interactive "P")
-  (let ((project (and (not all) (consult--project-root))))
+  (let ((scope "Multiple buffers"))
+    (unless (keywordp (car-safe query))
+      (let ((project (and (not query) (consult--project-root))))
+        (setq query `(:sort alpha :directory ,project)
+              scope (if project
+                        (format "Project %s" (consult--project-name project))
+                      "All buffers"))))
     (consult--line
-     (consult--line-multi-candidates :sort 'alpha :directory project)
-     :prompt (if project
-                 (format "Go to line (Project %s): " (consult--project-name 
project))
-               "Go to line (All buffers): ")
+     (consult--line-multi-candidates query)
+     :prompt (format "Go to line (%s): " scope)
      :initial initial
      :group #'consult--line-group)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]