changeset 30421:544a9b8ebb8d

(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.
author Eli Zaretskii <eliz@gnu.org>
date Mon, 24 Jul 2000 15:16:29 +0000
parents 3ed29d254c6c
children 9561d1a7e032
files lisp/mouse.el
diffstat 1 files changed, 39 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mouse.el	Mon Jul 24 15:11:52 2000 +0000
+++ b/lisp/mouse.el	Mon Jul 24 15:16:29 2000 +0000
@@ -60,11 +60,26 @@
 		  (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 @@
 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'.