changeset 93889:a22fbbd18c59

* mouse.el (mouse-menu-major-mode-map): New fun extracted from mouse-major-mode-menu. (mouse-menu-bar-map): New fun extracted from mouse-popup-menubar. (mouse-major-mode-menu, mouse-popup-menubar) (mouse-popup-menubar-stuff): Use them. (C-down-mouse-3): Bind to a dynamic map rather than to mouse-popup-menubar-stuff. * bindings.el (mode-line-major-mode-keymap): Bind down-mouse-1 to mouse-menu-major-mode-map rather than to mouse-major-mode-menu.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Wed, 09 Apr 2008 03:53:48 +0000
parents ea7acaabb973
children 5bd4e09f29d0
files lisp/ChangeLog lisp/bindings.el lisp/mouse.el
diffstat 3 files changed, 62 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Wed Apr 09 03:44:27 2008 +0000
+++ b/lisp/ChangeLog	Wed Apr 09 03:53:48 2008 +0000
@@ -1,3 +1,15 @@
+2008-04-09  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* mouse.el (mouse-menu-major-mode-map): New fun extracted from
+	mouse-major-mode-menu.
+	(mouse-menu-bar-map): New fun extracted from mouse-popup-menubar.
+	(mouse-major-mode-menu, mouse-popup-menubar)
+	(mouse-popup-menubar-stuff): Use them.
+	(C-down-mouse-3): Bind to a dynamic map rather than to
+	mouse-popup-menubar-stuff.
+	* bindings.el (mode-line-major-mode-keymap): Bind down-mouse-1
+	to mouse-menu-major-mode-map rather than to mouse-major-mode-menu.
+
 2008-04-09  Dan Nicolaescu  <dann@ics.uci.edu>
 
 	* vc-svn.el (vc-svn-modify-change-comment): Add support for the
--- a/lisp/bindings.el	Wed Apr 09 03:44:27 2008 +0000
+++ b/lisp/bindings.el	Wed Apr 09 03:53:48 2008 +0000
@@ -287,7 +287,9 @@
 
 (defvar mode-line-major-mode-keymap
   (let ((map (make-sparse-keymap)))
-    (define-key map [mode-line down-mouse-1] 'mouse-major-mode-menu)
+    (define-key map [mode-line down-mouse-1]
+      '(menu-item "Menu Bar" ignore
+        :filter (lambda (_) (mouse-menu-major-mode-map))))
     (define-key map [mode-line mouse-2] 'describe-mode)
     (define-key map [mode-line down-mouse-3] mode-line-mode-menu)
     map) "\
@@ -565,12 +567,11 @@
 is okay.  See `mode-line-format'.")
 ;; Don't use purecopy here--some people want to change these strings.
 (setq minor-mode-alist
-      (list
-       (list 'abbrev-mode " Abbrev")
-       '(overwrite-mode overwrite-mode)
-       (list 'auto-fill-function " Fill")
-       ;; not really a minor mode...
-       '(defining-kbd-macro " Def")))
+      '((abbrev-mode " Abbrev")
+        (overwrite-mode overwrite-mode)
+        (auto-fill-function " Fill")
+        ;; not really a minor mode...
+        (defining-kbd-macro " Def")))
 
 ;; These variables are used by autoloadable packages.
 ;; They are defined here so that they do not get overridden
--- a/lisp/mouse.el	Wed Apr 09 03:44:27 2008 +0000
+++ b/lisp/mouse.el	Wed Apr 09 03:53:48 2008 +0000
@@ -181,14 +181,7 @@
   (let ((indicator (car (nth 4 (car (cdr event))))))
     (minor-mode-menu-from-indicator indicator)))
 
-(defun mouse-major-mode-menu (event &optional prefix)
-  "Pop up a mode-specific menu of mouse commands.
-Default to the Edit menu if the major mode doesn't define a menu."
-  ;; Switch to the window clicked on, because otherwise
-  ;; the mode's commands may not make sense.
-  (interactive "@e\nP")
-  ;; Let the mode update its menus first.
-  (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
+(defun mouse-menu-major-mode-map ()
   (let* (;; Keymap from which to inherit; may be null.
 	 (ancestor (mouse-menu-non-singleton
 		    (and (current-local-map)
@@ -202,8 +195,7 @@
 	 uniq)
     (if ancestor
 	(set-keymap-parent newmap ancestor))
-    (popup-menu newmap event prefix)))
-
+    newmap))
 
 (defun mouse-menu-non-singleton (menubar)
   "Given menu keymap,
@@ -218,12 +210,10 @@
             menubar
           (lookup-key menubar (vector (car submap)))))))
 
-(defun mouse-popup-menubar (event prefix)
-  "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
+(defun mouse-menu-bar-map ()
+  "Return a keymap equivalent to the menu bar.
 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 'menu-bar-update-hook)
   (let* ((local-menu (and (current-local-map)
 			  (lookup-key (current-local-map) [menu-bar])))
 	 (global-menu (lookup-key global-map [menu-bar]))
@@ -262,19 +252,42 @@
 			        (cons "Global Menu"
 				      (cdr global-menu)))))
     ;; Supplying the list is faster than making a new map.
-    (popup-menu (append (list global-menu)
-			(if local-menu
-			    (list local-menu))
-			minor-mode-menus)
-		event prefix)))
+    ;; FIXME: We have a problem here: we have to use the global/local/minor
+    ;; so they're displayed in the expected order, but later on in the command
+    ;; loop, they're actually looked up in the opposite order.
+    (apply 'append
+           global-menu
+           local-menu
+           minor-mode-menus)))
+
+(defun mouse-major-mode-menu (event &optional prefix)
+  "Pop up a mode-specific menu of mouse commands.
+Default to the Edit menu if the major mode doesn't define a menu."
+  (interactive "@e\nP")
+  (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
+  (popup-menu (mouse-menu-major-mode-map) event prefix))
+(make-obsolete 'mouse-major-mode-menu 'mouse-menu-major-mode-map)
+
+(defun mouse-popup-menubar (event prefix)
+  "Pop up a menu equivalent to the menu bar for keyboard EVENT with PREFIX.
+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 'menu-bar-update-hook)
+  (popup-menu (mouse-menu-bar-map) event prefix))
+(make-obsolete 'mouse-popup-menubar 'mouse-menu-bar-map)
 
 (defun mouse-popup-menubar-stuff (event prefix)
   "Popup a menu like either `mouse-major-mode-menu' or `mouse-popup-menubar'.
 Use the former if the menu bar is showing, otherwise the latter."
-  (interactive "@e \nP")
-  (if (zerop (assoc-default 'menu-bar-lines (frame-parameters) 'eq 0))
-      (mouse-popup-menubar event prefix)
-    (mouse-major-mode-menu event prefix)))
+  (interactive "@e\nP")
+  (run-hooks 'activate-menubar-hook 'menu-bar-update-hook)
+  (popup-menu
+   (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
+       (mouse-menu-bar-map)
+     (mouse-menu-major-mode-map))
+   event prefix))
+(make-obsolete 'mouse-popup-menubar-stuff nil)
 
 ;; Commands that operate on windows.
 
@@ -2466,7 +2479,12 @@
 (if (not (eq system-type 'ms-dos))
     (global-set-key [S-down-mouse-1] 'mouse-set-font))
 ;; C-down-mouse-2 is bound in facemenu.el.
-(global-set-key [C-down-mouse-3] 'mouse-popup-menubar-stuff)
+(global-set-key [C-down-mouse-3]
+  '(menu-item "Menu Bar" ignore
+    :filter (lambda (_)
+              (if (zerop (or (frame-parameter nil 'menu-bar-lines) 0))
+                  (mouse-menu-bar-map)
+                (mouse-menu-major-mode-map)))))
 
 
 ;; Replaced with dragging mouse-1