Re: [textadept] Highlight matching braces

From: mitchell <c....at.caladbolg.net>
Date: Thu, 14 Oct 2010 22:51:04 -0400 (EDT)

Hi,

On Wed, 6 Oct 2010, Robert wrote:

> On Tue, Sep 28, 2010 at 4:06 PM, mitchell <c....at.caladbolg.net> wrote:
>> Robert,
>>
>>> currently ta highlights a brace if it is to the right of the cursor.
>>> To have the highlighting as well when I'm before the brace, for
>>> example to see which one was closed by the just inserted one
>>> I came up with the attached solution. There are two ways to handle
>>> being between two braces, for example Scite highlights the left, Gvim
>>> the right one. I prefer Scite's way, for the aforementioned reason.
>>> Would you consider this for inclusion?
>>
>> I like how SciTE does it too, and I would have implemented this a long time
>> ago but I am concerned about performance. 'update_ui' is called A LOT. The
>> more API calls that are made, the slower performance is. I haven't done a
>> study, so maybe I'm too paranoid.

I tried to implement this just now, but I have two problems: I use a block
caret so a ((foo)) sequence with the caret on the second '(' results in an
undesirable highlight. Also, for the caret on 'f' in (foo), brace matching
(ctrl+e) does not work. Additional fixes would be necessary. I don't think
the added complexity is worth it.

mitchell

>>
>> mitchell
>>
>
> I'm not sure if this is a good way to measure this:
> keys.ci = {
> function()
> local s = os.clock()
> for i=1,1000 do
> events.emit('update_ui')
> end
> local e = os.clock()
> buffer:add_text(string.format(" %.2f\n", e - s))
> end
> }
> Is there a better way?
>
> I can't really see a difference (with a slightly changed version to
> avoid call buffer.char_at twice):
> events.connect('update_ui',
> function() -- highlights matching braces
> local buffer = buffer
> local pos = buffer.current_pos
> if braces[buffer.char_at[pos - 1]] then
> pos = pos - 1
> local found = true
> end
> if HIGHLIGHT_BRACES and found or braces[buffer.char_at[pos]] and
> buffer:get_style_name(buffer.style_at[pos]) == 'operator' then
> local match_pos = buffer:brace_match(pos)
> if match_pos ~= -1 then
> buffer:brace_highlight(pos, match_pos)
> else
> buffer:brace_bad_light(pos)
> end
> else
> buffer:brace_bad_light(-1)
> end
> end)
>
> On my machine it's 0.3 to 0.5 seconds for 1000 emits of update_ui.
> More leaning towards 0.5 if there is a brace.
>
> Robert
>
> --
> You received this message because you are subscribed to the Google Groups "textadept" group.
> To post to this group, send email to textadept.at.googlegroups.com.
> To unsubscribe from this group, send email to textadept+unsubscribe.at.googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/textadept?hl=en.
>
>

mitchell
Received on Thu 14 Oct 2010 - 22:51:04 EDT

This archive was generated by hypermail 2.2.0 : Thu 08 Mar 2012 - 11:52:07 EST