Function: kbd
kbd is a byte-compiled function defined in subr.el.gz.
Signature
(kbd KEYS)
Documentation
Convert KEYS to the internal Emacs key representation.
KEYS should be a string in the format returned by commands such
as C-h k (describe-key) (describe-key).
This is the same format used for saving keyboard macros (see
edmacro-mode).
Here's some example key sequences:
"f"
"C-c C-c"
"H-<left>"
"M-RET"
"C-M-<return>"
For an approximate inverse of this, see key-description.
Probably introduced at or before Emacs version 22.1.
Source Code
;; Defined in /usr/src/emacs/lisp/subr.el.gz
;;;; Keymap support.
(defun kbd (keys)
"Convert KEYS to the internal Emacs key representation.
KEYS should be a string in the format returned by commands such
as \\[describe-key] (`describe-key').
This is the same format used for saving keyboard macros (see
`edmacro-mode').
Here's some example key sequences:
\"f\"
\"C-c C-c\"
\"H-<left>\"
\"M-RET\"
\"C-M-<return>\"
For an approximate inverse of this, see `key-description'."
(declare (pure t) (side-effect-free t))
(let ((res (key-parse keys)))
;; For historical reasons, parse "C-x ( C-d C-x )" as "C-d", since
;; `kbd' used to be a wrapper around `read-kbd-macro'.
(when (and (>= (length res) 4)
(eq (aref res 0) ?\C-x)
(eq (aref res 1) ?\()
(eq (aref res (- (length res) 2)) ?\C-x)
(eq (aref res (- (length res) 1)) ?\)))
(setq res (apply #'vector (let ((lres (append res nil)))
;; Remove the first and last two elements.
(setq lres (cddr lres))
(setq lres (nreverse lres))
(setq lres (cddr lres))
(nreverse lres)))))
(if (not (memq nil (mapcar (lambda (ch)
(and (numberp ch)
(<= 0 ch 127)))
res)))
;; Return a string.
(concat (mapcar #'identity res))
;; Return a vector.
res)))