summaryrefslogtreecommitdiff
path: root/lisp/mouse.el
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-10-12 09:27:49 +0000
committerRichard M. Stallman <rms@gnu.org>1994-10-12 09:27:49 +0000
commit95132d1c301e0eca501c4a3db9bed7cede74b81c (patch)
treee9c4d4ac8197c21930339c44983d165b974c6dde /lisp/mouse.el
parentb89e11349827c475994ce738fbd70674d6ab46a5 (diff)
downloademacs-95132d1c301e0eca501c4a3db9bed7cede74b81c.tar.gz
(mouse-major-mode-menu): Use minor-mode-map-alist
instead of overriding-local-map. Display equiv keys using mouse-major-mode-menu-compute-equiv-keys. (mouse-major-mode-menu-compute-equiv-keys): New function. (mouse-major-mode-menu): New function, on C-mouse-3. (mouse-major-mode-menu-1): New function (mouse-set-font): Move it to C-mouse-2.
Diffstat (limited to 'lisp/mouse.el')
-rw-r--r--lisp/mouse.el61
1 files changed, 59 insertions, 2 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el
index 7ae15deb57f..689707f2cc1 100644
--- a/lisp/mouse.el
+++ b/lisp/mouse.el
@@ -39,6 +39,61 @@
(defvar mouse-yank-at-point nil
"*If non-nil, mouse yank commands yank at point instead of at click.")
+;; Provide a mode-specific menu on a mouse button.
+
+(defun mouse-major-mode-menu (event)
+ "Pop up a mode-specific menu of mouse commands."
+ ;; Switch to the window clicked on, because otherwise
+ ;; the mode's commands may not make sense.
+ (interactive "@e")
+ (let ((newmap (make-sparse-keymap))
+ (unread-command-events (list event)))
+ ;; Make a keymap in which our last command leads to a menu
+ (define-key newmap (vector (car event))
+ (nconc (make-sparse-keymap "Menu")
+ (mouse-major-mode-menu-1
+ (lookup-key (current-local-map) [menu-bar]))))
+ (mouse-major-mode-menu-compute-equiv-keys newmap)
+ (command-execute
+ ;; Make NEWMAP override the usual definition
+ ;; of the mouse button that got us here.
+ ;; Then read the user's menu choice.
+ (let ((minor-mode-map-alist
+ (cons (cons t newmap) minor-mode-map-alist)))
+ (lookup-key newmap (read-key-sequence ""))))))
+
+;; Compute and cache the equivalent keys in MENU and all its submenus.
+(defun mouse-major-mode-menu-compute-equiv-keys (menu)
+ (and (eq (car menu) 'keymap)
+ (x-popup-menu nil menu))
+ (while menu
+ (and (consp (car menu))
+ (consp (cdr (car menu)))
+ (let ((tail (cdr (car menu))))
+ (while (and (consp tail)
+ (not (eq (car tail) 'keymap)))
+ (setq tail (cdr tail)))
+ (if (consp tail)
+ (mouse-major-mode-menu-compute-equiv-keys tail))))
+ (setq menu (cdr menu))))
+
+;; Given a mode's menu bar keymap,
+;; if it defines exactly one menu bar menu,
+;; return just that menu.
+;; Otherwise return a menu for all of them.
+(defun mouse-major-mode-menu-1 (menubar)
+ (if menubar
+ (let ((tail menubar)
+ submap)
+ (while tail
+ (if (consp (car tail))
+ (if submap
+ (setq submap t)
+ (setq submap (cdr (car tail)))))
+ (setq tail (cdr tail)))
+ (if (eq submap t) menubar
+ submap))))
+
;; Commands that operate on windows.
(defun mouse-minibuffer-check (event)
@@ -1437,8 +1492,10 @@ and selects that window."
;; By binding these to down-going events, we let the user use the up-going
;; event to make the selection, saving a click.
-(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
-(global-set-key [C-down-mouse-3] 'mouse-set-font)
+(global-set-key [C-down-mouse-1] 'mouse-buffer-menu)
+(global-set-key [C-down-mouse-2] 'mouse-set-font)
+(global-set-key [C-down-mouse-3] 'mouse-major-mode-menu)
+
;; Replaced with dragging mouse-1
;; (global-set-key [S-mouse-1] 'mouse-set-mark)