Keymaps

Keys and key sequences

Neomacs internally represents keys using the key structure and key sequences using lists of key's.

It is usually more convenient to represent keys and key sequences using Emacs-style strings, such as "C-x C-b". kbd and key-description converts between string and the internal representation.

Function: kbd (string)
Parse STRING into a key sequence.
Function: key-description (key &optional stream)
Format the string representation of KEY and write to STREAM.
KEY can either by a key or a key sequence.
If STREAM is nil, return the string representation instead.

Defining keys

Function: set-key (keymap keyspec command)
Bind COMMAND to a KEYSPEC in a KEYMAP.
If KEYSPEC argument is a string, valid prefixes are: H (Hyper), s (Super), M (Meta), C (Ctrl), S (Shift)
Example: (set-key *global-keymap* "C-x b" 'switch-to-buffer)
Macro: define-keys (keymap-name &body bindings)
Define key BINDINGS for KEYMAP-NAME.
Example: (define-keys :global "C-x b" 'switch-to-buffer "C-x k" 'delete-buffer)

Looking up key bindings

When Neomacs command loop receive key events, it tries to find a command from a list of active keymaps depending on modes enabled in the buffer and the buffer focus. The active keymaps are, in precedence order:

  1. Non-nil keymap attributes of elements surrounding the buffer focus. Inner elements take precedence over outer elements.

  2. Keymaps with the same name of modes enabled in current buffer. The precedence order of keymaps is the same as the corresponding modes in the buffer's class precedence list.

Function: keymaps (buffer)
Compute the list of active keymaps for BUFFER.