Re: [code] Highlight trailing whitespace

From: Mitchell <m.att.foicica.com>
Date: Wed, 4 Mar 2015 14:41:54 -0500 (EST)

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.
Received on Wed 04 Mar 2015 - 14:41:54 EST

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