在Emacs键映射值中显示键

Evg*_*pov 26 emacs elisp

当我查询keymap的当前值时,例如with M-: (current-local-map),它向我展示了这些内容:

Value: 
(keymap
 (S-mouse-2 . muse-follow-name-at-mouse-other-window)
 (mouse-2 . muse-follow-name-at-mouse)
 (33554445 . muse-follow-name-at-point-other-window)
 (S-return . muse-follow-name-at-point-other-window)
 (13 . muse-follow-name-at-point)
 (return . muse-follow-name-at-point)
 keymap
 (67108924 . muse-decrease-list-item-indentation)
 (67108926 . muse-increase-list-item-indentation)
 (M-return . muse-insert-list-item)
 (33554441 . muse-previous-reference)
 (S-iso-lefttab . muse-previous-reference)
 (S-tab . muse-previous-reference)
 (S-mouse-2 . muse-follow-name-at-mouse-other-window)
 (mouse-2 . muse-follow-name-at-mouse)
 (33554445 . muse-follow-name-at-point-other-window)
 (9 . muse-next-reference)
 (tab . muse-next-reference)
 (3 keymap
    (19 . muse-search)
    (2 . muse-find-backlinks)
    (tab . muse-insert-thing)
    (9 . muse-insert-thing)
    (16 . muse-project-publish)
    (6 . muse-project-find-file)
    (61 . muse-what-changed)
    (22 . muse-browse-result)
    (27 keymap
        (20 . muse-publish-this-file))
    (33554452 . muse-publish-this-file)
    (20 . muse-project-publish-this-file)
    (12 . font-lock-mode)
    (5 . muse-edit-link-at-point)
    (1 . muse-index))
 keymap
 (27 keymap
     (9 . ispell-complete-word)))
Run Code Online (Sandbox Code Playgroud)

我想要而不是数字看到更有意义的东西(control ?c) return,例如.我怎么做 ?

Gil*_*il' 24

  • 您是否知道命令C-h m(describe-mode),它通常显示当前主要和次要模式的描述,通常使用其键盘映射?

  • (substitute-command-keys "\\{foo-map}")describe-mode内部用于生成键映射的用户友好描述的内容foo-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"

  • 这是一个很好的简单答案!(简单评估(替换命令键“ \\ {foo-map}”);为什么我没有想到这一点!) (2认同)

Dre*_*rew 21

这就是你需要的:图书馆help-fns+.el.

这给了你as C-h M-k,command describe-keymap,它给你一个人类可读的描述绑定到变量的任何键映射.例如:

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


phi*_*ils 6

我只是根据Gilles的回答写了以下内容,所以我认为应该发表。

我看到Drew的describe-keymap基础非常相似,但也涵盖了其他各种用例,因此,我倾向于建议将其用作更完整的解决方案。但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)))))
Run Code Online (Sandbox Code Playgroud)


mih*_*hai 6

对于更现代的方法,请使用which-keywhich-key-show-full-keymap包中的命令。它会要求您提供键盘映射,然后向您显示该键盘映射的所有绑定,就像您按前缀键(如果启用)一样。也就是说,在迷你缓冲区中,干净整洁。which-key-mode

\n\n

从文档中:

\n\n
\n

which-key-show-full-keymap是 \xe2\x80\x98which-key.el\xe2\x80\x99 中的交互式自动加载编译 Lisp\n 函数。

\n\n
\n

(which-key-show-full-keymap KEYMAP)

\n
\n\n

使用哪个键显示 KEYMAP 中的所有绑定。KEYMAP 是从所有可用的键盘映射中交互选择的。

\n
\n


Tre*_*son 5

describe-bindings这是( ) 为您提供的一个穷人的实现C-h b,但仅限于特定的键盘映射。格式不太好,但应该可以帮助您入门:

(defun describe-keymap (keymap &optional prefix)
  (pop-to-buffer "Keymap description")
  (erase-buffer)
  (describe-keymap-impl keymap prefix))

(defun describe-keymap-impl (keymap &optional prefix)
  "show a description of keymap"
  (let (keymaps-to-process)
    (mapc (lambda (partofkeymap)
            (when prefix
              (insert (concat prefix " ")))
            (insert (key-description (list partofkeymap)))
            (insert "                ")
            (cond ((atom partofkeymap))
                  ((listp (cdr partofkeymap))
                   (insert "prefix-key")
                   (if (eq 'keymap (cadr partofkeymap))
                       (setq keymaps-to-process (cons partofkeymap keymaps-to-process))))
                  (t 
                   (insert (symbol-name (cdr partofkeymap)))))
            (insert "\n"))
          (if (and (symbolp keymap) (boundp keymap))
              (symbol-value keymap)
            keymap))
    (while keymaps-to-process
      (insert "\n\n")
      (describe-keymap-impl (cddar keymaps-to-process) (concat prefix (key-description (list (caar keymaps-to-process)))))
      (setq keymaps-to-process (cdr keymaps-to-process))))
  nil)
Run Code Online (Sandbox Code Playgroud)

我通过评估两者进行了测试:

(describe-keymap emacs-lisp-mode-map)
(describe-keymap 'emacs-lisp-mode-map)
Run Code Online (Sandbox Code Playgroud)

  • 但您不需要重新实现描述绑定。只要可用的函数——describe-bindings——就应该能够完成任何任意键盘映射所需的操作。考虑“describe-mode”:它以人类可读的形式打印文档中由 \{MAPVAR} 形式的表达式指定的键盘映射。它的输出是由“documentation”函数格式化的模式函数的文档字符串;反过来,“documentation”函数使用“substitute-command-keys”,而“substitute-command-keys”又调用“describe-bindings”来格式化源文档字符串中的 \{MAPVAR} 表达式。 (2认同)