diff options
author | Stefan Monnier <monnier@iro.umontreal.ca> | 2000-07-18 23:43:41 +0000 |
---|---|---|
committer | Stefan Monnier <monnier@iro.umontreal.ca> | 2000-07-18 23:43:41 +0000 |
commit | 21ad0f7b2f55e3701febc76470e77a88eace19dd (patch) | |
tree | 9f7eb4e1a47072ca7da9e1fd226b2fc4c3b2de7c /lisp/mouse.el | |
parent | 3b33a0059c10b22373eeee7914685afa7af20108 (diff) | |
download | emacs-21ad0f7b2f55e3701febc76470e77a88eace19dd.tar.gz |
(popup-menu): New function.
(mouse-major-mode-menu): Use it.
Diffstat (limited to 'lisp/mouse.el')
-rw-r--r-- | lisp/mouse.el | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/lisp/mouse.el b/lisp/mouse.el index 9057e781d5d..ad86868f13c 100644 --- a/lisp/mouse.el +++ b/lisp/mouse.el @@ -44,6 +44,35 @@ ;; Provide a mode-specific menu on a mouse button. +(defun popup-menu (menu &optional position prefix) + "Popup the given menu and call the selected option. +MENU can be a keymap or an easymenu-style menu. +POSITION can be a click event or ((XOFFSET YOFFSET) WINDOW) and defaults to + the current mouse position. +PREFIX is the prefix argument (if any) to pass to the command." + (let* ((map (if (keymapp menu) menu + (let* ((map (easy-menu-create-menu (car menu) (cdr menu))) + (filter (when (symbolp map) + (plist-get (get map 'menu-pro) :filter)))) + (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))) + ;; 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)))) + (setq map nil) + ;; Clear out echoing, which perhaps shows a prefix arg. + (message "") + (when cmd + (if (keymapp cmd) + ;; Try again but with the submap. + (setq map cmd) + (setq prefix-arg prefix) + ;; mouse-major-mode-menu was using `command-execute' instead. + (call-interactively cmd))))))) + (defun mouse-major-mode-menu (event prefix) "Pop up a mode-specific menu of mouse commands. Default to the Edit menu if the major mode doesn't define a menu." @@ -70,18 +99,8 @@ Default to the Edit menu if the major mode doesn't define a menu." ;; Make our menu inherit from the desired keymap which we want ;; to display as the menu now. (set-keymap-parent newmap ancestor)) - (setq result (x-popup-menu t (list newmap))) - (if result - (let ((command (key-binding - (apply 'vector (append '(menu-bar) - mouse-major-mode-menu-prefix - result))))) - ;; Clear out echoing, which perhaps shows a prefix arg. - (message "") - (if command - (progn - (setq prefix-arg prefix) - (command-execute command))))))) + (popup-menu newmap event prefix))) + ;; Compute and cache the equivalent keys in MENU and all its submenus. ;;;(defun mouse-major-mode-menu-compute-equiv-keys (menu) |