emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/lisp/emacs-lisp/easymenu.el,v


From: Stefan Monnier
Subject: [Emacs-diffs] Changes to emacs/lisp/emacs-lisp/easymenu.el,v
Date: Tue, 15 Jan 2008 22:33:09 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     Stefan Monnier <monnier>        08/01/15 22:33:08

Index: emacs-lisp/easymenu.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/emacs-lisp/easymenu.el,v
retrieving revision 1.88
retrieving revision 1.89
diff -u -b -r1.88 -r1.89
--- emacs-lisp/easymenu.el      8 Jan 2008 20:45:34 -0000       1.88
+++ emacs-lisp/easymenu.el      15 Jan 2008 22:33:05 -0000      1.89
@@ -216,12 +216,18 @@
    (setq menu (cdr (easy-menu-convert-item menu)))))
  menu)
 
+(defvar easy-menu-avoid-duplicate-keys t
+  "Dynamically scoped var to register already used keys in a menu.
+If it holds a list, this is expected to be a list of keys already seen in the
+menu we're processing.  Else it means we're not processing a menu.")
+
 ;;;###autoload
 (defun easy-menu-create-menu (menu-name menu-items)
   "Create a menu called MENU-NAME with items described in MENU-ITEMS.
 MENU-NAME is a string, the name of the menu.  MENU-ITEMS is a list of items
 possibly preceded by keyword pairs as described in `easy-menu-define'."
   (let ((menu (make-sparse-keymap menu-name))
+        (easy-menu-avoid-duplicate-keys nil)
        prop keyword arg label enable filter visible help)
     ;; Look for keywords.
     (while (and menu-items
@@ -371,12 +377,27 @@
     ;; `intern' the name so as to merge multiple entries with the same name.
     ;; It also makes it easier/possible to lookup/change menu bindings
     ;; via keymap functions.
-    (cons (easy-menu-intern name)
+    (let ((key (easy-menu-intern name)))
+      (when (listp easy-menu-avoid-duplicate-keys)
+        ;; Merging multiple entries with the same name is sometimes what we
+        ;; want, but not when the entries are actually different (e.g. same
+        ;; name but different :suffix as seen in cal-menu.el) and appear in
+        ;; the same menu.  So we try to detect and resolve conflicts.
+        (while (and (stringp name)
+                    (memq key easy-menu-avoid-duplicate-keys))
+          ;; We need to use some distinct object, ideally a symbol, ideally
+          ;; related to the `name'.  Uninterned symbols do not work (they
+          ;; are apparently turned into strings and re-interned later on).
+          (setq key (intern (format "%s (%d)" (symbol-name key)
+                                    (length easy-menu-avoid-duplicate-keys)))))
+        (push key easy-menu-avoid-duplicate-keys))
+
+      (cons key
          (and (not remove)
               (cons 'menu-item
                     (cons label
                           (and name
-                               (cons command prop))))))))
+                                  (cons command prop)))))))))
 
 (defun easy-menu-define-key (menu key item &optional before)
   "Add binding in MENU for KEY => ITEM.  Similar to `define-key-after'.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]