Re: [code] [textadept] Key Definition Question

From: Mitchell <m.att.foicica.com>
Date: Mon, 1 Apr 2013 14:58:35 -0400 (Eastern Daylight Time)

Hi Pete,

On Mon, 1 Apr 2013, Pete Kazmier wrote:

> I'm a Lua newbie, Emacs fan (extensibility), terminal lover (tmux) that has
> just discovered textadept so naturally I was curious if I could create a
> set of keybindings that would satisfy many years of muscle memory. After
> looking at the API and code, it seems like this is very plausible given the
> presence of key chaining.
>
> I did have a question about assigning functions to key definitions. Why use
> this 3rd form:
>
> keys['cn'] = new_buffer
> keys['cs'] = buffer.save
> keys['a('] = {_M.textadept.editing.enclose, '(', ')'}
>
>
> Instead of:
>
> keys['cn'] = new_buffer
> keys['cs'] = buffer.save
> keys['a('] = function() M.textadept.editing.enclose('(',')') end
>
>
> core/keys.lua has some automagic for the third form to replace references
> to 'buffer' and 'view', but with the anonymous function above, you don't
> need that magic. The magic also is limited to using a buffer or view as the
> first argument.
>
> What am I missing?

You're not missing anything. You can do either. Way back in the day[1] you
were only allowed to use tables. The former syntax is a relic from that.

Cheers,
Mitchell

[1]: http://foicica.com/hg/textadept/file/769a80778d85/core/keys.lua#l65

-- 
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 01 Apr 2013 - 14:58:35 EDT

This archive was generated by hypermail 2.2.0 : Tue 02 Apr 2013 - 06:30:49 EDT