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

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

[elpa] externals/embark 7a2487f5bb: TOC = imenu items in prog mode buffe


From: ELPA Syncer
Subject: [elpa] externals/embark 7a2487f5bb: TOC = imenu items in prog mode buffers, else outline headings
Date: Mon, 2 May 2022 01:57:32 -0400 (EDT)

branch: externals/embark
commit 7a2487f5bb8a6ea5a9b5048386d6dcbbc1b6cc85
Author: Omar Antolín <omar.antolin@gmail.com>
Commit: Omar Antolín <omar.antolin@gmail.com>

    TOC = imenu items in prog mode buffers, else outline headings
    
    Also, add the nice consult-imenu group-function to imenu TOCs now that
    Embark collect has group-function support.
---
 embark-consult.el | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/embark-consult.el b/embark-consult.el
index 263b543cd8..503da3e93f 100644
--- a/embark-consult.el
+++ b/embark-consult.el
@@ -372,8 +372,39 @@ for any action that is a Consult async command."
   "Collect all imenu items in the current buffer."
   (cons 'imenu (mapcar #'car (consult-imenu--items))))
 
+(defvar consult-imenu-config)
+(defun embark-consult--imenu-group-function (metadata prop)
+  "Return a suitable group-function for imenu METADATA.
+Meant as :after-until advice for `completion-metadata-get'."
+  (when-let (((eq (alist-get 'category metadata) 'imenu))
+             (config (plist-get
+                      (cdr (seq-find (lambda (x) (derived-mode-p (car x)))
+                                     consult-imenu-config))
+                      :types)))
+    ;; taken from consult-imenu
+    (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 (car (alist-get type config))))))))
+
+(defun embark-consult-imenu-or-outline-candidates ()
+  "Collect imenu items in prog modes buffer or outline headings otherwise."
+  (if (derived-mode-p 'prog-mode)
+      (embark-consult-imenu-candidates)
+    (embark-consult-outline-candidates)))
+
+(advice-add 'completion-metadata-get :after-until
+            #'embark-consult--imenu-group-function)
+
 (setf (alist-get 'imenu embark-default-action-overrides) #'consult-imenu)
-(add-to-list 'embark-candidate-collectors #'embark-consult-outline-candidates 
'append)
+
+(add-to-list 'embark-candidate-collectors
+             #'embark-consult-imenu-or-outline-candidates
+             'append)
 
 ;; consult-completing-read-multiple
 



reply via email to

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