From c3cc402b5b5c26af560ee255a59537adf132876a Mon Sep 17 00:00:00 2001 From: Eshel Yaron Date: Mon, 2 Sep 2024 12:40:48 +0200 Subject: [PATCH] ; * lisp/imenu.el: Simplify. --- lisp/imenu.el | 66 ++++++++++++++++----------------------------------- 1 file changed, 21 insertions(+), 45 deletions(-) diff --git a/lisp/imenu.el b/lisp/imenu.el index 271fedbd97c..47fa73bc4ea 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -697,26 +697,12 @@ depending on PATTERNS." ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; See also info-lookup-find-item -(defun imenu-find-default (guess completions) - "Fuzzily find an item based on GUESS inside the alist COMPLETIONS." - (catch 'found - (let ((case-fold-search t)) - (if (assoc guess completions) guess - (dolist (re (list (concat "\\`" (regexp-quote guess) "\\'") - (concat "\\`" (regexp-quote guess)) - (concat (regexp-quote guess) "\\'") - (regexp-quote guess))) - (dolist (x completions) - (if (string-match re (car x)) (throw 'found (car x))))))))) - (defun imenu--completion-buffer (index-alist &optional prompt) "Let the user select from INDEX-ALIST in a completion buffer with PROMPT. Return one of the entries in index-alist or nil." ;; Create a list for this buffer only when needed. - (let ((name (thing-at-point 'symbol)) - choice + (let (choice (prepared-index-alist (if (not imenu-space-replacement) index-alist (mapcar @@ -725,36 +711,26 @@ Return one of the entries in index-alist or nil." (car item)) (cdr item))) index-alist)))) - (when (stringp name) - (setq name (or (imenu-find-default name prepared-index-alist) name))) - (unless prompt - (setq prompt (format-prompt - "Index item" - (and name - (imenu--in-alist name prepared-index-alist) - ;; Default to `name' if it's in the alist. - name)))) - ;; Display the completion buffer. - (minibuffer-with-setup-hook - (lambda () - (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))) - (when (stringp name) - (progn - (setq choice (assoc name prepared-index-alist)) - (if (imenu--subalist-p choice) - (imenu--completion-buffer (cdr choice) prompt) - choice))))) + (unless prompt (setq prompt (format-prompt "Index item" nil))) + (when-let ((name (minibuffer-with-setup-hook + (lambda () + (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 + ;; Display the completion buffer. + (minibuffer-completion-help))) + (completing-read prompt prepared-index-alist nil t nil 'imenu--history)))) + (setq choice (assoc name prepared-index-alist)) + (if (imenu--subalist-p choice) + (imenu--completion-buffer (cdr choice) prompt) + choice)))) (defun imenu--mouse-menu (index-alist event &optional title) "Let the user select from a buffer index from a mouse menu. -- 2.39.5