2010-08-13 86 views
24

當我詢問鍵盤映射的電流值,例如與M-: (current-local-map),它讓我看到這些方針的東西:顯示鍵在Emacs的鍵盤映射值

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))) 

我要的不是數字看到更有意義的事情像(control ?c) return爲例。我怎麼做 ?

回答

17

這是你所需要的:庫help-fns+.el

這使你,如C-H M-ķ,指揮describe-keymap,它給你綁定到變量任何鍵映射的人類可讀的描述。例如: -

C-高中-K dired模式地圖

 

    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 

+0

這個很好! – EvgeniySharapov 2012-05-11 12:10:55

+0

無論誰:小心解釋爲什麼你低估了這個答案? – Drew 2014-01-27 21:05:27

+0

我已經安裝(通過'package-install') 'help +'和'help-fns +',但既沒有定義「C-h M-k」或「C-h C-k」,也沒有定義「describe-keymap」命令。 – 2016-05-02 13:19:50

18
  • 你知道命令C-h mdescribe-mode),通常顯示當前的主要和次要模式的說明,通常與他們的鍵盤佈局?

  • (substitute-command-keys "\\{foo-map}")是什麼describe-mode內部使用生成的關鍵圖foo-map的用戶友好的描述。

  • 如果您希望有更接近鍵映射結構的東西,API將記錄在Emacs Lisp手冊的「分類事件」中。例如,
    (event-modifiers 33554445) ==>(shift control)
    (format "%c" (event-basic-type 33554445)) ==>"m"

+1

這是一個很好的簡單的答案! (簡單評估(替代命令鍵「\\ {foo-map}」);爲什麼我沒有想到這個!) – 2010-08-13 23:57:07

2

這裏有一個人可憐的實現什麼describe-bindingsC-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) 

我測試通過評估兩種:

(describe-keymap emacs-lisp-mode-map) 
(describe-keymap 'emacs-lisp-mode-map) 
+2

但是你不應該需要重新實現describe-bindings。只有可用的函數 - describe-bindings - 應該能夠完成任意鍵盤映射所需的功能。 考慮'describe-mode':它以可讀的形式在文檔中打印由\ {MAPVAR}形式的表達式指定的鍵盤映射。它的輸出是由'documentation'函數格式化的模式函數的文檔字符串;反過來,'documentation'函數使用'substitute-command-keys',它依次調用'describe-bindings'來格式化源文檔字符串中的{{MAPVAR}表達式。 – 2010-08-13 23:37:27

+0

在研究了Elisp源代碼之後,我發現與我上面寫的以及文檔中可以推斷出的內容相反,「describe-bindings」不會將keymap作爲參數。 :( 但對於'替代-命令鍵的文檔清楚地設此: 「形式\ {MAPVAR}的子串被摘要 (由'描述-綁定作出替代MAPVAR的值的) ,作爲一個鍵盤映射。「 也許,人們可以通過將有趣的鍵盤映射作爲本地鍵盤映射安裝在臨時緩衝區中,並在那裏運行標準的」描述綁定「來克服這個問題...... – 2010-08-13 23:46:42

+0

這正是」describe- keymap',在[help-fns + .el](http://www.emacswiki.org/emacs/download/help-fns%2b.el)中可以找到。請參閱我的回答,以上。 – Drew 2013-10-12 21:08:29

0

我只是寫了下面的根據吉爾的回答,所以我想我會張貼。

我看到德魯的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)))))