elisp: Searching Keymaps
21.8 Searching the Active Keymaps
=================================
Here is a pseudo-Lisp summary of how Emacs searches the active keymaps:
(or (if overriding-terminal-local-map
(FIND-IN overriding-terminal-local-map))
(if overriding-local-map
(FIND-IN overriding-local-map)
(or (FIND-IN (get-char-property (point) 'keymap))
(FIND-IN-ANY emulation-mode-map-alists)
(FIND-IN-ANY minor-mode-overriding-map-alist)
(FIND-IN-ANY minor-mode-map-alist)
(if (get-text-property (point) 'local-map)
(FIND-IN (get-char-property (point) 'local-map))
(FIND-IN (current-local-map)))))
(FIND-IN (current-global-map)))
Here, FIND-IN and FIND-IN-ANY are pseudo functions that search in one
keymap and in an alist of keymaps, respectively. Note that the
‘set-transient-map’ function works by setting
‘overriding-terminal-local-map’ (Controlling Active Maps).
In the above pseudo-code, if a key sequence starts with a mouse event
(Mouse Events), that event’s position is used instead of point,
and the event’s buffer is used instead of the current buffer. In
particular, this affects how the ‘keymap’ and ‘local-map’ properties are
looked up. If a mouse event occurs on a string embedded with a
‘display’, ‘before-string’, or ‘after-string’ property (Special
Properties), and the string has a non-‘nil’ ‘keymap’ or ‘local-map’
property, that overrides the corresponding property in the underlying
buffer text (i.e., the property specified by the underlying text is
ignored).
When a key binding is found in one of the active keymaps, and that
binding is a command, the search is over—the command is executed.
However, if the binding is a symbol with a value or a string, Emacs
replaces the input key sequences with the variable’s value or the
string, and restarts the search of the active keymaps. Key
Lookup.
The command which is finally found might also be remapped.
Remapping Commands.