changeset 46137:520292a3983b

(easy-menu-popup-menu): New function.
author Richard M. Stallman <rms@gnu.org>
date Tue, 02 Jul 2002 18:49:03 +0000
parents 79f132657570
children dafa37505b60
files lisp/emacs-lisp/easymenu.el
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/emacs-lisp/easymenu.el	Tue Jul 02 18:48:34 2002 +0000
+++ b/lisp/emacs-lisp/easymenu.el	Tue Jul 02 18:49:03 2002 +0000
@@ -616,6 +616,20 @@
   (or (keymapp map) (error "Malformed menu in easy-menu: (%s)" map))
   map)
 
+(defun easy-menu-popup-menu (menu &optional event)
+  "Pop up a menu and run a command according to user's selection.
+MENU is a menu description as in `easy-menu-define'.
+EVENT is a mouse button event and determines where to pop up the menu.
+If EVENT is nil, pop up menu at the current mouse position."
+  (let ((map (easy-menu-create-menu (car menu) (cdr menu))))
+    (if (symbolp map)
+	(let ((f (memq :filter (get map 'menu-prop))))
+	  (setq map (symbol-function map))
+	  (if f (setq map (funcall (cadr f) map)))))
+    (let* ((sel (x-popup-menu (or event t) map))
+	   (f (if (consp sel) (lookup-key map (apply 'vector sel)))))
+      (if (commandp f) (call-interactively f)))))
+
 (provide 'easymenu)
 
 ;;; easymenu.el ends here