From 00ac01aa8f11b6cd7e55a07f69f8807c12871fc4 Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Tue, 25 Feb 2025 20:54:42 +0100 Subject: [PATCH] Improve imenu indexing in ELisp mode --- lisp/progmodes/elisp-mode.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/elisp-mode.el b/lisp/progmodes/elisp-mode.el index a86683be2a5..bce12f35765 100644 --- a/lisp/progmodes/elisp-mode.el +++ b/lisp/progmodes/elisp-mode.el @@ -658,7 +658,7 @@ be used instead. #'elisp-flymake-byte-compile nil t) (add-hook 'refactor-backend-functions #'elisp-refactor-backend nil t) (add-hook 'context-menu-functions #'elisp-context-menu 10 t) - (setq-local imenu-create-index-function #'elisp-create-index) + (setq-local imenu-create-index-function #'elisp-create-imenu-index) (alist-set "compf" prettify-symbols-alist ?∘ #'equal)) ;; Font-locking support. @@ -2590,6 +2590,25 @@ of TARGET." (let ((bounds (bounds-of-thing-at-point 'symbol))) (delete-region (car bounds) (cdr bounds)))) +(defun elisp-create-imenu-index () + (goto-char (point-min)) + (let (index) + (condition-case nil + (while t + (scope (lambda (type beg len &rest _) + (cl-case type + ((defun) + (push (cons (buffer-substring-no-properties beg (+ beg len)) beg) + (alist-get "Function" index nil nil #'string=))) + ((defvar) + (push (cons (buffer-substring-no-properties beg (+ beg len)) beg) + (alist-get "Var" index nil nil #'string=))) + ((defface) + (push (cons (buffer-substring-no-properties beg (+ beg len)) beg) + (alist-get "Face" index nil nil #'string=))))))) + (end-of-file + (dolist (group index) (setcdr group (nreverse (cdr group)))) + index)))) (put 'read-symbol-shorthands 'safe-local-variable #'consp) -- 2.39.5