]> git.eshelyaron.com Git - emacs.git/commitdiff
Improve menu-bar-item-at-x
authorGerd Möllmann <gerd.moellmann@gmail.com>
Tue, 25 Feb 2025 08:23:58 +0000 (09:23 +0100)
committerEshel Yaron <me@eshelyaron.com>
Wed, 26 Feb 2025 09:38:16 +0000 (10:38 +0100)
* 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

index 6826842a1083c19ecc7d980bbbff98a6aafc874a..756487a9e499c68b264242d1904347e571b14326 100644 (file)
@@ -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)