Previous: , Up: Defining Menus   [Contents][Index] Alias Menu Items

Sometimes it is useful to make menu items that use the “same” command but with different enable conditions. The best way to do this in Emacs now is with extended menu items; before that feature existed, it could be done by defining alias commands and using them in menu items. Here’s an example that makes two aliases for read-only-mode and gives them different enable conditions:

(defalias 'make-read-only 'read-only-mode)
(put 'make-read-only 'menu-enable '(not buffer-read-only))
(defalias 'make-writable 'read-only-mode)
(put 'make-writable 'menu-enable 'buffer-read-only)

When using aliases in menus, often it is useful to display the equivalent key bindings for the “real” command name, not the aliases (which typically don’t have any key bindings except for the menu itself). To request this, give the alias symbol a non-nil menu-alias property. Thus,

(put 'make-read-only 'menu-alias t)
(put 'make-writable 'menu-alias t)

causes menu items for make-read-only and make-writable to show the keyboard bindings for read-only-mode.