forked from dail8859/LuaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleCSV.lua
More file actions
Latest commit
44 lines (38 loc) · 1.58 KB
/
Copy pathStyleCSV.lua
File metadata and controls
44 lines (38 loc) · 1.58 KB
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
-- Anytime a file is switched, check to see if it needs styled
npp.AddEventHandler("OnSwitchFile", function(filename, bufferid)
ifnpp:GetExtPart() ==".csv" then
-- Add the event handler for our custom style function
npp.AddEventHandler("OnStyle", StyleCSV)
-- Make sure to set the lexer as a custom container
editor.Lexer=SCLEX_CONTAINER
-- Set up the styles as appropriate
editor.StyleBack[1] =0xffffff
editor.StyleBack[2] =0xC0D9AF
editor.StyleEOLFilled[1] =true
editor.StyleEOLFilled[2] =true
-- Clear any style and re-lex the entire document
editor:ClearDocumentStyle()
editor:Colourise(0, -1)
-- Set any other options, for this styler the caret line is ugly
editor.CaretLineVisible=false
else
-- Can remove the handler if it's not needed
npp.RemoveEventHandler("OnStyle", StyleCSV)
editor.CaretLineVisible=true
end
returnfalse
end)
-- A simplified lexer - style the line according to the line number
functionStyleCSV(styler)
locallineStart=editor:LineFromPosition(styler.startPos)
locallineEnd=editor:LineFromPosition(styler.startPos+styler.lengthDoc)
editor:StartStyling(styler.startPos, 0--[[ unused --]])
forline=lineStart,lineEnd,1do
locallengthLine=editor:PositionFromLine(line+1) -editor:PositionFromLine(line)
ifline%2==0then
editor:SetStyling(lengthLine, 1)
else
editor:SetStyling(lengthLine, 2)
end
end
end