-(defun popup-menu (menu-desc)
- "Pop up the given menu.
-A menu is a list of menu items, strings, and submenus.
-
-The first element of a menu must be a string, which is the name of the
-menu. This is the string that will be displayed in the parent menu, if
-any. For toplevel menus, it is ignored. This string is not displayed
-in the menu itself.
-
-A menu item is a vector containing:
-
- - the name of the menu item (a string);
- - the `callback' of that item;
- - a list of keywords with associated values:
- - :active active-p a form specifying whether this item is selectable;
- - :suffix suffix a string to be appended to the name as an `argument'
- to the command, like `Kill Buffer NAME';
- - :keys command-keys a string, suitable for `substitute-command-keys',
- to specify the keyboard equivalent of a command
- when the callback is a form (this is not necessary
- when the callback is a symbol, as the keyboard
- equivalent is computed automatically in that case);
- - :style style a symbol: nil for a normal menu item, `toggle' for
- a toggle button (a single option that can be turned
- on or off), or `radio' for a radio button (one of a
- group of mutually exclusive options);
- - :selected form for `toggle' or `radio' style, a form that specifies
- whether the button will be in the selected state.
-
-Alternately, the vector may contain exactly 3 or 4 elements, with the third
-element specifying `active-p' and the fourth specifying `suffix'.
-
-If the `callback' of a menu item is a symbol, then it must name a command.
-It will be invoked with `call-interactively'. If it is a list, then it is
-evaluated with `eval'.
-
-If an element of a menu is a string, then that string will be presented in
-the menu as unselectable text.
-
-If an element of a menu is a string consisting solely of hyphens, then that
-item will be presented as a solid horizontal line.
-
-If an element of a menu is a list, it is treated as a submenu. The name of
-that submenu (the first element in the list) will be used as the name of the
-item representing this menu on the parent.
-
-The syntax, more precisely:
-
- form := <something to pass to `eval'>
- command := <a symbol or string, to pass to `call-interactively'>
- callback := command | form
- active-p := <t or nil, whether this thing is selectable>
- text := <string, non selectable>
- name := <string>
- suffix := <string>
- command-keys := <string>
- object-style := 'nil' | 'toggle' | 'radio'
- keyword := ':active' active-p
- | ':suffix' suffix
- | ':keys' command-keys
- | ':style' object-style
- | ':selected' form
- menu-item := '[' name callback active-p [ suffix ] ']'
- | '[' name callback [ keyword ]+ ']'
- menu := '(' name [ menu-item | menu | text ]+ ')'"
- (let ((menu (make-lucid-menu-keymap (car menu-desc) (cdr menu-desc)))
- (pos (mouse-pixel-position))
- answer cmd)
- (while (and menu
- (setq answer (x-popup-menu (list (list (nth 1 pos)
- (nthcdr 2 pos))
- (car pos))
- menu)))
- (setq cmd (lookup-key menu (apply 'vector answer)))
- (setq menu nil)
- (and cmd
- (if (keymapp cmd)
- (setq menu cmd)
- (call-interactively cmd))))))
-