From 11b8e76f836d22a69ee53b84acaad2c7ddf1bf30 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerd=20M=C3=B6llmann?= Date: Tue, 25 Feb 2025 09:23:58 +0100 Subject: [PATCH] Improve menu-bar-item-at-x * lisp/menu-bar.el (menu-bar-item-at-x): Handle case of duplicate keys in the menu-bar definition. (cherry picked from commit 41837050181a7cc313f1e9951136f4356601fc4a) --- lisp/menu-bar.el | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 6826842a108..756487a9e49 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2901,24 +2901,27 @@ returns nil." (menu-bar (menu-bar-keymap)) prev-key prev-column + keys-seen found) (catch 'done (map-keymap (lambda (key binding) - (when (> column x-position) - (setq found t) - (throw 'done nil)) - (setq prev-key key) - (pcase binding - ((or `(,(and (pred stringp) name) . ,_) ;Simple menu item. - `(menu-item ,name ,_cmd ;Extended menu item. - . ,(and props - (guard (let ((visible - (plist-get props :visible))) - (or (null visible) - (eval visible))))))) - (setq prev-column column - column (+ column (length name) 1))))) + (unless (memq key keys-seen) + (push key keys-seen) + (when (> column x-position) + (setq found t) + (throw 'done nil)) + (setq prev-key key) + (pcase binding + ((or `(,(and (pred stringp) name) . ,_) ;Simple menu item. + `(menu-item ,name ,_cmd ;Extended menu item. + . ,(and props + (guard (let ((visible + (plist-get props :visible))) + (or (null visible) + (eval visible))))))) + (setq prev-column column + column (+ column (length name) 1)))))) menu-bar) ;; Check the last menu item. (when (> column x-position) -- 2.39.5