Next: , Previous: , Up: The Command Interpreter   [Contents][Index]


7.2.2 Binding Commands to Keys

The command interpreter determines which command to invoke on the basis of key bindings. A key binding is an association between a command and a sequence of key-events (see section key-events-intro. A sequence of key-events is called a key and is represented by a single key-event or a sequence (list or vector) of key-events.

Since key bindings may be local to a mode or buffer, the current environment (page current-environment) determines the set of key bindings in effect at any given time. When the command interpreter tries to find the binding for a key, it first checks if there is a local binding in the current-buffer, then if there is a binding in each of the minor modes and the major mode for the current buffer (page modes), and finally checks to see if there is a global binding. If no binding is found, then the command interpreter beeps or flashes the screen to indicate this.

Function: bind-key name key &optional kind where

This function associates command name and key in some environment. Key is either a key-event or a sequence of key-events. There are three possible values of kind:

:global

The default, make a global key binding.

:mode

Make a mode specific key binding in the mode whose name is where.

:buffer

Make a binding which is local to buffer where.

This processes key for key translations before establishing the binding. See section key-trans.

If the key is some prefix of a key binding which already exists in the specified place, then the new one will override the old one, effectively deleting it.

ext:do-alpha-key-events is useful for setting up bindings in certain new modes.

Function: command-bindings command

This function returns a list of the places where command is bound. A place is specified as a list of the key (always a vector), the kind of binding, and where (either the mode or buffer to which the binding is local, or nil if it is a global).

Function: delete-key-binding key &optional kind where

This function removes the binding of key in some place. Key is either a key-event or a sequence of key-events. kind is the kind of binding to delete, one of :global (the default), :mode or :buffer. If kind is :mode, where is the mode name, and if kind is :buffer, then where is the buffer.

This function signals an error if key is unbound.

This processes key for key translations before deleting the binding. See section key-trans.

Function: get-command key &optional kind where

This function returns the command bound to key, returning nil if it is unbound. Key is either a key-event or a sequence of key-events. If key is an initial subsequence of some keys, then this returns the keyword :prefix. There are four cases of kind:

:current

Return the current binding of key using the current buffer’s search list. If there are any transparent key bindings for key, then they are returned in a list as a second value.

:global

Return the global binding of key. This is the default.

:mode

Return the binding of key in the mode named where.

:buffer

Return the binding of key local to the buffer where.

This processes key for key translations before looking for any binding. See section key-trans.

Function: map-bindings function kind &optional where

This function maps over the key bindings in some place. For each binding, this passes function the key and the command bound to it. Kind and where are the same as in bind-key. The key is not guaranteed to remain valid after a given iteration.


Next: Key Translation, Previous: Editor Input, Up: The Command Interpreter   [Contents][Index]