]> git.eshelyaron.com Git - emacs.git/commitdiff
; * lisp/imenu.el: Simplify.
authorEshel Yaron <me@eshelyaron.com>
Mon, 2 Sep 2024 10:40:48 +0000 (12:40 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 4 Sep 2024 07:51:36 +0000 (09:51 +0200)
lisp/imenu.el

index 271fedbd97c40fffb591b3faded5ce06446abd00..47fa73bc4eadbfd658a868761ba3b96f2585ecb4 100644 (file)
@@ -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.