Re: [code] Auto-pairing feature request

From: Mitchell <m.att.foicica.com>
Date: Wed, 30 Jan 2013 12:24:49 -0500 (Eastern Standard Time)

Ryan,

On Wed, 30 Jan 2013, Ryan Pusztai wrote:

> Hi Mitchell,
>
> On Wed, Jan 30, 2013 at 10:41 AM, Mitchell <m.att.foicica.com> wrote:
>
>> Hi Ryan,
>> <...>
>>
> Yes, you can probably do it on your own. In an events.CHAR_ADDED event you
>> can check for ')', ']', '}' and see if buffer.char_at[buffer.current_**pos]
>> is the char and if buffer:brace_match(buffer.**current_pos) ~= -1, call
>> buffer:char_right().
>>
>> That's my initial thought, but I'll have to first see if that works and
>> then iron out the rough edges.
>>
>
>
> I worked on this a bit only using your instructions and here is a quick and
> dirty approach.
>
> Add this to your init.lua
> -----------------------
> events.connect( "char_added",
> function( char )
> local achar = string.char( char ) -- Convert to ASCII
>
> if achar == ")" or achar == "]" or achar == "}" then
> local buffer = buffer
> if buffer.char_at[buffer.current_pos] == char and buffer:brace_match(
> buffer.current_pos ) ~= -1 then
> buffer:char_right()
> buffer:delete_back()
>
> return
> end
> end
> end )
> ----------------------
>
> I can't figure out how to do a similar thing for the double-quote(") and
> single-quote(') characters. brace_match() does not match those characters
> so it never works. Thoughts?

You could use buffer.style_at[] to get the style on either side of the
current position. If all match, then you are inside a string and do not
skip over the quote. If the style before the current pos matches the style
at the current pos, you are at the end of a string and can skip over the
closing quote.

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 Wed 30 Jan 2013 - 12:24:49 EST

This archive was generated by hypermail 2.2.0 : Thu 31 Jan 2013 - 06:37:25 EST