emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Buffer-local key-translation-map


From: Stefan Monnier
Subject: Re: Buffer-local key-translation-map
Date: Sat, 23 Dec 2023 10:39:58 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> Is it OK to have key-translation-map be a buffer-local variable?

The purpose of `key-translation-map` is rather unclear nowadays.
It's not used very much.  So in principle it's a risk, but in practice
it's unlikely you'll get bitten.

> If there's a key translation in function-key-map which I wish to change
> on a per-buffer basis, is it correct to delete that key translation from
> function-key-map and add it back in a buffer-local key-translation-map?

In general no, since the two work differently.

> In graphical frames, Emacs maps <escape> to ESC with function-key-map.
> evil-mode users would usually prefer for this to not happen;

If `evil-mode` defines bindings that start with `escape`, then the
`function-key-map` mapping will (or at least should) have no effect.

> they never want to hit <escape> and have it be potentially interpreted
> as the start of a key sequence.  (For example, if an evil-mode user
> types C-x <escape>, they would prefer that the key sequence be
> aborted, not that it be interpreted as potentially the start of C-x
> M-: or other such bindings)

Hmm...

> The most obvious way to do this is simply:
> (define-key function-key-map (kbd "<escape>") nil)

The less obvious way could be something like:

    (define-key function-key-map (kbd "<escape>")
                `(menu-item "" ,(kbd "ESC")
                  :filter ,(lambda (cmd) (unless evil-mode cmd))))

> So then, the next obvious thought is to run:
> 
> (setq-local function-key-map
>  (define-keymap :parent function-key-map
>   "<escape>" nil))
> 
> in any buffer which wants to use evil-mode keybindings, and therefore
> disable mapping <escape> to ESC.
> 
> However, function-key-map and local-function-key-map cannot be
> buffer-local variables.

I can't see any technical reason why `function-key-map` can't be
buffer-local (tho it comes with the same caveats as
`key-translation-map`, and even more so because it's used more
commonly).


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]