Questions tagged [keymap]

A keymap is a Lisp data structure that specifies key bindings for various key sequences. A single keymap directly specifies definitions for individual events. When a key sequence consists of a single event, its binding in a keymap is the keymap's definition for that event.

A keymap is a Lisp data structure that specifies key bindings for various key sequences. A single keymap directly specifies definitions for individual events. When a key sequence consists of a single event, its binding in a keymap is the keymap's definition for that event.


The binding of a longer key sequence is found by an iterative process: first find the definition of the first event (which must itself be a keymap); then find the second event's definition in that keymap, and so on until all the events in the key sequence have been processed.

If the binding of a key sequence is a keymap, we call the key sequence a prefix key. Otherwise, we call it a complete key (because no more events can be added to it). If the binding is nil, we call the key undefined. Examples of prefix keys are C-c, C-x, and C-x 4. Examples of defined complete keys are X, enter, and C-x 4 C-f. Examples of undefined complete keys are C-x C-g, and C-c 3. See Prefix Keys, for more details.

The rule for finding the binding of a key sequence assumes that the intermediate bindings (found for the events before the last) are all keymaps; if this is not so, the sequence of events does not form a unit—it is not really one key sequence. In other words, removing one or more events from the end of any valid key sequence must always yield a prefix key. For example, C-f C-n is not a key sequence; C-f is not a prefix key, so a longer sequence starting with C-f cannot be a key sequence.

The set of possible multi-event key sequences depends on the bindings for prefix keys; therefore, it can be different for different keymaps, and can change when bindings are changed. However, a one-event sequence is always a key sequence, because it does not depend on any prefix keys for its well-formedness.

At any time, several primary keymaps are active—that is, in use for finding key bindings. These are the global map, which is shared by all buffers; the local keymap, which is usually associated with a specific major mode; and zero or more minor mode keymaps, which belong to currently enabled minor modes. (Not all minor modes have keymaps.) The local keymap bindings shadow (i.e., take precedence over) the corresponding global bindings. The minor mode keymaps shadow both local and global keymaps. See Active Keymaps, for details.

259 questions
4
votes
1 answer

How to "call" a keymap

I would like to have a function call-keymap which takes one argument km (a keymap) and such that the result of (call-keymap km) is the same as binding km to a key and then pressing that key. It should look something like this (defun call-keymap…
Joj Helfer
  • 43
  • 4
3
votes
1 answer

html-mode and custom backspace keybinding

I changed the C-h key binding to be used as backspace. (define-key key-translation-map (kbd "C-h") (kbd "< DEL >")) Now, this works flawlessy pretty much everywhere except in html-mode. When I'm in an HTML command minibuffer and press C-h, instead…
allikotsa
  • 115
  • 4
2
votes
1 answer

Read a key sequence only from a specified keymap

Is there a way to prompt the user for a key sequence, like read-key-sequence, but only including keys from a specified keymap? It seems like read-key-sequence always reads from all active keymaps.
Prismavoid
  • 41
  • 1
2
votes
1 answer

Turn keymap number back to key sequence

When viewing a keymap, prefix keys and keys in their maps are displayed as numerical values. E.g. (keymap (M-delete . sp-unwrap-sexp) (27 keymap (23 . sp-copy-sexp) (6 . *-forward-sexp))) Keys at the top-level map, as we can see, are…
Tianxiang Xiong
  • 3,878
  • 18
  • 28
2
votes
4 answers

Persistent transient keymap for mouse scrolling

I'm trying to create a transient keymap that calls calls quick-peek-hide on any key except mouse scrolling, which should function normally. I've got the following: (let ((map (make-sparse-keymap))) (define-key map [mouse-4] #'mwheel-scroll) …
Tianxiang Xiong
  • 3,878
  • 18
  • 28
2
votes
1 answer

define bindings of map a into map b

I am trying to write the following function: (defun define-keymap-onto-keymap (from-map to-map) (map-keymap (lambda (key cmd) (define-key to-map key cmd)) from-map)) My implementation above does not work in general, since the key argument…
erjoalgo
  • 863
  • 1
  • 5
  • 18
2
votes
1 answer

set-transient-map doesn't behave properly after repetitive call

I wonder what is wrong with the following code? (defvar my-forward-word-map (let ((map (make-sparse-keymap))) (define-key map (kbd "n") 'forward-word) (define-key map (kbd "p") 'my-backward-word) map)) (defvar my-backward-word-map …
Andrii Tykhonov
  • 452
  • 2
  • 13
1
vote
3 answers

How to activate a keymap without binding it to a prefix?

I have defined a keymap my-custom-key-map with some commands. This keymap lives in memory. There is no (prefix) key to activate this keymap. How to activate this keymap from lisp code? I don't want to bind this keymap to a prefix key. I want to…
Witek
  • 345
  • 1
  • 11
1
vote
0 answers

Setting Caps Lock as Hyper Key for Emacs

With an 87 key mechanical keyboard and am running Ubuntu 18.04 LTS, I want the Caps Lock Key to be the Hyper Key for Emacs. Have selected a keyboard layout Generic 101-key PC and set Make Caps Lock an additional Hyper. Yet the Caps Lock is…
Dilna
  • 1
  • 3
  • 11
1
vote
0 answers

How to handle & differentiate both click & drag mouse button events?

Is it possible to handle both click and drag for keymaps in emacs? Click: Press and release with no motion. Activates action A. Drag: Press & move (beyond a threshold). Activates another action B, which can be interactive, using the release event…
ideasman42
  • 8,786
  • 1
  • 32
  • 114
1
vote
1 answer

keymapp with kmacro keymaps

Why evals (keymapp 'kmacro-keymap) to t, and (keymapp 'kmacro-step-edit-map) to nil? Both look like ordinary keymaps to me.
jue
  • 4,576
  • 8
  • 21
1
vote
1 answer

Name of the commands in keymap creation

As I use a different language from English often I would like to create some keymaps to avoid changing languages all the time. I don't know the name of the commands that I have to place in the section interactive-command-here of the keymap:…
Adam
  • 2,447
  • 2
  • 22
  • 40
1
vote
1 answer

copy-tree on global-map

The following code (define-key (copy-tree global-map) (kbd "C-r") 'forward-char) Immediately remaps C-r to forward-char. My understanding is that copy-tree will return a deepcopy of global-map. So why does editing the resulting keymap with…
Dodgie
  • 472
  • 2
  • 14
1
vote
1 answer

Changing CTRL with CAPSLOCK

I want CTRL to be my personal modifier for my bindings and CAPSLOCK to act as CTRL only in Emacs. Most of the material out there shows you how to swap these two modifiers. However, since I use CTRL outside of Emacs regularly, changing the meaning of…
0
votes
0 answers

Temporarily modify local keymap, with failsafe to restore original

The following example is based, in part, on the idea used by set-transient-map; however, this example uses a local keymap that is only active on certain text within a buffer that was set with a text-property: 'local-map tda--dynamic-map Q: How can…
lawlist
  • 19,106
  • 5
  • 38
  • 120
1
2