[code] [textadept] highlighting dates and hours

From: Pascal <patatetom.att.gmail.com>
Date: Fri, 31 Mar 2017 16:10:27 +0200

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...

regards, lacsaP.

-- 
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 - 10:10:27 EDT

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