From: Juri Linkov Date: Tue, 3 Aug 2021 08:23:57 +0000 (+0300) Subject: Improve handling of context menus for global, local, minor-mode menus X-Git-Tag: emacs-28.0.90~1470^2~1 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=de5601f0902b05f594bd2254b23032ed4c598f9d;p=emacs.git 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. --- diff --git a/lisp/mouse.el b/lisp/mouse.el index 49191e32ea4..1f5bd8e4a6b 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)