Re: [code] Highlight trailing whitespace

From: Ryan Pusztai <rpusztai.att.gmail.com>
Date: Wed, 4 Mar 2015 09:40:39 -0500

Hi Carlos,

On Wed, Mar 4, 2015 at 9:26 AM, Mitchell <m.att.foicica.com> wrote:

> Hi Carlos,
>
> On Wed, 4 Mar 2015, Carlos Pita wrote:
>
> Good tip, Mitchell! That line looked suspicious to me, I didn't know
>> whether it returned a view or a copy of the buffer.
>>
>
> Due to the nature of the bridge between Lua and C, every string you're
> working with is a copy, not a pointer to an existing one. It's important to
> keep this in mind if you care about performance. Don't lose sleep over it
> though :)
>
> Another point you may clarify: is it necessary to reset indicator_current
>> to the previous value?
>>
>
> No it's not. Users are expected to set `buffer.indicator_current` (as you
> have done) prior to setting indicators.
>
> Cheers,
> Mitchell
>
>
> 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
>>>
>>
When this is working can you post it on the wiki. I think this is a neat
feature.

Thanks.

--
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 04 Mar 2015 - 09:40:39 EST

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