From: Gerd Möllmann Date: Tue, 25 Feb 2025 08:23:58 +0000 (+0100) Subject: Improve menu-bar-item-at-x X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=11b8e76f836d22a69ee53b84acaad2c7ddf1bf30;p=emacs.git 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) --- 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)