From 21ad0f7b2f55e3701febc76470e77a88eace19dd Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 18 Jul 2000 23:43:41 +0000 Subject: [PATCH] (popup-menu): New function. (mouse-major-mode-menu): Use it. --- lisp/ChangeLog | 33 ++++++++++++++++++--------------- lisp/mouse.el | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 27 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 3b326ed4d32..53810eea67a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2000-07-18 Stefan Monnier + + * mouse.el (popup-menu): New function. + (mouse-major-mode-menu): Use it. + 2000-07-18 Dave Love * bindings.el (mode-line-mule-info, mode-line-modified): help-echo @@ -5,7 +10,7 @@ 2000-07-18 Gerd Moellmann - * faces.el (face-font-selection-order) + * faces.el (face-font-selection-order) (face-font-family-alternatives): Add custom type. 2000-07-18 Dave Love @@ -46,27 +51,26 @@ * eshell/esh-cmd.el (eshell-cmd): Ditto. * eshell/em-smart.el (eshell-smart): Ditto. * eshell/em-banner.el (eshell-banner): Ditto. - * eshell/em-alias.el (eshell-alias, eshell-bad-command-tolerance): - Ditto. + * eshell/em-alias.el (eshell-alias, eshell-bad-command-tolerance): Ditto. * eshell/em-unix.el (eshell-shuffle-files): Don't disable same-file check in the MS-DOS version (it does support inodes). * eshell/em-alias.el (eshell-maybe-replace-by-alias): Doc fix. - * eshell/eshell.el (eshell-directory-name): Run default directory - name through convert-standard-filename. + * eshell/eshell.el (eshell-directory-name): + Run default directory name through convert-standard-filename. 2000-07-18 Kenichi Handa - * international/mule-cmds.el (select-safe-coding-system): Fix typo - in the comment. + * international/mule-cmds.el (select-safe-coding-system): + Fix typo in the comment. - * language/european.el (compound-text): Force katakana-jisx0201 to - be designated to G1. + * language/european.el (compound-text): + Force katakana-jisx0201 to be designated to G1. - * international/mule-conf.el (oldjis-newjis-jisroman-ascii): Don't - translate some national variant characters of latin-jisx0201. + * international/mule-conf.el (oldjis-newjis-jisroman-ascii): + Don't translate some national variant characters of latin-jisx0201. (x-ctext): Force katakana-jisx0201 to be designated to G1. * international/kkc.el (kkc-after-update-conversion-functions): @@ -75,14 +79,13 @@ 2000-07-16 John Wiegley - * lisp/align.el (align-newline-and-indent): Adding new function. - for auto-aligning blocks of code on RET. + * lisp/align.el (align-newline-and-indent): + Adding new function. for auto-aligning blocks of code on RET. (align-region): Fixed badly formatted minibuffer message. 2000-07-17 Kenichi Handa - * international/kkc.el (kkc-show-conversion-list-count): Customize - it. + * international/kkc.el (kkc-show-conversion-list-count): Customize it. (kkc-region): Update kkc-next-count and kkc-prev-count here. Show the conversion list at first if appropriate. (kkc-next): Don't update kkc-next-count here. 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) -- 2.39.2