HugoV you are awesome. Heresy also. And the rest of you too.
I have always wanted a way to emulate line enumeration found in my old word processor, WordPerfect. Call it a legacy from the days of hard copy

but it can start new line numbers on every page. So with this small mod you can emulate that and make the line numbers restart every time it reaches a designated number. This way I can set up my printed pages to contain N number of lines and make line number restart at N.
Also a minor mod here is you can replace the leading zero with any character, with the possible exception of ahk operators or code (haven't checked that). And the default, instead of zero, is simply A_Space. This way effectively Right-justifies the line number.
I still want a way to left-justify the line number without having all the text move to the right one char when you add another digit, which is what happens now.
So two new params in this version:
MaxNumber = maximum line number. If = 0 (default) MaxNumber = true line number
Padliner = character or number to take place of "leading zero." Default is A_Space
Code:
TF_LineNumber(TextFile, LeadingZeros = 0, MaxNumber = 0, Padliner = "A_Space")
{
TextFile := (SubStr(TextFile,1,1)="!") ? (SubStr(TextFile,2),OW=1) : TextFile
FileRead, Str, %TextFile%
If (LeadingZeros > 0)
{
StringReplace, Str, Str, `n, `n, UseErrorLevel
Lines:=ErrorLevel+1
Padding:=StrLen(Lines)
Loop, %Padding%
PadLines .= Padliner
}
Loop, Parse, Str, `n
{
If MaxNumber = 0
MaxNo = %A_Index%
Else
{
MaxNo++
If MaxNo > %MaxNumber%
Maxno = 1
}
LineNumber:= Maxno
If (LeadingZeros > 0)
{
LineNumber := Padlines LineNumber ; add padding
StringRight, LineNumber, LineNumber, StrLen(Lines) ; remove excess padding
}
OutPut .= LineNumber A_Space A_LoopField "`n"
}
Return OW ? _OverWrite_(TextFile, Output) : _MakeCopy_(TextFile, Output)
}
Pls. feel free to offer any improvements or suggestions. I'm not a fluent AHK coder, but with your help I'm improving slowly. I've only tested these a few times.