Go to the first, previous, next, last section, table of contents.


Menus and the Mouse

The way to make a menu keymap produce a menu is to make it the definition of a prefix key.

If the prefix key ends with a mouse event, Emacs handles the menu keymap by popping up a visible menu, so that the user can select a choice with the mouse. When the user clicks on a menu item, the event generated is whatever character or symbol has the binding that brought about that menu item. (A menu item may generate a series of events if the menu has multiple levels or comes from the menu bar.)

It's often best to use a button-down event to trigger the menu. Then the user can select a menu item by releasing the button.

A single keymap can appear as multiple menu panes, if you explicitly arrange for this. The way to do this is to make a keymap for each pane, then create a binding for each of those maps in the main keymap of the menu. Give each of these bindings an item string that starts with `@'. The rest of the item string becomes the name of the pane. See the file `lisp/mouse.el' for an example of this. Any ordinary bindings with `@'-less item strings are grouped into one pane, which appears along with the other panes explicitly created for the submaps.

X toolkit menus don't have panes; instead, they can have submenus. Every nested keymap becomes a submenu, whether the item string starts with `@' or not. In a toolkit version of Emacs, the only thing special about `@' at the beginning of an item string is that the `@' doesn't appear in the menu item.

You can also get multiple panes from separate keymaps. The full definition of a prefix key always comes from merging the definitions supplied by the various active keymaps (minor mode, local, and global). When more than one of these keymaps is a menu, each of them makes a separate pane or panes. See section Active Keymaps.

In toolkit versions of Emacs, menus don't have panes, so submenus are used to represent the separate keymaps. Each keymap's contribution becomes one submenu.

A Lisp program can explicitly pop up a menu and receive the user's choice. You can use keymaps for this also. See section Pop-Up Menus.


Go to the first, previous, next, last section, table of contents.