Re: [code][textadept] New keybinding syntax

From: Mitchell <m.att.foicica.com>
Date: Mon, 29 Jun 2020 12:08:19 -0400 (EDT)

Hi Robert,

On Mon, 29 Jun 2020, Robert Gieseke wrote:

> Hi Mitchell,
>
> i quite like the new keybinding syntax you introduced in a recent commit
> [1].
>
> The Modifier+key syntax looks much easier to parse:
>
> [buffer.new] = {'ctrl+n', 'cmd+n', 'ctrl+meta+n'},
>
> I saw your 'translate' function [2]
>
> local keys = keys
> local function translate(key)
> return not CURSES and key or key:gsub('alt%+', 'meta+')
> end
>
> and was wondering whether it would be possible to expose the mappings in
> `core/keys.lua` [3] as public variables to allow for direct
> configuration of these?
>
> Something like
>
> keys.CMD = keys.ALT
>
> Or is there a technical reason why such a replacement couldn't work?

I think it just gets complicated.

An example:

1. You set `keys.CMD = keys.ALT` in your *~/.textadept/init.lua*.
2. `keys['cmd+n'] = buffer.new` is the current, default setting.
3. You press "Command+n".
4. *core/keys.lua* is given the 'n' key followed by a 'cmd' modifier.
5. It translates that modifier to 'alt' and produces the sequence 'alt+n'.
6. `keys['alt+n']` is not bound to anything, so it has to loop through modifiers to see what else is assigned to 'alt', perform a translation (e.g. 'alt+n' -> 'cmd+n'), and check for a binding.
7. Eventually it finds `keys['cmd+n']` is bound to `buffer.new` and calls it.

That seems like a lot of work to do for each keypress. Keep in mind that Textadept also needs to check for language-specific keys, so there are potentially 4 lookups and 2 translations to try before finding a binding or not.

So I think this is possible, but I'm not sure it's worth it.

Cheers,
Mitchell

-- 
You are subscribed to code.att.foicica.com.
To change subscription settings, send an e-mail to code+help.att.foicica.com.
To unsubscribe, send an e-mail to code+unsubscribe.att.foicica.com.
Received on Mon 29 Jun 2020 - 12:08:19 EDT

This archive was generated by hypermail 2.2.0 : Tue 30 Jun 2020 - 06:35:08 EDT