Re: [code] Highlight trailing whitespace

From: Carlos Pita <>
Date: Wed, 4 Mar 2015 16:26:26 -0300

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.target_start, buffer.target_end - buffer.target_start)
    buffer.target_start = buffer.target_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 are subscribed to
To change subscription settings, send an e-mail to
To unsubscribe, send an e-mail to
Received on Wed 04 Mar 2015 - 14:26:26 EST

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