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

From: Pascal <patatetom.att.gmail.com>
Date: Tue, 4 Apr 2017 09:14:34 +0200

hi Mitchell,

I chose to make several simple loops (by slightly rearranging my regular
expressions) and it works perfectly, well, so again, thank you for your
advice.

can you help me on two other points?

firstly, I use the function buffer.fold_all with the action
buffer.FOLDACTION_CONTRACT : it works, but only on the first level.

events.connect(events.FILE_OPENED,
    function()
...
        buffer.fold_all(buffer.FOLDACTION_CONTRACT)
        buffer.read_only = true
    end
)

for example :

  <level1>
    blabla
    <level2>
      blabla
    </level2>
  </level1>
  <level1>
    blabla
    <level2>
      blabla
    </level2>
  </level1>

give the good display :

+ <level1>
+ <level1>

but, if I unfold the first folding, the second level is already unfolded :

  <level1>
    blabla
    <level2>
      blabla
    </level2>
  </level1>
+ <level1>

and I would like :

  <level1>
    blabla
  + <level2>
  </level1>
+ <level1>

is it possible ?
and secondly, is it possible to disable syntax highlighting, especially on
xml language, without losing folding ?

regards, lacsaP.

2017-04-02 19:43 GMT+02:00 Pascal <patatetom.att.gmail.com>:

> hi Mitchell,
>
> thank a lot for your explanations, I now better understand the results
> obtained. :-) so I wonder if it is not preferable to make several simple
> loops (one for each regexp) rather than only one with a lot of tests... what
> do you think about (speed) ?
>
> as you advise me, I moved buffer.indic_fore etc in the event
> events.VIEW_NEW : is the event events.FILE_OPENED chosen for highlighting
> a good place ?
>
> regards, lacsaP.
>
> 2017-04-02 17:35 GMT+02:00 Mitchell <m.att.foicica.com>:
>
>> Hi,
>>
>>
>> On Sat, 1 Apr 2017, Pascal wrote:
>>
>> if I try to reduce the number of loops to one like this :
>>>
>>> -- read only and highlight
>>>
>>> local date_indicator = _SCINTILLA.next_indic_number()
>>> local time_indicator = _SCINTILLA.next_indic_number()
>>>
>>> events.connect(events.FILE_OPENED,
>>> function()
>>> buffer.indic_style[date_indicator] = buffer.INDIC_ROUNDBOX
>>> buffer.indic_fore[date_indicator] = 0x0000FF
>>> buffer.indic_style[time_indicator] = buffer.INDIC_ROUNDBOX
>>> buffer.indic_fore[time_indicator] = 0x00FF00
>>> buffer.search_flags = buffer.FIND_REGEXP
>>>
>>> buffer.target_start = 0
>>> 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[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:
>>> [0-5][0-9])?')
>>> ~= -1 then buffer.indicator_current = time_indicator
>>> else break end
>>> buffer:indicator_fill_range(buffer.target_start,
>>> buffer.target_end - buffer.target_start)
>>> buffer.target_start = buffer.target_end
>>> end
>>>
>>> buffer.read_only = true
>>> end
>>> )
>>>
>>> I get this :
>>>
>>> 2017/04/01 11:59:59 2017/04/01 12:00:00 2017/04/01 12:00:00
>>> 2017.04-01 11:59:59
>>> 11:59:59
>>> 11:59:59
>>>
>>> whereas with the two loops, I've the expected result :
>>>
>>> 2017/04/01 11:59:59 2017/04/01 12:00:00 2017/04/01 12:00:00
>>> 2017.04-01 11:59:59
>>> 11:59:59
>>> 11:59:59
>>>
>>
>> When you use one loop, you are always looking for dates first. This will
>> skip over any times (due to `buffer.target_start = buffer.target_end` after
>> a date match) until no date can be found. Only then will you find any
>> subsequent times.
>>
>> If you want to do one loop, you need to check for both a date and a time
>> (resetting `buffer.target_start` between checks), and see which returns a
>> lesser position. Go with the lesser position, and continue the loop.
>>
>> So using your example input, the loop would look for both a date and a
>> time. The first date found is "2017/04/01" and the first time found is
>> "11:59:59". Since the date has a lesser position, you use that, and then
>> increment `buffer.target_start` before starting the loop again. In the next
>> iteration, the first date found is the next occurrence of "2017/04/01" and
>> the first time found is "11:59:59" (remember to reset `buffer.target_start`
>> in order to find that time; otherwise you'll get "12:00:00"). Since the
>> time has the lesser position, you use that, and then increment
>> `buffer.target_end`. And so on.
>>
>> 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 Tue 04 Apr 2017 - 03:14:34 EDT

This archive was generated by hypermail 2.2.0 : Tue 04 Apr 2017 - 06:47:09 EDT