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 define-key
to add the item, it normally goes at the front of
the menu. To put it elsewhere in the menu, use keymap-set-after
:
Define a binding in map for key, with value binding,
just like keymap-set
(see Changing Key Bindings), but
position the binding in map after the binding for the event
after. The argument key should represent a single menu
item or key, and should satisfy key-valid-p
(see Key Sequences). after should be a single event type—a symbol or
a character, not a sequence. The new binding goes after the binding
for after. If after is t
or is omitted, then the
new binding goes last, at the end of the keymap. However, new
bindings are added before any inherited keymap.
Here is an example:
(keymap-set-after my-menu "<drink>" '("Drink" . drink-command) 'eat)
makes a binding for the fake function key DRINK and puts it right after the binding for EAT.
Here is how to insert an item called ‘Work’ in the ‘Signals’
menu of Shell mode, after the item break
:
(keymap-set-after shell-mode-map "<menu-bar> <signals> <work>" '("Work" . work-command) 'break)