From: Eshel Yaron Date: Sun, 14 Jul 2024 10:14:33 +0000 (+0200) Subject: Optionally group imenu completions when flattened X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=322b9c0af9548d3973d50f72d463ac28b4f70367;p=emacs.git Optionally group imenu completions when flattened --- diff --git a/lisp/imenu.el b/lisp/imenu.el index 18e5ed9e50d..9f51e95bd87 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -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))