From 8fba4cff1bd0b953af9e950e872e1eaecff179d7 Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Sun, 19 Feb 2023 16:09:32 +0000 Subject: [PATCH] imenu: Make the test for a single category of map (e.g. "Class") rigorous This fixes bug #61629. * lisp/imenu.el (imenu--mouse-menu): Test (consp (cdadr menu)) to avoid confusion with a single entry for a single function. (imenu-update-menubar): Change the code to match that above. --- lisp/imenu.el | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lisp/imenu.el b/lisp/imenu.el index 25a02004570..fd23a65c7b3 100644 --- a/lisp/imenu.el +++ b/lisp/imenu.el @@ -756,9 +756,11 @@ Returns t for rescan and otherwise an element or subelement of INDEX-ALIST." (setq index-alist (imenu--split-submenus 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))))))) + (cdr (if (and (null (cddr menu)) + (stringp (caadr menu)) + (consp (cdadr menu))) + (cadr menu) + menu))))) (popup-menu map event))) (defun imenu-choose-buffer-index (&optional prompt alist) @@ -854,13 +856,12 @@ A trivial interface to `imenu-add-to-menubar' suitable for use in a hook." (buffer-name))) (menu1 (imenu--create-keymap (car menu) - (cdr (if (or (< 1 (length (cdr menu))) - ;; Have we a non-nested single entry? - (atom (cdadr menu)) - (atom (cadadr menu))) - menu - (car (cdr menu)))) - 'imenu--menubar-select))) + (cdr (if (and (null (cddr menu)) + (stringp (caadr menu)) + (consp (cdadr menu))) + (cadr menu) + menu)) + 'imenu--menubar-select))) (setcdr imenu--menubar-keymap (cdr menu1))))))) (defun imenu--menubar-select (item) -- 2.39.2