Numbering lines

Geoff Canyon gcanyon at gmail.com
Sat Oct 27 20:32:33 EDT 2018


And of course if retaining the order isn't critical you could just go with:

function numberText T,D
   split T by cr
   combine T by cr and D
   return T
end numberText

function unNumberText T,D
   split T by cr and D
   combine T by cr
   return T
end unNumberText

On Sat, Oct 27, 2018 at 5:29 PM Geoff Canyon <gcanyon at gmail.com> wrote:

> Sorry, missed a delimiter reference:
>
> function numberText T,D
>    split T by return
>    put "1" & D & T[1] into R
>    repeat with K = 2 to item 2 of the extents of T
>       put cr & K & D & T[K] after R --> change separator here
>    end repeat
>    return R
> end numberText
>
> On Sat, Oct 27, 2018 at 5:27 PM Geoff Canyon <gcanyon at gmail.com> wrote:
>
>> Converted to functions with the text and delimiter as paramaters for ease
>> of use:
>>
>> -- Add "inline line numbers" [-hh fecit, 2014]
>> function numberText T,D
>>    split T by return
>>    put "1:" && T[1] into R
>>    repeat with K = 2 to item 2 of the extents of T
>>       put cr & K & D & T[K] after R
>>    end repeat
>>    return R
>> end numberText
>>
>> -- Remove "inline line numbers" [-hh fecit, 2014]
>> function unNumberText T,D
>>    split T by return and D
>>    put the keys of T into K
>>    sort K numeric
>>    repeat for each line L in K
>>       put cr & T[L] after R
>>    end repeat
>>    return char 2 to -1 of R
>> end unNumberText
>>
>>
>>
>> On Sat, Oct 27, 2018 at 11:54 AM hh via use-livecode <
>> use-livecode at lists.runrev.com> wrote:
>>
>>> 1. Besides removing scroll-update, which takes most of the time, you
>>> could
>>> try the following array-methods (which are essentially from my stack
>>> http://forums.livecode.com/viewtopic.php?p=101301#p101301 , see there
>>> card "LineNums, tab "Nb2").
>>>
>>> This needs here on a medium fast machine (Mac mini, 2.5GHz) in average
>>> with LC 9.0.1 (which is at about 30% faster than LC 8.1.10 with that):
>>>
>>> 680 ms for 10000 lines to add the line numbers,
>>> 650 ms for 10000 lines to remove the line numbers,
>>> both incl. the field update (a lot of long lines are to break).
>>>
>>> -- Add "inline line numbers" [-hh fecit, 2014]
>>> -- Uses separator ": " (In LC 6 use one single char, remove below needs
>>> that)
>>> on mouseUp
>>>   lock screen; lock messages
>>>   put the millisecs into m1
>>>   set cursor to watch
>>>   put fld "IN" into T
>>>   split T by return
>>>   put the keys of T into K
>>>   sort K numeric
>>>   repeat for each line L in K
>>>     put cr & L & ": " & T[L] after S --> change separator here
>>>   end repeat
>>>   set text of fld "OUT" to char 2 to -1 of S
>>>   put -1+the num of lines of S & " lines: " & \
>>>         the millisecs -m1 & " ms" into fld "timing"
>>> end mouseUp
>>>
>>> -- Remove "inline line numbers" [-hh fecit, 2014]
>>> -- Uses separator ": " (the above, in LC 6 you have to use one single
>>> char)
>>> on mouseUp
>>>   lock screen; lock messages
>>>   put the millisecs into m1
>>>   set cursor to watch
>>>   put the text of fld "OUT" into S
>>>   split S by return and ": " --> change separator here
>>>   put the keys of S into K
>>>   sort K numeric
>>>   repeat for each line L in K
>>>     put cr & S[L] after T
>>>   end repeat
>>>   put char 2 to -1 of T into fld "IN2"
>>>   put -1+the num of lines of T & " lines: " & \
>>>         the millisecs -m1 & " ms : " & (fld "IN2" is fld "IN") into fld
>>> "timing"
>>> end mouseUp
>>>
>>> 2. All "big" editors that show line numbers never update the whole long
>>> text
>>> ** but only a few lines more than the visible line range **. Using that,
>>> nearly
>>> every LCS method (that locks the screen (and messages)) will be fast
>>> enough.
>>>
>>> > JLG wrote:
>>> > Another issue may be the line that updates the scrollbar. Try
>>> commenting out
>>> > that line as a test just to see if that's the problem. If so, you
>>> might opt
>>> > for a spinner or progress bar instead.
>>> >
>>> > > David Glasgow wrote:
>>> > > your routine is about the same as mine - 3200 lines in 106 seconds
>>> (on my
>>> > > fairly old MacBook).
>>> > >> Mark Hsu wrote:
>>> > >> <use-livecode at lists.runrev.com> wrote:
>>> > >>
>>> > >> I think your issue is where you say “put tcount & j into line
>>> tcount of it”
>>> > >> — The line X of … call is very slow as it has to count every line
>>> from 1 - X.
>>> > >> try this:
>>> > >>
>>> > >> local tBuffer
>>> > >> put 1 into tCount
>>> > >> repeat for each line j in pText
>>> > >> put tCount & j & lf after tBuffer
>>> > >> add 1 to tCount
>>> > >> set the thumbpos of scrollbar “filterprog” to tCount
>>> > >> end repeat
>>> > >> delete line -1 of tBuffer
>>> > >> put tBuffer into pText //If you want to update the initial variable
>>> with
>>> > >> the numbered lines
>>> > >> put tBuffer into field “numberedtext"
>>> > >>> David V Glasgow  wrote:
>>> > >>>
>>> > >>> Hello folks
>>> > >>>
>>> > >>> I am doing a content analysis of online chat and messaging.
>>> Sometimes very
>>> > >>> large files, thousands or even hundreds of thousands of messages.
>>> I am
>>> > >>> finding filter and find to be delightfully fast.
>>> > >>>
>>> > >>> However…. Sometimes I want to prefix each line with the line
>>> number, and do
>>> > >>> this:
>>> > >>>
>>> > >>> put 1 into tcount
>>> > >>> repeat for each line j in it
>>> > >>> put tcount & j into line tcount of it
>>> > >>> put tcount + 1 into tcount
>>> > >>> set the thumbpos of scrollbar "filterprog" to tcount
>>> > >>> end repeat
>>> > >>> put it into field “numberedtext”
>>> > >>>
>>> > >>> I use ‘it’ because of a dim memory (superstition? Myth?) from long
>>> ago that
>>> > >>> it is faster than an arbitrarily named variable. Still, the whole
>>> process
>>> > >>> is pretty darned slow. Any brilliant suggestions?
>>>
>>> _______________________________________________
>>> use-livecode mailing list
>>> use-livecode at lists.runrev.com
>>> Please visit this url to subscribe, unsubscribe and manage your
>>> subscription preferences:
>>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>>



More information about the use-livecode mailing list