From: Juri Linkov Date: Thu, 21 Oct 2021 16:55:24 +0000 (+0300) Subject: * lisp/menu-bar.el (menu-bar-keymap): Add optional arg KEYMAP (bug#50067). X-Git-Tag: emacs-28.0.90~226 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1cdb4d2077c4e402bf2b2991e8395f0ccdedd1d1;p=emacs.git * lisp/menu-bar.el (menu-bar-keymap): Add optional arg KEYMAP (bug#50067). * lisp/mouse.el (context-menu-global): Use 'menu-bar-keymap' with its arg KEYMAP set to 'global-map'. --- diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index 1cc126b5017..f19dc9e7c97 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -2696,10 +2696,13 @@ This command is to be used when you click the mouse in the menubar." (cdr menu-bar-item-cons) 0)))) -(defun menu-bar-keymap () +(defun menu-bar-keymap (&optional keymap) "Return the current menu-bar keymap. +The ordering of the return value respects `menu-bar-final-items'. -The ordering of the return value respects `menu-bar-final-items'." +It's possible to use the KEYMAP argument to override the default keymap +that is the currently active maps. For example, the argument KEYMAP +could provide `global-map' where items are limited to the global map only." (let ((menu-bar '()) (menu-end '())) (map-keymap @@ -2712,7 +2715,7 @@ The ordering of the return value respects `menu-bar-final-items'." ;; sorting. (push (cons pos menu-item) menu-end) (push menu-item menu-bar)))) - (lookup-key (menu-bar-current-active-maps) [menu-bar])) + (lookup-key (or keymap (menu-bar-current-active-maps)) [menu-bar])) `(keymap ,@(nreverse menu-bar) ,@(mapcar #'cdr (sort menu-end (lambda (a b) diff --git a/lisp/mouse.el b/lisp/mouse.el index bcb58d153a8..7bac6dd07bf 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -364,7 +364,7 @@ Some context functions add menu items below the separator." (when (consp binding) (define-key-after menu (vector key) (copy-sequence binding)))) - (lookup-key global-map [menu-bar])) + (menu-bar-keymap global-map)) menu) (defun context-menu-local (menu _click)