[Top][All Lists]

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

Re: Round-tripping key definitions

From: Stefan Monnier
Subject: Re: Round-tripping key definitions
Date: Mon, 15 Nov 2021 16:10:10 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

> -(define-key global-map "\t" 'indent-for-tab-command)
> +(define-key global-map [TAB] 'indent-for-tab-command)
> +(define-key global-map [?\C-i] nil)
> +(define-key global-map [tab] nil)
> +(define-key function-key-map [?\C-i] [TAB])
> +(define-key function-key-map [tab] [TAB])

Sadly, I think this will introduce a fair bit of trouble because code
which currently does

    (define-key map "\t" ...)

expects this binding to apply to both `tab` and tty's TAB key.

We could try and fix it by having `tab` first fallback to `?\t` and only
then to `TAB`, but that currently can't be done with `function-key-map`
because `function-key-map` is not applied to its output.

We could do it via ad-hoc code (like we currently have for the
`drag-mouse-1` fallback to `mouse-1`) or we could introduce a new keymap
like `function-key-map` but that's applied repeatedly until it doesn't
apply any more (or until a binding is found).

Or maybe we could do

    (define-key function-key-map [tab] #'some-new-tab-remap)

and then make sure `some-new-tab-remap` can get enough info to figure
out whether this `tab` should be remapped to `TAB` or to `?\C-i`.

I remember wanting such a repeatedly applied keymap a few times in the
past, and similarly getting enough info for a function to be able to
decide whether to do would be useful in other cases as well.


reply via email to

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