blob: 7c9c4cd7dd2f00dd993c27e7c4df90b013ff7582 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<h4 class="subsection">Modifying Menus</h4> <p>When you insert a new item in an existing menu, you probably want to put it in a particular place among the menu’s existing items. If you use <code>define-key</code> to add the item, it normally goes at the front of the menu. To put it elsewhere in the menu, use <code>define-key-after</code>: </p> <dl> <dt id="define-key-after">Function: <strong>define-key-after</strong> <em>map key binding &optional after</em>
</dt> <dd>
<p>Define a binding in <var>map</var> for <var>key</var>, with value <var>binding</var>, just like <code>define-key</code>, but position the binding in <var>map</var> after the binding for the event <var>after</var>. The argument <var>key</var> should be of length one—a vector or string with just one element. But <var>after</var> should be a single event type—a symbol or a character, not a sequence. The new binding goes after the binding for <var>after</var>. If <var>after</var> is <code>t</code> or is omitted, then the new binding goes last, at the end of the keymap. However, new bindings are added before any inherited keymap. </p> <p>Here is an example: </p> <div class="example"> <pre class="example">(define-key-after my-menu [drink]
'("Drink" . drink-command) 'eat)
</pre>
</div> <p>makes a binding for the fake function key <tt class="key">DRINK</tt> and puts it right after the binding for <tt class="key">EAT</tt>. </p> <p>Here is how to insert an item called ‘<samp>Work</samp>’ in the ‘<samp>Signals</samp>’ menu of Shell mode, after the item <code>break</code>: </p> <div class="example"> <pre class="example">(define-key-after shell-mode-map [menu-bar signals work]
'("Work" . work-command) 'break)
</pre>
</div> </dd>
</dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 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/Modifying-Menus.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Modifying-Menus.html</a>
</p>
</div>
|