Function: helpful--keymap-keys
helpful--keymap-keys is a byte-compiled function defined in
helpful.el.
Signature
(helpful--keymap-keys KEYMAP)
Documentation
Return all the keys and commands in KEYMAP.
Flattens nested keymaps and follows remapped commands.
Returns a list of pairs (KEYCODES COMMAND), where KEYCODES is a
vector suitable for key-description, and COMMAND is a smbol.
This function has :around advice: helpful--keymap-keys@keymap-fallback.
Source Code
;; Defined in ~/.emacs.d/elpa/helpful-20250408.334/helpful.el
(defun helpful--keymap-keys (keymap)
"Return all the keys and commands in KEYMAP.
Flattens nested keymaps and follows remapped commands.
Returns a list of pairs (KEYCODES COMMAND), where KEYCODES is a
vector suitable for `key-description', and COMMAND is a smbol."
(cond
;; Prefix keys.
((and
(symbolp keymap)
(fboundp keymap)
;; Prefix keys use a keymap in the function slot of a symbol.
(keymapp (symbol-function keymap)))
(helpful--keymap-keys (symbol-function keymap)))
;; Other symbols or compiled functions mean we've reached a leaf,
;; so this is a command we can call.
((or
(symbolp keymap)
(functionp keymap)
;; Strings or vectors mean a keyboard macro.
(stringp keymap)
(vectorp keymap))
`(([] ,keymap)))
((stringp (car keymap))
(helpful--keymap-keys (cdr keymap)))
;; Otherwise, recurse on the keys at this level of the keymap.
(t
(let (result)
(dolist (item (cdr keymap))
(cond
((and (consp item)
(eq (car item) 'menu-bar))
;; Skip menu bar items.
nil)
;; Sparse keymaps are lists.
((consp item)
(-let [(keycode . value) item]
(-each (helpful--keymap-keys value)
(-lambda ((keycodes command))
(push (list (vconcat (vector keycode) keycodes) command)
result)))))
;; Dense keymaps are char-tables.
((char-table-p item)
(map-char-table
(lambda (keycode value)
(-each (helpful--keymap-keys value)
(-lambda ((keycodes command))
(push (list (vconcat (vector keycode) keycodes) command)
result))))
item))))
;; For every command `new-func' mapped to a command `orig-func', show `new-func' with
;; the key sequence for `orig-func'.
(setq result
(-map-when
(-lambda ((keycodes _))
(and (> (length keycodes) 1)
(eq (elt keycodes 0) 'remap)))
(-lambda ((keycodes command))
(list
(where-is-internal (elt keycodes 1) global-map t)
command))
result))
;; Preserve the original order of the keymap.
(nreverse result)))))