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: Spencer Baugh
Subject: Re: Buffer-local key-translation-map
Date: Wed, 17 Jan 2024 14:52:12 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> 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))))

That works great, indeed.

The filter I'm using now for evil-mode is:

(define-key function-key-map (kbd "<escape>")
 `(menu-item "" ,(kbd "ESC") :filter
   ,(lambda (cmd) (when (or (null evil-local-mode) (eq evil-state 'emacs)) 
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).

function-key-map can be buffer-local, yes.  But nothing actually uses
that variable.  Its only use is to set the parent of
local-function-key-map at startup.  And local-function-key-map can't be
buffer-local because it's a SYMBOL_FORWARDED to the current kboard
object.

This could be changed of course, perhaps by making function-key-map not
actually the parent of local-function-key-map, and teaching key
translation that if lookup in local-function-key-map fails, it should do
lookup in function-key-map.

Or maybe the parent of local-function-key-map could be changed to a
symbol instead of a direct reference?




reply via email to

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