Function: keymap-set
keymap-set is a byte-compiled function defined in keymap.el.gz.
Signature
(keymap-set KEYMAP KEY DEFINITION)
Documentation
Set KEY to DEFINITION in KEYMAP.
KEY is a string that satisfies key-valid-p.
If DEFINITION is a string, it must also satisfy key-valid-p.
DEFINITION is anything that can be a key's definition:
nil (means key is undefined in this keymap),
a command (a Lisp function suitable for interactive calling),
a string (treated as a keyboard macro or a sequence of input events),
a keymap (to define a prefix key),
a symbol (when the key is looked up, the symbol will stand for its
function definition, which should at that time be one of the above,
or another symbol whose function definition is used, etc.),
a cons (STRING . DEFN), meaning that DEFN is the definition
(DEFN should be a valid definition in its own right) and
STRING is the menu item name (which is used only if the containing
keymap has been created with a menu name, see make-keymap),
or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP,
or an extended menu item definition.
(See info node (elisp)Extended Menu Items.)
Other relevant functions are documented in the keymaps group.
Probably introduced at or before Emacs version 29.1.
Shortdoc
;; keymaps
(keymap-set map "C-c C-c" #'quit-buffer)
Source Code
;; Defined in /usr/src/emacs/lisp/keymap.el.gz
(defun keymap-set (keymap key definition)
"Set KEY to DEFINITION in KEYMAP.
KEY is a string that satisfies `key-valid-p'.
If DEFINITION is a string, it must also satisfy `key-valid-p'.
DEFINITION is anything that can be a key's definition:
nil (means key is undefined in this keymap),
a command (a Lisp function suitable for interactive calling),
a string (treated as a keyboard macro or a sequence of input events),
a keymap (to define a prefix key),
a symbol (when the key is looked up, the symbol will stand for its
function definition, which should at that time be one of the above,
or another symbol whose function definition is used, etc.),
a cons (STRING . DEFN), meaning that DEFN is the definition
(DEFN should be a valid definition in its own right) and
STRING is the menu item name (which is used only if the containing
keymap has been created with a menu name, see `make-keymap'),
or a cons (MAP . CHAR), meaning use definition of CHAR in keymap MAP,
or an extended menu item definition.
(See info node `(elisp)Extended Menu Items'.)"
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form)))
(keymap--check key)
;; If we're binding this key to another key, then parse that other
;; key, too.
(when (stringp definition)
(keymap--check definition)
(setq definition (key-parse definition)))
(define-key keymap (key-parse key) definition))