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

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

[elpa] externals/consult 87a9499c7b: Extract consult-imenu--group for us


From: ELPA Syncer
Subject: [elpa] externals/consult 87a9499c7b: Extract consult-imenu--group for use in embark-consult
Date: Mon, 2 May 2022 10:57:24 -0400 (EDT)

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

    Extract consult-imenu--group for use in embark-consult
    
    See https://github.com/oantolin/embark/pull/498
    cc @oantolin
---
 consult-imenu.el | 80 +++++++++++++++++++++++++++++---------------------------
 1 file changed, 42 insertions(+), 38 deletions(-)

diff --git a/consult-imenu.el b/consult-imenu.el
index e7878c4b0f..667ae25cd3 100644
--- a/consult-imenu.el
+++ b/consult-imenu.el
@@ -153,7 +153,6 @@ TYPES is the mode-specific types configuration."
 
 (defun consult-imenu--jump (item)
   "Jump to imenu ITEM via `consult--jump'.
-
 In contrast to the builtin `imenu' jump function,
 this function can jump across buffers."
   (pcase item
@@ -161,45 +160,50 @@ this function can jump across buffers."
     (`(,_ . ,pos) (consult--jump pos))
     (_ (error "Unknown imenu item: %S" item))))
 
+(defun consult-imenu--narrow ()
+  "Return narrowing configuration for the current buffer."
+  (mapcar (lambda (x) (cons (car x) (cadr x)))
+          (plist-get (cdr (seq-find (lambda (x) (derived-mode-p (car x)))
+                                    consult-imenu-config))
+                     :types)))
+
+(defun consult-imenu--group ()
+  "Create a imenu group function for the current buffer."
+  (when-let (narrow (consult-imenu--narrow))
+    (lambda (cand transform)
+      (let ((type (get-text-property 0 'consult--type cand)))
+        (cond
+         ((and transform type)
+          (substring cand (1+ (next-single-property-change 0 'consult--type 
cand))))
+         (transform cand)
+         (type (alist-get type narrow)))))))
+
 (defun consult-imenu--select (prompt items)
   "Select from imenu ITEMS given PROMPT string."
-  (let ((narrow
-         (mapcar (lambda (x) (cons (car x) (cadr x)))
-                 (plist-get (cdr (seq-find (lambda (x) (derived-mode-p (car 
x)))
-                                           consult-imenu-config))
-                            :types))))
-    (consult-imenu--deduplicate items)
-    (consult-imenu--jump
-     (consult--read
-      (or items (user-error "Imenu is empty"))
-      :prompt prompt
-      :state
-      (let ((preview (consult--jump-preview)))
-        (lambda (action cand)
-          ;; Only preview simple menu items which are markers,
-          ;; in order to avoid any bad side effects.
-          (funcall preview action (and (markerp (cdr cand)) (cdr cand)))))
-      :require-match t
-      :group
-      (when narrow
-        (lambda (cand transform)
-          (let ((type (get-text-property 0 'consult--type cand)))
-            (cond
-             ((and transform type)
-              (substring cand (1+ (next-single-property-change 0 
'consult--type cand))))
-             (transform cand)
-             (type (alist-get type narrow))))))
-      :narrow
-      (when narrow
-        (list :predicate
-              (lambda (cand)
-                (eq (get-text-property 0 'consult--type (car cand)) 
consult--narrow))
-              :keys narrow))
-      :category 'imenu
-      :lookup #'consult--lookup-cons
-      :history 'consult-imenu--history
-      :add-history (thing-at-point 'symbol)
-      :sort nil))))
+  (consult-imenu--deduplicate items)
+  (consult-imenu--jump
+   (consult--read
+    (or items (user-error "Imenu is empty"))
+    :state
+    (let ((preview (consult--jump-preview)))
+      (lambda (action cand)
+        ;; Only preview simple menu items which are markers,
+        ;; in order to avoid any bad side effects.
+        (funcall preview action (and (markerp (cdr cand)) (cdr cand)))))
+    :narrow
+    (when-let (narrow (consult-imenu--narrow))
+      (list :predicate
+            (lambda (cand)
+              (eq (get-text-property 0 'consult--type (car cand)) 
consult--narrow))
+            :keys narrow))
+    :group (consult-imenu--group)
+    :prompt prompt
+    :require-match t
+    :category 'imenu
+    :lookup #'consult--lookup-cons
+    :history 'consult-imenu--history
+    :add-history (thing-at-point 'symbol)
+    :sort nil)))
 
 ;;;###autoload
 (defun consult-imenu ()



reply via email to

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