A menu is described using a menu description, which is a list of menu items, keyword-value pairs, strings, and submenus. The menu description specifies which items are present in the menu, what function each item invokes, and whether the item is selectable or not. Pop-up menus are directly described with a menu description, while menubars are described slightly differently (see below).
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 or
menubar, if any. This string is not displayed in the menu itself,
except in the case of the top level pop-up menu, where there is no
parent. In this case, the string will be displayed at the top of the
menu if popup-menu-titles is non-nil.
Immediately following the first element there may optionally be up to four keyword-value pairs, as follows:
:included formnil.
:config symbol:included (memq symbol
menubar-configuration). See the variable menubar-configuration.
:filter function:accelerator keyThe rest of the menu consists of elements as follows:
[name callback :keyword value :keyword value... ]
name is a string, the name of the menu item; it is the string to display on the menu. It is filtered through the resource database, so it is possible for resources to override what string is actually displayed.
callback is a form that will be invoked when the menu item is
selected. 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.
The valid keywords and their meanings are described below.
Note that for compatibility purposes, the form
[name callback active-p]
is also accepted and is equivalent to
[name callback:activeactive-p]
and the form
[name callback active-p suffix]
is accepted and is equivalent to
[name callback:activeactive-p:suffixsuffix]
However, these older forms are deprecated and should generally not be used.
The possible keywords are as follows:
nil. If the item is unselectable, it will
usually be displayed grayed-out to indicate this.
substitute-command-keys first.
niltoggleradiobuttonThe only difference between toggle and radio buttons is how they are
displayed. But for consistency, a toggle button should be used when
there is one option whose value can be turned on or off, and radio
buttons should be used when there is a set of mutually exclusive options.
When using a group of radio buttons, you should arrange for no more than
one to be marked as selected at a time.
toggle, radio or
button. This specifies whether the button will be in the
selected or unselected state. form is evaluated, as for
:active.
nil. Note that this is different from :active: If
:active evaluates to nil, the item will be displayed
grayed out, while if :included evaluates to nil, the item
will be omitted entirely.
:included (memq symbol
menubar-configuration). See the variable menubar-configuration.
This variable holds a list of symbols, against which the value of the
:configtag for each menubar item will be compared. If a menubar item has a:configtag, then it is omitted from the menubar if that tag is not a member of themenubar-configurationlist.
For example:
("File"
:filter file-menu-filter ; file-menu-filter is a function that takes
; one argument (a list of menu items) and
; returns a list of menu items
[ "Save As..." write-file]
[ "Revert Buffer" revert-buffer :active (buffer-modified-p) ]
[ "Read Only" toggle-read-only :style toggle :selected buffer-read-only ]
)