;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; 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
(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.