Function: describe-keymap

describe-keymap is an autoloaded, interactive and byte-compiled function defined in help-fns.el.gz.

Signature

(describe-keymap KEYMAP)

Documentation

Describe key bindings in KEYMAP.

When called interactively, prompt for a variable that has a keymap value.

Probably introduced at or before Emacs version 28.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/help-fns.el.gz
;;;###autoload
(defun describe-keymap (keymap)
  "Describe key bindings in KEYMAP.
When called interactively, prompt for a variable that has a
keymap value."
  (interactive
   (let* ((km (help-fns--most-relevant-active-keymap))
          (val (completing-read
                (format-prompt "Keymap" km)
                obarray
                (lambda (m) (and (boundp m) (keymapp (symbol-value m))))
                t nil 'keymap-name-history
                (symbol-name km))))
     (unless (equal val "")
       (setq km (intern val)))
     (unless (and km (keymapp (symbol-value km)))
       (user-error "Not a keymap: %s" km))
     (list km)))
  (let (used-gentemp)
    (unless (and (symbolp keymap)
                 (boundp keymap)
                 (keymapp (symbol-value keymap)))
      (when (not (keymapp keymap))
        (if (symbolp keymap)
            (error "Not a keymap variable: %S" keymap)
          (error "Not a keymap")))
      (let ((sym nil))
        (unless sym
          (setq sym (cl-gentemp "KEYMAP OBJECT (no variable) "))
          (setq used-gentemp t)
          (set sym keymap))
        (setq keymap sym)))
    ;; Follow aliasing.
    (setq keymap (or (ignore-errors (indirect-variable keymap)) keymap))
    (help-setup-xref (list #'describe-keymap keymap)
                     (called-interactively-p 'interactive))
    (let* ((name (symbol-name keymap))
           (doc (documentation-property keymap 'variable-documentation))
           (file-name (find-lisp-object-file-name keymap 'defvar)))
      (with-help-window (help-buffer)
        (with-current-buffer standard-output
          (unless used-gentemp
            (princ (format-message "%S is a keymap variable" keymap))
            (if (not file-name)
                (progn
                  (setq help-mode--current-data (list :symbol keymap))
                  (princ ".\n\n"))
              (princ (format-message
                      " defined in `%s'.\n\n"
                      (if (eq file-name 'C-source)
                          "C source code"
                        (help-fns-short-filename file-name))))
              (save-excursion
                (re-search-backward (substitute-command-keys
                                     "`\\([^`']+\\)'")
                                    nil t)
                (setq help-mode--current-data (list :symbol keymap
                                                    :file file-name))
                (help-xref-button 1 'help-variable-def
                                  keymap file-name))))
          (when (and (not (equal "" doc)) doc)
            (princ "Documentation:\n")
            (princ (format-message "%s\n\n" doc)))
          ;; Use `insert' instead of `princ', so control chars (e.g. \377)
          ;; insert correctly.
          (insert (substitute-command-keys (concat "\\{" name "}"))))))
    ;; Cleanup.
    (when used-gentemp
      (makunbound keymap))))