PREV UP NEXT GNU Emacs Lisp Reference Manual

19.4: Inheritance and Keymaps

A keymap can inherit the bindings of another keymap. Do do this, make a keymap whose ``tail'' is another existing keymap to inherit from. Such a keymap looks like this:

(keymap bindings... . other-keymap)

The effect is that this keymap inherits all the bindings of other-keymap, whatever they may be at the time a key is looked up, but can add to them or override them with bindings.

If you change the bindings in other-keymap using define-key or other key-binding functions, these changes are visible in the inheriting keymap unless shadowed by bindings. The converse is not true: if you use define-key to change the inheriting keymap, that affects bindings, but has no effect on other-keymap.

Here is an example showing how to make a keymap that inherits from text-mode-map:

(setq my-mode-map (cons 'keymap text-mode-map))