Re: [textadept] Code: Warning on key shortcut re-assignment

From: mitchell <c....at.caladbolg.net>
Date: Fri, 24 Feb 2012 09:34:18 -0500 (Eastern Standard Time)

Hi,

On Tue, 21 Feb 2012, HyperHacker wrote:

> Just something I cooked up to warn if you assign something to a
> shortcut key that already had a previous assignment, or assign nil
> (since that usually would be by assigning something that doesn't
> really exist). Copy/edit the keys.lua module and replace:
> local keys = keys
>
> with:
> local _g_keys = keys
> local key_set_src = {}
> local keys = setmetatable({}, {
> __index = _g_keys,
> __newindex = function(t,k,v)
> local where = debug.getinfo(2, 'Sl')
> if _g_keys[k] then
> io.stderr:write(("Warning: %s:%d: re-assignment to key %s\n\t" ..
> "first defined at %s:%d\n"):format(where.short_src,
> where.currentline, tostring(k), key_set_src[k].short_src,
> key_set_src[k].currentline))
> else key_set_src[k] = where
> end
> if v == nil then io.stderr:write((
> "Warning: %s:%d: assigning nothing to key %s\n"):format(
> where.short_src, where.currentline, tostring(k)))
> end
> _g_keys[k] = v
> end,
> })
>
> This will print warnings to stderr if you overwrite a previous
> assignment or assign nothing, e.g.:
> Warning: /home/rena/.textadept/modules/textadept/keys.lua:233:
> re-assignment to key c/
> first defined at /home/rena/.textadept/modules/textadept/keys.lua:190
>
> I'm not sure how to print them to the message window this early in
> initialization, so you have to launch TA from a terminal to see the
> messages. I found this very handy to debug my custom keybindings. (Why
> doesn't this key do anything? Where is my custom binding being
> overwritten? etc)

I was able to put this at the top of my ~/.textadept/modules/keys.lua,
replace 'io.stderr:write' with 'gui.print' and I got your messages to
print when I redefined keys within said keys.lua. That way Windows and OSX
users do not need terminals.

This is useful wiki material! :)

mitchell
Received on Fri 24 Feb 2012 - 09:34:18 EST

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 12:31:28 EST