Function: imenu-choose-buffer-index
imenu-choose-buffer-index is a byte-compiled function defined in
imenu.el.gz.
Signature
(imenu-choose-buffer-index &optional PROMPT ALIST)
Documentation
Let the user select from a buffer index and return the chosen index.
If the user originally activated this function with the mouse, a mouse menu is used. Otherwise a completion buffer is used and the user is prompted with PROMPT.
If you call this function with index alist ALIST, then it lets the user select from ALIST.
With no index alist ALIST, it calls imenu--make-index-alist to
create the index alist.
If imenu-use-popup-menu is nil, then the completion buffer
is always used, no matter if the mouse was used or not.
The returned value is of the form (INDEX-NAME . INDEX-POSITION).
Source Code
;; Defined in /usr/src/emacs/lisp/imenu.el.gz
(defun imenu-choose-buffer-index (&optional prompt alist)
"Let the user select from a buffer index and return the chosen index.
If the user originally activated this function with the mouse, a mouse
menu is used. Otherwise a completion buffer is used and the user is
prompted with PROMPT.
If you call this function with index alist ALIST, then it lets the user
select from ALIST.
With no index alist ALIST, it calls `imenu--make-index-alist' to
create the index alist.
If `imenu-use-popup-menu' is nil, then the completion buffer
is always used, no matter if the mouse was used or not.
The returned value is of the form (INDEX-NAME . INDEX-POSITION)."
(let (index-alist
(mouse-triggered (listp last-nonmenu-event))
(result t))
;; If selected by mouse, see to that the window where the mouse is
;; really is selected.
(and mouse-triggered
(not (equal last-nonmenu-event '(menu-bar)))
(let ((window (posn-window (event-start last-nonmenu-event))))
(or (framep window) (null window) (select-window window))))
;; Create a list for this buffer only when needed.
(while (eq result t)
(setq index-alist (if alist alist (imenu--make-index-alist)))
(cond
(imenu-flatten
(setq index-alist (imenu--flatten-index-alist index-alist t)))
((when-let* ((alist (if (eq (car index-alist) imenu--rescan-item)
(cdr index-alist) index-alist))
(name (caar alist)))
(get-text-property 0 'imenu-region name))
;; Change the menu structure by adding ".." to non-leaf nodes
;; only when the first node has Eglot text properties.
(setq index-alist (imenu--parentify-index-alist index-alist))))
(setq result
(if (and imenu-use-popup-menu
(or (eq imenu-use-popup-menu t) mouse-triggered))
(imenu--mouse-menu index-alist last-nonmenu-event)
(imenu--completion-buffer index-alist prompt)))
(and (equal result imenu--rescan-item)
(imenu--cleanup)
(setq result t imenu--index-alist nil)))
result))