-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEditor.SearchLinesWithMinMaxLength.lua
68 lines (64 loc) · 2.91 KB
/
Editor.SearchLinesWithMinMaxLength.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Editor.SearchLinesWithMinMaxLength.lua
-- v1.3.2.1
-- Search for lines with minimum and maximum length, excluding the first and last lines, they are often empty
-- 
-- Press the [ Min ] or [ Max ] button for to go to this line
-- Required: MessageX.lua in the modules folder
-- Keys: F3
local MessageX=require'MessageX'
local e=editor
local GetInfo,GetStringW,SetPosition = e.GetInfo,e.GetStringW,e.SetPosition
local w=win
local Utf16ToUtf8,WideCharToMultiByte = w.Utf16ToUtf8,w.WideCharToMultiByte
Macro {
description="Search Lines with MinMax Lengths";
area="Editor"; key="F3";
action=function()
local ttime=far.FarClock()
local MinText,MaxText,LineInfo,StringNumber,MinNumber,MaxNumber,MinSymbols,MaxSymbols = "","",{},1,0,0,math.huge,0
local EGI=GetInfo()
local EditorID,CodePage,TotalLines = EGI.EditorID,EGI.CodePage,EGI.TotalLines
while true do
LineInfo=GetStringW(EditorID,StringNumber,0)
if LineInfo then
local Symbols=LineInfo.StringLength
if Symbols<MinSymbols and StringNumber>1 and StringNumber<TotalLines then MinText,MinNumber,MinSymbols = LineInfo.StringText,StringNumber,Symbols
elseif Symbols>MaxSymbols then MaxText,MaxNumber,MaxSymbols = LineInfo.StringText,StringNumber,Symbols
end
StringNumber=StringNumber+1
else break
end
end
local MaxLen,MinPf,MaxPf,MinBytes,MaxBytes = 2000,"",""
if MinSymbols>MaxLen then MinText=MinText:sub(0,MaxLen) MinPf=">" end
if MaxSymbols>MaxLen then MaxText=MaxText:sub(0,MaxLen) MaxPf=">" end
if CodePage>=1200 and CodePage<=1201
then MinBytes,MaxBytes,MinPf,MaxPf = MinSymbols*2,MaxSymbols*2,"",""
else MinBytes,MaxBytes = #WideCharToMultiByte(MinText,CodePage),#WideCharToMultiByte(MaxText,CodePage)
end
MinText=Utf16ToUtf8(MinText)
MaxText=Utf16ToUtf8(MaxText)
local spc='\194\183'
local tab='\26'
local function show(s)
s=s:gsub('%d+%.?%d*','<#2s>%1<#rs>')
s=s:gsub(' +','<#1s>%1<#rs>')
s=s:gsub(' ',spc)
s=s:gsub('\t+','<#1s>%1<#rs>')
s=s:gsub('\t',tab)
return s
end
MinText=show(MinText)
MaxText=show(MaxText)
ttime=far.FarClock()-ttime
local res=MessageX(
' MinLine: <#1s>'..MinNumber..'<#rs> Symbols: <#1s>'..MinSymbols..'<#rs> Bytes: <#1s>'..MinPf..MinBytes..'<#rs>\n'..MinText..' \n\n'..
' MaxLine: <#1s>'..MaxNumber..'<#rs> Symbols: <#1s>'..MaxSymbols..'<#rs> Bytes: <#1s>'..MaxPf..MaxBytes..'<#rs>\n'..MaxText..' \n\nTime: <#9s>'..ttime..'<#rs> mcs',
'Search Lines with MinMax Lengths',
'Min;Max;Cancel','c'
)
if res==1 then SetPosition(EditorID,{CurLine=MinNumber})
elseif res==2 then SetPosition(EditorID,{CurLine=MaxNumber})
end
end
}