emacs-diffs
[Top][All Lists]
Advanced

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

feature/context-menu de5601f: Improve handling of context menus for glob


From: Juri Linkov
Subject: feature/context-menu de5601f: Improve handling of context menus for global, local, minor-mode menus
Date: Tue, 3 Aug 2021 04:24:30 -0400 (EDT)

branch: feature/context-menu
commit de5601f0902b05f594bd2254b23032ed4c598f9d
Author: Juri Linkov <juri@linkov.net>
Commit: Juri Linkov <juri@linkov.net>

    Improve handling of context menus for global, local, minor-mode menus
    
    * lisp/mouse.el (context-menu-global, context-menu-local, 
context-menu-minor):
    Better handling of possibly nested menu maps.
---
 lisp/mouse.el | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/lisp/mouse.el b/lisp/mouse.el
index 49191e3..1f5bd8e 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -318,11 +318,9 @@ the same menu with changes such as added new menu items."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-global] menu-bar-separator)
   (dolist (item (lookup-key global-map [menu-bar]))
-    (when (consp item)
+    (when (and (consp item) (consp (cdr item)))
       (define-key-after menu (vector (car item))
-        (if (consp (cdr item))
-            (copy-sequence (cdr item))
-          (cdr item)))))
+        (copy-sequence (cdr item)))))
   menu)
 
 (defun context-menu-local (menu)
@@ -330,11 +328,11 @@ the same menu with changes such as added new menu items."
   (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
   (define-key-after menu [separator-local] menu-bar-separator)
   (dolist (item (local-key-binding [menu-bar]))
-    (when (consp item)
+    (when (and (consp item) (consp (cdr item)))
+      ;; Fix deep menu created by `imenu-add-to-menubar'.
+      (when (eq (car item) 'keymap) (setq item (cadr item)))
       (define-key-after menu (vector (car item))
-        (if (consp (cdr item))
-            (copy-sequence (cdr item))
-          (cdr item)))))
+        (copy-sequence (cdr item)))))
   menu)
 
 (defun context-menu-minor (menu)
@@ -344,11 +342,9 @@ the same menu with changes such as added new menu items."
   (dolist (mode (minor-mode-key-binding [menu-bar]))
     (when (and (consp mode) (symbol-value (car mode)))
       (dolist (item (cdr mode))
-        (when (consp item)
+        (when (and (consp item) (consp (cdr item)))
           (define-key-after menu (vector (car item))
-            (if (consp (cdr item))
-                (copy-sequence (cdr item))
-              (cdr item)))))))
+            (copy-sequence (cdr item)))))))
   menu)
 
 (defun context-menu-vc (menu)



reply via email to

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