(popup-menu): New function.
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 18 Jul 2000 23:43:41 +0000 (23:43 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 18 Jul 2000 23:43:41 +0000 (23:43 +0000)
(mouse-major-mode-menu): Use it.

lisp/ChangeLog
lisp/mouse.el

index 3b326ed..53810ee 100644 (file)
@@ -1,3 +1,8 @@
+2000-07-18  Stefan Monnier  <monnier@cs.yale.edu>
+
+       * mouse.el (popup-menu): New function.
+       (mouse-major-mode-menu): Use it.
+
 2000-07-18  Dave Love  <fx@gnu.org>
 
        * bindings.el (mode-line-mule-info, mode-line-modified): help-echo
@@ -5,7 +10,7 @@
 
 2000-07-18  Gerd Moellmann  <gerd@gnu.org>
 
-       * faces.el (face-font-selection-order) 
+       * faces.el (face-font-selection-order)
        (face-font-family-alternatives): Add custom type.
        
 2000-07-18  Dave Love  <fx@gnu.org>
        * 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  <handa@etl.go.jp>
 
-       * 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):
 
 2000-07-16  John Wiegley  <johnw@gnu.org>
 
-       * 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  <handa@etl.go.jp>
 
-       * 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.
index 9057e78..ad86868 100644 (file)
 \f
 ;; 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)