Re: [code] [textadept] highlighting dates and hours

From: Mitchell <m.att.foicica.com>
Date: Fri, 31 Mar 2017 18:00:14 -0400 (EDT)

Hi,

On Fri, 31 Mar 2017, Pascal wrote:

> hi,
>
> inspired by "Highlight Trailing Whitespace
> <https://foicica.com/wiki/highlight-trailing-whitespace>" from wiki, I've
> added this code to my init.lua to do the job :
>
> io.encodings[#io.encodings + 1] = 'ISO-8859-15'
> io.encodings[#io.encodings + 1] = 'CP1252'
> io.encodings[#io.encodings + 1] = 'CP850'
>
> ui.set_theme('dark')
>
> -- highlight
> local date_indicator = _SCINTILLA.next_indic_number()
> buffer.indic_style[date_indicator] = buffer.INDIC_ROUNDBOX
> buffer.indic_fore[date_indicator] = 0xFFFF00
> buffer.indic_alpha[date_indicator] = "80"
>
> local hour_indicator = _SCINTILLA.next_indic_number()
> buffer.indic_style[hour_indicator] = buffer.INDIC_ROUNDBOX
> buffer.indic_fore[hour_indicator] = 0x0000FF
> buffer.indic_alpha[hour_indicator] = "80"
>
> events.connect(events.UPDATE_UI,
> function()
> buffer.target_start = 0
> buffer.search_flags = buffer.FIND_REGEXP
> while true do
> buffer.target_end = buffer.length
> if
> buffer.search_in_target('20[1-9][0-9][-/.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])')
> ~= -1 then buffer.indicator_current = date_indicator
> elseif
> buffer.search_in_target('(0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])[-/.]20[1-9][0-9]')
> ~= -1 then buffer.indicator_current = date_indicator
> elseif
> buffer.search_in_target('(0[1-9]|[12][0-9]|3[01])[-/.](0[1-9]|1[012])[-/.]20[1-9][0-9]')
> ~= -1 then buffer.indicator_current = date_indicator
> elseif
> buffer.search_in_target('(0?[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?')
> ~= -1 then buffer.indicator_current = hour_indicator
> else break
> end
> buffer.indicator_fill_range(buffer.target_start,
> buffer.target_end - buffer.target_start)
> buffer.target_start = buffer.target_end
> end
> end
> )
>
> --view only
> events.connect(events.FILE_OPENED,
> function()
> buffer.read_only = true
> end
> )
>
> but when I open a file, only the last hour string is highlighted :-(
> but when I write in a new buffer (not read-only), the code seems working...

You should wrap your indicator settings `buffer.indic_fore = ...` in

   events.connect(events.VIEW_NEW, function()
     buffer.indic_fore = ...
     buffer.indic_alpha = ...
   end)

(Leave the `_SCINTILLA.next_indic_number()` outside.) That way your
indicator settings apply to all buffers, not just the first one.

Without any input text it's next to impossible to deduce the issue from
your source code alone. You may want to try adding
`ui.dialogs.msgbox{...}`[1] statements in your code to see which
conditionals are hit as a debugging technique.

Cheers,
Mitchell

[1]: http://foicica.com/textadept/api.html#ui.dialogs.msgbox

-- 
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 Fri 31 Mar 2017 - 18:00:14 EDT

This archive was generated by hypermail 2.2.0 : Sat 01 Apr 2017 - 06:41:45 EDT