Re: [code] Highlight trailing whitespace

From: Carlos Pita <carlosjosepita.att.gmail.com>
Date: Wed, 4 Mar 2015 16:56:58 -0300

Ok, wise knuthish advice. I just posted it to the wiki [1] after
adding a simple optimization: checking for buffer.UPDATE_CONTENT.
Cheers, Carlos.

[1] http://foicica.com/wiki/highlight-trailing-whitespace

On Wed, Mar 4, 2015 at 4:41 PM, Mitchell <m.att.foicica.com> wrote:
> Hi Carlos,
>
> On Wed, 4 Mar 2015, Carlos Pita wrote:
>
>> Following the advice of Mitchell I've tried to go further and also
>> avoid the line-by-line get_line call, so as to minimize the number of
>> string copies between C and Lua. This uses search_in_target to search
>> directly in the buffer:
>>
>> -- 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.target_start = 0
>> buffer.search_flags = buffer.FIND_REGEXP
>> buffer.indicator_current = tw_indicator
>> buffer:indicator_clear_range(0, buffer.length)
>> while true do
>> buffer.target_end = buffer.length
>> if buffer:search_in_target('[ \t]+$') == -1 then break end
>> buffer:indicator_fill_range(
>> buffer.target_start, buffer.target_end - buffer.target_start)
>> buffer.target_start = buffer.target_end
>> end
>> end)
>>
>> Mitchell, is this avoiding the copies or are they still happening
>> internally? Is it worth the extra complexity? Would you recommend a
>> grammar based approach, instead? (that's how I did it in vim some time
>> ago: a syntax rule).
>
>
> You're fine with this approach. Like I said earlier, don't lose sleep over
> this :) You have a good approach. No need to throw it into a lexer.
>
>
> 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 - 14:56:58 EST

This archive was generated by hypermail 2.2.0 : Thu 05 Mar 2015 - 06:39:10 EST