summaryrefslogtreecommitdiff
path: root/devdocs/elisp/simple-menu-items.html
blob: 7ce8b52dfdfda87067a26ae51d9d6aae80b75a5c (plain)
1
2
3
4
5
6
7
8
9
10
 <h4 class="subsubsection">Simple Menu Items</h4> <p>The simpler (and original) way to define a menu item is to bind some event type (it doesn’t matter what event type) to a binding like this: </p> <div class="example"> <pre class="example">(<var>item-string</var> . <var>real-binding</var>)
</pre>
</div> <p>The <small>CAR</small>, <var>item-string</var>, is the string to be displayed in the menu. It should be short—preferably one to three words. It should describe the action of the command it corresponds to. Note that not all graphical toolkits can display non-<acronym>ASCII</acronym> text in menus (it will work for keyboard menus and will work to a large extent with the GTK+ toolkit). </p> <p>You can also supply a second string, called the help string, as follows: </p> <div class="example"> <pre class="example">(<var>item-string</var> <var>help</var> . <var>real-binding</var>)
</pre>
</div> <p><var>help</var> specifies a help-echo string to display while the mouse is on that item in the same way as <code>help-echo</code> text properties (see <a href="special-properties#Help-display">Help display</a>). </p> <p>As far as <code>define-key</code> is concerned, <var>item-string</var> and <var>help-string</var> are part of the event’s binding. However, <code>lookup-key</code> returns just <var>real-binding</var>, and only <var>real-binding</var> is used for executing the key. </p> <p>If <var>real-binding</var> is <code>nil</code>, then <var>item-string</var> appears in the menu but cannot be selected. </p> <p>If <var>real-binding</var> is a symbol and has a non-<code>nil</code> <code>menu-enable</code> property, that property is an expression that controls whether the menu item is enabled. Every time the keymap is used to display a menu, Emacs evaluates the expression, and it enables the menu item only if the expression’s value is non-<code>nil</code>. When a menu item is disabled, it is displayed in a fuzzy fashion, and cannot be selected. </p> <p>The menu bar does not recalculate which items are enabled every time you look at a menu. This is because the X toolkit requires the whole tree of menus in advance. To force recalculation of the menu bar, call <code>force-mode-line-update</code> (see <a href="mode-line-format">Mode Line Format</a>). </p><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
    <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Menu-Items.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Simple-Menu-Items.html</a>
  </p>
</div>