Show Keys In Emacs Keymap Value
Did you know the command
C-h m
(describe-mode
), which usually shows a description of the current major and minor modes, usually with their keymaps?(substitute-command-keys "\\{foo-map}")
is whatdescribe-mode
uses internally to generate the user-friendly description of the keymapfoo-map
.If you'd like to have something closer to the keymap structure, the API is documented in "Classifying Events" in the Emacs Lisp manual. For example,
(event-modifiers 33554445)
==>(shift control)
(format "%c" (event-basic-type 33554445))
==>"m"
I just wrote the following based on Gilles' answer, so I figured I'd post it.
I see that Drew's describe-keymap
has a very similar basis, but also covers various other use-cases, so offhand I'm inclined to suggest using that one as a more complete solution; but FWIW:
(defun my-describe-keymap (keymap)
"Describe a keymap using `substitute-command-keys'."
(interactive
(list (completing-read
"Keymap: " (let (maps)
(mapatoms (lambda (sym)
(and (boundp sym)
(keymapp (symbol-value sym))
(push sym maps))))
maps)
nil t)))
(with-output-to-temp-buffer (format "*keymap: %s*" keymap)
(princ (format "%s\n\n" keymap))
(princ (substitute-command-keys (format "\\{%s}" keymap)))
(with-current-buffer standard-output ;; temp buffer
(setq help-xref-stack-item (list #'my-describe-keymap keymap)))))
This is what you need: library help-fns+.el
.
- http://www.emacswiki.org/emacs/HelpPlus
- http://www.emacswiki.org/emacs/download/help-fns%2b.el
That gives you, as C-h M-k, command describe-keymap
, which gives you a human-readable description of any keymap bound to a variable. E.g.:
C-h M-k dired-mode-map
dired-mode-map -------------- For more information check the manuals. Local keymap for `dired-mode' buffers. key binding --- ------- e .. f dired-find-file RET dired-find-file C-o dired-display-file C-t Prefix Command ESC Prefix Command SPC dired-next-line ! dired-do-shell-command # dired-flag-auto-save-files $ dired-hide-subdir % Prefix Command & dired-do-async-shell-command * Prefix Command + dired-create-directory - negative-argument . dired-clean-directory 0 .. 9 digit-argument : Prefix Command dired-next-dirline ? dired-summary A dired-do-search B dired-do-byte-compile C dired-do-copy D dired-do-delete G dired-do-chgrp H dired-do-hardlink L dired-do-load M dired-do-chmod O dired-do-chown P dired-do-print Q dired-do-query-replace-regexp R dired-do-rename S dired-do-symlink T dired-do-touch U dired-unmark-all-marks X dired-do-shell-command Z dired-do-compress ^ dired-up-directory a dired-find-alternate-file d dired-flag-file-deletion g revert-buffer h describe-mode i dired-maybe-insert-subdir j dired-goto-file k dired-do-kill-lines l dired-do-redisplay m dired-mark n dired-next-line o dired-find-file-other-window p dired-previous-line q quit-window s dired-sort-toggle-or-edit t dired-toggle-marks u dired-unmark v dired-view-file w dired-copy-filename-as-kill x dired-do-flagged-delete y dired-show-file-type z kill-this-buffer ~ dired-flag-backup-files DEL dired-unmark-backward mouse-face dired-mouse-find-file-other-window ?? C-t C-t image-dired-dired-toggle-marked-thumbs C-t . image-dired-display-thumb C-t a image-dired-display-thumbs-append C-t c image-dired-dired-comment-files C-t d image-dired-display-thumbs C-t e image-dired-dired-edit-comment-and-tags C-t f image-dired-mark-tagged-files C-t i image-dired-dired-display-image C-t j image-dired-jump-thumbnail-buffer C-t r image-dired-delete-tag C-t t image-dired-tag-files C-t x image-dired-dired-display-external C-M-d dired-tree-down C-M-n dired-next-subdir C-M-p dired-prev-subdir C-M-u dired-tree-up M-$ dired-hide-all M-= dired-backup-diff M-s Prefix Command M-{ dired-prev-marked-file M-} dired-next-marked-file M-DEL dired-unmark-all-files M-s a Prefix Command M-s f Prefix Command % & dired-flag-garbage-files % C dired-do-copy-regexp % H dired-do-hardlink-regexp % R dired-do-rename-regexp % S dired-do-symlink-regexp % d dired-flag-files-regexp % g dired-mark-files-containing-regexp % l dired-downcase % m dired-mark-files-regexp % r dired-do-rename-regexp % u dired-upcase * C-n dired-next-marked-file * C-p dired-prev-marked-file * ! dired-unmark-all-marks * % dired-mark-files-regexp * * dired-mark-executables * / dired-mark-directories * ? dired-unmark-all-files * @ dired-mark-symlinks * c dired-change-marks * m dired-mark * s dired-mark-subdir-files * t dired-toggle-marks * u dired-unmark * DEL dired-unmark-backward : d epa-dired-do-decrypt : e epa-dired-do-encrypt : s epa-dired-do-sign : v epa-dired-do-verify dired-undo dired-next-line dired-previous-line dired-toggle-read-only dired-undo M-s f C-s dired-isearch-filenames M-s f ESC Prefix Command M-s a C-s dired-do-isearch M-s a ESC Prefix Command M-s f C-M-s dired-isearch-filenames-regexp M-s a C-M-s dired-do-isearch-regexp