- (let* ((menu (imenu--split-menu index-alist
- (or title (buffer-name))))
- position)
- (setq menu (imenu--create-keymap-1 (car menu)
- (if (< 1 (length (cdr menu)))
- (cdr menu)
- (cdr (car (cdr menu))))))
- (setq position (x-popup-menu event menu))
- (cond ((eq position nil)
- position)
- ;; If one call to x-popup-menu handled the nested menus,
- ;; find the result by looking down the menus here.
- ((and (listp position)
- (numberp (car position))
- (stringp (nth (1- (length position)) position)))
- (let ((final menu))
- (while position
- (setq final (assoc (car position) final))
- (setq position (cdr position)))
- (or (string= (car final) (car imenu--rescan-item))
- (cdr (cdr (cdr final))))))
- ;; If x-popup-menu went just one level and found a leaf item,
- ;; return the INDEX-ALIST element for that.
- ((and (consp position)
- (stringp (car position))
- (null (cdr position)))
- (or (string= (car position) (car imenu--rescan-item))
- (assq (car position) index-alist)))
- ;; If x-popup-menu went just one level
- ;; and found a non-leaf item (a submenu),
- ;; recurse to handle the rest.
- ((listp position)
- (imenu--mouse-menu position event
- (if title
- (concat title imenu-level-separator
- (car (rassq position index-alist)))
- (car (rassq position index-alist))))))))
+ (let* ((menu (imenu--split-menu index-alist (or title (buffer-name))))
+ (map (imenu--create-keymap (car menu)
+ (cdr (if (< 1 (length (cdr menu)))
+ menu
+ (car (cdr menu)))))))
+ (popup-menu map event)))