Re: [code] [textadept] Key Modes

From: Mitchell <m.att.foicica.com>
Date: Tue, 9 Jul 2019 11:43:23 -0400 (EDT)

Hi,

On Mon, 8 Jul 2019, Qwerky wrote:

> Hello.  Key bindings provide for key modes which, according to the
> documentation, provide a set of key bindings which are executed when that
> mode is active, to the exclusion of all other key bindings.
>
> Is it possible to have a mode, whose key bindings simply replace the
> same-named bindings while that mode is active, without blocking all other
> bindings[1]?
>
> An example would be a rectangular-select mode which, when active, would
> replace bindings such as caret-left-extend with
> caret-left-rectangular-extend, and so forth; but would not block other
> bindings, such as caret-left, line-down, etc. This would be extremely useful,
> in the given example, for making selection easier by not having to hold down
> the Alt key, and would also free up Alt key combinations for other functions.
>
> [1] The mode may also provide new bindings which do not exist outside the
> mode.

Yes, I'm pretty sure this is possible. In your *~/.textadept/init.lua*:

   keys.my_mode = setmetatable({
     esc = function() keys.MODE = nil end, -- exit mode
     -- keys to handle specially go here
   }, {__index = function()
     return false -- propagate everything else
   end})

Then set `keys.MODE = 'my_mode'` to initialize it (e.g. via a function bound to a key). Escape key, or whatever else you set, will go back to "normal" mode.

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 Tue 09 Jul 2019 - 11:43:23 EDT

This archive was generated by hypermail 2.2.0 : Wed 10 Jul 2019 - 06:38:41 EDT