From de5601f0902b05f594bd2254b23032ed4c598f9d Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 3 Aug 2021 11:23:57 +0300 Subject: [PATCH] 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 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) -- 2.39.2