Re: [code] Auto-pairing feature request

From: Ryan Pusztai <rpusztai.att.gmail.com>
Date: Wed, 30 Jan 2013 12:16:04 -0500

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?

--
Regards,
Ryan
-- 
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:16:04 EST

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