- (if imenu-use-keymap-menu
- (progn
- (cond
- ((and (listp position)
- (numberp (car position))
- (stringp (nth (1- (length position)) position)))
- (setq position (nth (1- (length position)) position)))
- ((and (stringp (car position))
- (null (cdr position)))
- (setq position (car position))))))
- (cond
- ((eq position nil)
- position)
- ((listp position)
- (imenu--mouse-menu position event
- (if title
- (concat title imenu-level-separator
- (car (rassq position index-alist)))
- (car (rassq position index-alist)))))
- ((stringp position)
- (or (string= position (car imenu--rescan-item))
- (imenu--in-alist position index-alist)))
- ((or (= position (cdr imenu--rescan-item))
- (and (stringp position)
- (string= position (car imenu--rescan-item))))
- t)
- (t
- (rassq position index-alist)))))
+ (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))))))))