Re: [code] [textadept] Hotkeys in other locale

From: Robert Gieseke <rob.g.att.web.de>
Date: Wed, 04 Sep 2013 16:10:08 +0200

Hi,

Am 9/4/13 12:49 PM, schrieb A.M. Genaev:
> Hi,
>
> The most of key bindings doesn't work when i switch to Russian.
> Is there a way to do hotkeys to be locale-independent?
>

As Mitchell wrote Textadept doesn't use key codes but chars.
You could try the following hack to use the same keybindings.

Textadept has the keys.KEYSYMS table to look up key codes greater than
255 (it's in core/keys.lua). You could add mappings from the Cyrillic
letters to the Latin ones used in short cuts.

An example:
When I switch to a Russian layout and press 's' I get 'ы'.

In my 'init.lua' I put
_G.keys.KEYSYMS[1753] = 's'

Now I can press the 'Ctrl s' or 'Cmd s' shortcuts and get the expected
behaviour, without the modifier it's still yery, 'ы'.

To get the key code you can comment out the first print statement in the
keypress function in core/keys.lua. I think these numbers are GTK
specific so you could look them up, I've found this table for PyGTK with
Hex representations:
https://github.com/nzjrs/pygtk/blob/master/gtk/keysyms.py#L827

So if you can figure out a mapping from Cyrillic to Latin letters you
could probably write a for loop otherwise you would have to add them one
by one.
Unfortunately this approach doesn't work for short cuts with shift due
to the way Textadept core/keys module handles shift keys. (This might be
worth investigating…)

Here is an example for directly assigning cyrillic short cuts:
keys.KEYSYMS[1753] = 'ы'
keys.KEYSYMS[0x6f9] = 'Ы'
keys['cы'] = buffer.save
keys['csЫ'] = buffer.save_as

Note that you have to define the KEYSYMS mappings and that for short
cuts with shift you need to explicitly use 's' for cyrillic letter, for
comparison:
keys['csЫ'] = buffer.save_as
keys['cS'] = buffer.save_as

I hope this wasn't a too confusing explanation :-)
Cheers,
Robert

-- 
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 Wed 04 Sep 2013 - 10:10:08 EDT

This archive was generated by hypermail 2.2.0 : Thu 05 Sep 2013 - 06:25:58 EDT