3

when i run,

 (dolist (elt ctl-x-map)
             (print elt))

it prints,

#^[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 kmacro-keymap downcase-region (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)
#^^[3 0 pop-global-mark nil list-buffers save-buffers-kill-terminal list-directory eval-last-sexp find-file nil nil indent-rigidly nil kmacro-keymap downcase-region (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)) set-goal-column delete-blank-lines mark-page read-onl
(67108896 . pop-global-mark)

(C-left . previous-buffer)

(left . previous-buffer)

(C-right . next-buffer)

I expected Ctl-x-map to be a plain map with key sequence as key and function name as value (ex - (C-left . previous-buffer)). But the second & third entry that begins with #^^[ proves it to be wrong. Is ctl-x-map variable, some sort of map within a map ?

3

It is a full keymap, not a sparse keymap. That is, it has an entry that is a char-table.

See the Elisp manual, node Format of Keymaps.

It says this about a char-table entry (emphasis added):

char-table

If an element of a keymap is a char-table, it counts as holding bindings for all character events with no modifier bits (see modifier bits): element n is the binding for the character with code n. This is a compact way to record lots of bindings. A keymap with such a char-table is called a full keymap. Other keymaps are called sparse keymaps.

  • a char-table is a vector. why does a vector sit inside a key-map? and i see in above example - second entry, many function names like list-buffers, list-directory,find-file don't have any key mapping at all? – Madhavan Mar 2 '15 at 17:44
  • Did you read the doc I pointed you to? Yes, a char-table is a vector. It is used for a full keymap. – Drew Mar 2 '15 at 18:07
  • 1
    @MadhavanKumar the position of those names in the vector indicates the key they are bound to. – Malabarba Mar 2 '15 at 19:32
  • @Malabarba: ...which is another way of saying, as the manual puts it, "element n is the binding for the character with code n". – Drew Mar 2 '15 at 20:06
  • @Drew Indeed. ;-) Sometimes rephrasing a statement helps people understand it. – Malabarba Mar 2 '15 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.