Function: keymap-local-set
keymap-local-set is an interactive and byte-compiled function defined
in keymap.el.gz.
Signature
(keymap-local-set KEY COMMAND)
Documentation
Give KEY a local binding as COMMAND.
When called interactively, KEY is a key sequence. When called from
Lisp, KEY is a string that must satisfy key-valid-p.
COMMAND is the command definition to use. When called interactively,
this function prompts for COMMAND and accepts only names of known
commands, i.e., symbols that satisfy the commandp predicate. When
called from Lisp, COMMAND can be anything that keymap-set accepts
as its DEFINITION argument.
If COMMAND is a string (which can only happen when this function is
called from Lisp), it must satisfy key-valid-p.
The key-description convenience function converts a simple
string of characters to an equivalent form that is acceptable for
COMMAND.
The binding goes in the current buffer's local keymap, which in most cases is shared with all other buffers in the same major mode.
Other relevant functions are documented in the keymaps group.
Probably introduced at or before Emacs version 29.1.
Key Bindings
Shortdoc
;; keymaps
(keymap-local-set "C-c C-c" #'quit-buffer)
Source Code
;; Defined in /usr/src/emacs/lisp/keymap.el.gz
(defun keymap-local-set (key command &optional interactive)
"Give KEY a local binding as COMMAND.
When called interactively, KEY is a key sequence. When called from
Lisp, KEY is a string that must satisfy `key-valid-p'.
COMMAND is the command definition to use. When called interactively,
this function prompts for COMMAND and accepts only names of known
commands, i.e., symbols that satisfy the `commandp' predicate. When
called from Lisp, COMMAND can be anything that `keymap-set' accepts
as its DEFINITION argument.
If COMMAND is a string (which can only happen when this function is
called from Lisp), it must satisfy `key-valid-p'.
The `key-description' convenience function converts a simple
string of characters to an equivalent form that is acceptable for
COMMAND.
The binding goes in the current buffer's local keymap, which in most
cases is shared with all other buffers in the same major mode."
(declare (compiler-macro (lambda (form) (keymap--compile-check key) form))
(advertised-calling-convention (key command) "29.1"))
(interactive "KSet key locally: \nCSet key %s locally to command: \np")
(let ((map (current-local-map)))
(unless map
(use-local-map (setq map (make-sparse-keymap))))
(when interactive
(setq key (key-description key)))
(keymap-set map key command)))