求助:elisp key-binding 的用法

我想 打印 Control 下面所有 快捷键的组合

https://github.com/loyalpartner/emacs-keymap/blob/239b3e601e2e366743986eb3c877b72ed735c066/keymap.el#L85

我用 (keybinding (kbd “C-c”)) 得到

(keymap (keymap (38 keymap (22 . yas-visit-snippet-file) (14 . yas-new-snippet) (19 . yas-insert-snippet))) mode-specific-command-prefix)

然后去解析上面的格式 就能得到

image

当解析到 C-x 的时候 (keybinding (kbd “C-x”)) 获取的值是 Control-X-prefix 返回的值不是一个list,

我用 (symbol-function 'Control-X-prefix)

(keymap #^[nil nil keymap
#^^[3 0 pop-global-mark nil list-buffers save-buffers-kill-terminal list-directory eval-last-sexp find-file nil nil indent-rigidly nil ...] #^^[1 0 #^^[2 0
#^^[3 0 pop-global-mark nil list-buffers save-buffers-kill-terminal list-directory eval-last-sexp find-file nil nil indent-rigidly nil ...] nil nil nil nil nil nil nil nil nil nil ...] nil nil nil nil nil nil nil nil nil nil ...] nil nil nil nil nil nil nil ...] (67108912 . text-scale-adjust) (67108925 . text-scale-adjust) (67108909 . text-scale-adjust) (67108907 . text-scale-adjust) (67108923 . comment-line) (67108896 . pop-global-mark) (C-left . previous-buffer) (left . previous-buffer) (C-right . next-buffer) (right . next-buffer))

不知道有没有办法转换 把 Control-X-prefix 转成 这种 list 形式

(keymap (keymap (38 keymap (22 . yas-visit-snippet-file) (14 . yas-new-snippet) (19 . yas-insert-snippet))) mode-specific-command-prefix)

Any questions?

(emacs-version)
;; => "GNU Emacs 27.0.90 (build 3, x86_64-pc-linux-gnu, GTK+ Version 3.24.14, cairo version 1.17.3)
;;     of 2020-03-27"

(key-binding (kbd "C-x"))
;; => Control-X-prefix

(map-keymap (lambda (k v)
              (insert (format ";; %s %s\n" (key-description (vector k)) v)))
            (key-binding (kbd "C-x")))

;; C-@ pop-global-mark
;; C-b list-buffers
;; C-c save-buffers-kill-terminal
;; C-d list-directory
;; C-e eval-last-sexp
;; C-f find-file
;; TAB indent-rigidly
;; C-j dired-jump
;; C-k kmacro-keymap
;; C-l downcase-region
;; RET (keymap (108 . set-language-environment) (99 . universal-coding-system-argument) (28 . set-input-method) (88 . set-next-selection-coding-system) (120 . set-selection-coding-system) (112 . set-buffer-process-coding-system) (107 . set-keyboard-coding-system) (116 . set-terminal-coding-system) (70 . set-file-name-coding-system) (114 . revert-buffer-with-coding-system) (102 . set-buffer-file-coding-system))
;; C-n set-goal-column
;; C-o delete-blank-lines
;; C-p mark-page
;; C-q read-only-mode
;; C-r find-file-read-only
;; C-s save-buffer
;; C-t transpose-lines
;; C-u upcase-region
;; C-v find-alternate-file
;; C-w write-file
;; C-x exchange-point-and-mark
;; C-z suspend-frame
;; ESC (keymap (116 . walle-files-sudo-this-file) (102 . walle-files-sudo-find-file) (58 . repeat-complex-command) (27 . repeat-complex-command))
;; SPC rectangle-mark-mode
;; # server-edit
;; $ set-selective-display
;; ' expand-abbrev
;; ( kmacro-start-macro
;; ) kmacro-end-macro
;; * calc-dispatch
;; + balance-windows
;; - shrink-window-if-larger-than-buffer
;; . set-fill-prefix
;; 0 delete-window
;; 1 delete-other-windows
;; 2 split-window-below
;; 3 split-window-right
;; 4 ctl-x-4-prefix
;; 5 ctl-x-5-prefix
;; 6 2C-command
;; 8 (keymap (13 . insert-char))
;; ; comment-set-column
;; < scroll-left
;; = what-cursor-position
;; > scroll-right
;; X (keymap (61 . edebug-display-freq-count) (97 . abort-recursive-edit) (81 . edebug-top-level-nonstop) (113 . top-level) (87 . edebug-toggle-save-windows) (119 . edebug-where) (68 . edebug-toggle-disable-breakpoint) (88 . edebug-set-global-break-condition) (120 . edebug-set-conditional-breakpoint) (85 . edebug-unset-breakpoints) (117 . edebug-unset-breakpoint) (98 . edebug-set-breakpoint) (67 . edebug-Continue-fast-mode) (99 . edebug-continue-mode) (84 . edebug-Trace-fast-mode) (116 . edebug-trace-mode) (71 . edebug-Go-nonstop-mode) (103 . edebug-go-mode) (32 . edebug-step-mode))
;; [ backward-page
;; ] forward-page
;; ^ enlarge-window
;; ` next-error
;; a (keymap (110 . expand-jump-to-next-slot) (112 . expand-jump-to-previous-slot) (39 . expand-abbrev) (101 . expand-abbrev) (45 . inverse-add-global-abbrev) (105 keymap (108 . inverse-add-mode-abbrev) (103 . inverse-add-global-abbrev)) (43 . add-mode-abbrev) (103 . add-global-abbrev) (1 . add-mode-abbrev) (108 . add-mode-abbrev))
;; b switch-to-buffer
;; d dired
;; e kmacro-end-and-call-macro
;; f set-fill-column
;; h mark-whole-buffer
;; i insert-file
;; k kill-buffer
;; l count-lines-page
;; m compose-mail
;; n (keymap (112 . narrow-to-page) (100 . narrow-to-defun) (119 . widen) (110 . narrow-to-region))
;; o ace-window
;; q kbd-macro-query
;; r (keymap (108 . bookmark-bmenu-list) (77 . bookmark-set-no-overwrite) (109 . bookmark-set) (98 . bookmark-jump) (102 . frameset-to-register) (119 . window-configuration-to-register) (43 . increment-register) (110 . number-to-register) (114 . copy-rectangle-to-register) (103 . insert-register) (105 . insert-register) (120 . copy-to-register) (115 . copy-to-register) (106 . jump-to-register) (32 . point-to-register) (67108896 . point-to-register) (0 . point-to-register) (27 keymap (119 . copy-rectangle-as-kill)) (78 . rectangle-number-lines) (116 . string-rectangle) (111 . open-rectangle) (121 . yank-rectangle) (100 . delete-rectangle) (107 . kill-rectangle) (99 . clear-rectangle))
;; s save-some-buffers
;; t (keymap (6 . find-file-other-tab) (102 . find-file-other-tab) (98 . switch-to-buffer-other-tab) (13 . tab-bar-select-tab-by-name) (114 . tab-rename) (109 . tab-move) (111 . tab-next) (48 . tab-close) (49 . tab-close-other) (50 . tab-new) (100 . dired-other-tab))
;; u undo
;; v vc-prefix-map
;; z repeat
;; { shrink-window-horizontally
;; } enlarge-window-horizontally
;; DEL backward-kill-sentence
;; C-0 text-scale-adjust
;; C-= text-scale-adjust
;; C-- text-scale-adjust
;; C-+ text-scale-adjust
;; C-; comment-line
;; C-SPC pop-global-mark
;; <C-left> previous-buffer
;; <left> previous-buffer
;; <C-right> next-buffer
;; <right> next-buffer

不要把keymap当成alist来用,因为keymap 不是 alist

1赞

原来 keymap 居然可以直接遍历,我还大费周章的自己解析 :upside_down_face: