From 7636d2a3699d10e87d794d5beb5081712e151bb9 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Mon, 24 Jul 2000 15:19:02 +0000 Subject: [PATCH] (popup-menu): Run the keymap through indirect-function, in case it was defined with define-prefix-key. If the menu is a list of keymaps, look up the binding of user's choice in each one of the keymaps. (mouse-popup-menubar): If the global and local menu-bar keymaps don't have a prompt string, create one and insert it into the keymap. Don't barf if current-local-map returns nil. --- lisp/ChangeLog | 10 ++++++++++ lisp/mouse.el | 44 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bf3159647dc..e97205960ea 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,13 @@ +2000-07-24 Eli Zaretskii + + * mouse.el (popup-menu): Run the keymap through indirect-function, + in case it was defined with define-prefix-key. If the menu is a + list of keymaps, look up the binding of user's choice in each one + of the keymaps. + (mouse-popup-menubar): If the global and local menu-bar keymaps + don't have a prompt string, create one and insert it into the + keymap. Don't barf if current-local-map returns nil. + 2000-07-24 Francis Wright * dired.el (dired-sort-R-check): Added to allow recursive listing diff --git a/lisp/mouse.el b/lisp/mouse.el index b5d3a9dcb9d..ef78aff5a7c 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -60,11 +60,26 @@ PREFIX is the prefix argument (if any) to pass to the command." (if filter (funcall filter (symbol-function map)) map))))) event) ;; The looping behavior was taken from lmenu's popup-menu-popup - (while (and map (setq event (x-popup-menu position map))) + (while (and map (setq event + ;; map could be a prefix key, in which case + ;; we need to get its function cell + ;; definition. + (x-popup-menu position (indirect-function map)))) ;; Strangely x-popup-menu returns a list. ;; mouse-major-mode-menu was using a weird: ;; (key-binding (apply 'vector (append '(menu-bar) menu-prefix events))) - (let ((cmd (lookup-key map (apply 'vector event)))) + (let ((cmd + (if (and (not (keymapp map)) (listp map)) + ;; We were given a list of keymaps. Search them all + ;; in sequence until a first binding is found. + (let ((mouse-click (apply 'vector event)) + binding) + (while (and map (null binding)) + (setq binding (lookup-key (car map) mouse-click)) + (setq map (cdr map))) + binding) + ;; We were given a single keymap. + (lookup-key map (apply 'vector event))))) (setq map nil) ;; Clear out echoing, which perhaps shows a prefix arg. (message "") @@ -145,10 +160,29 @@ The contents are the items that would be in the menu bar whether or not it is actually displayed." (interactive "@e \nP") (run-hooks 'activate-menubar-hook) - (let* ((local-menu (lookup-key (current-local-map) [menu-bar])) - (global-menu (lookup-key global-map [menu-bar]))) + (let* ((local-menu (and (current-local-map) + (lookup-key (current-local-map) [menu-bar]))) + (global-menu (lookup-key global-map [menu-bar])) + (local-title-or-map (and local-menu (cadr local-menu))) + (global-title-or-map (cadr global-menu))) + ;; If the keymaps don't have prompt string (a lazy programmer + ;; didn't bother to provide one), create it and insert it into the + ;; keymaps; each keymap gets its own prompt. This is required for + ;; non-toolkit versions to display non-empty menu pane names. + (or (null local-menu) + (stringp local-title-or-map) + (setq local-menu (cons 'keymap + (cons (concat mode-name " Mode Menu") + (cdr local-menu))))) + (or (stringp global-title-or-map) + (setq global-menu (cons 'keymap + (cons "Global Menu" + (cdr global-menu))))) ;; Supplying the list is faster than making a new map. - (popup-menu (list global-menu local-menu) event prefix))) + (popup-menu (if local-menu + (list global-menu local-menu) + (list global-menu)) + event prefix))) (defun mouse-popup-menubar-stuff (event prefix) "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'. -- 2.39.2