]> git.eshelyaron.com Git - emacs.git/commitdiff
Optionally group imenu completions when flattened
authorEshel Yaron <me@eshelyaron.com>
Sun, 14 Jul 2024 10:14:33 +0000 (12:14 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sun, 14 Jul 2024 10:14:33 +0000 (12:14 +0200)
lisp/imenu.el

index 18e5ed9e50dccd20a2572bed025d38193426817a..9f51e95bd87efede508a3dfb022a237ce0aac0d3 100644 (file)
@@ -741,12 +741,18 @@ Return one of the entries in index-alist or nil."
     ;; Display the completion buffer.
     (minibuffer-with-setup-hook
         (lambda ()
-          (setq-local completion-extra-properties '(:category imenu))
+          (setq-local
+           completion-extra-properties
+           `( :category imenu
+              ,@(and imenu-flatten
+                     completions-group
+                     `(:group-function
+                       ,(lambda (s transform)
+                          (get-text-property
+                           0 (if transform 'imenu-base-name 'imenu-section) s))))))
           (when imenu-eager-completion-buffer (minibuffer-completion-help)))
-      (setq name (completing-read prompt
-                                 prepared-index-alist
-                                 nil t nil 'imenu--history name)))
-
+      (setq name (completing-read prompt prepared-index-alist
+                                  nil t nil 'imenu--history name)))
     (when (stringp name)
       (progn
        (setq choice (assoc name prepared-index-alist))
@@ -785,7 +791,10 @@ Returns t for rescan and otherwise an element or subelement of INDEX-ALIST."
                               name))))
        (cond
        ((not (imenu--subalist-p item))
-        (list (cons new-prefix pos)))
+         `((,(propertize (or new-prefix name)
+                         'imenu-section (or prefix "*")
+                         'imenu-base-name name)
+            . ,pos)))
        (t
         (imenu--flatten-index-alist pos concat-names new-prefix)))))
    index-alist))