Re: [code] Highlight trailing whitespace

From: Carlos Pita <carlosjosepita.att.gmail.com>
Date: Wed, 4 Mar 2015 11:22:33 -0300

Good tip, Mitchell! That line looked suspicious to me, I didn't know
whether it returned a view or a copy of the buffer. Another point you may
clarify: is it necessary to reset indicator_current to the previous value?

Cheers

--
Carlos
On Mar 4, 2015 11:16 AM, "Mitchell" <m.att.foicica.com> wrote:
> Hi Carlos,
>
> On Wed, 4 Mar 2015, Carlos Pita wrote:
>
>  This is a cleanup and simplification of some gist around the web. I
>> want to share it and ask for code review from the savvy users here
>> (specially in case I'm missing an important event or doing something
>> in a very inefficient way).
>>
>> -- Highlight trailing whitespace
>> local tw_indicator = _SCINTILLA.next_indic_number()
>> buffer.indic_style[tw_indicator] = buffer.INDIC_ROUNDBOX
>> buffer.indic_fore[tw_indicator] = 0x0000FF
>> events.connect(events.UPDATE_UI, function()
>>  buffer.indicator_current = tw_indicator
>>  buffer:indicator_clear_range(0, buffer.length)
>>  for s, e in buffer:get_text():gmatch('()[ \t]+()\r?\n') do
>>    buffer:indicator_fill_range(s - 1, e - (s - 1))
>>  end
>> end)
>>
>
> For large buffers, the constant string allocation and deallocation by Lua
> due to 'get_text()' may hamper performance. One idea is to operate on lines
> directly. Something like this untested snippet may work:
>
>   for i = 0, buffer.line_count - 1 do
>     local pos = buffer:position_from_line(i)
>     local line = buffer:get_line(i)
>     local s, e = line:find('()[ \t]+()\r?\n$')
>     if s and e then
>       buffer:indicator_fill_range(pos + s - 1, pos + e - (s - 1))
>     end
>   end
>
> Cheers,
> 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.
>
>
-- 
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 04 Mar 2015 - 09:22:33 EST

This archive was generated by hypermail 2.2.0 : Thu 05 Mar 2015 - 06:38:45 EST