-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathStyleCSV.lua
44 lines (38 loc) · 1.58 KB
/
StyleCSV.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
-- Anytime a file is switched, check to see if it needs styled
npp.AddEventHandler("OnSwitchFile", function(filename, bufferid)
if npp: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
return false
end)
-- A simplified lexer - style the line according to the line number
function StyleCSV(styler)
local lineStart = editor:LineFromPosition(styler.startPos)
local lineEnd = editor:LineFromPosition(styler.startPos + styler.lengthDoc)
editor:StartStyling(styler.startPos, 0 --[[ unused --]])
for line=lineStart,lineEnd,1 do
local lengthLine = editor:PositionFromLine(line+1) - editor:PositionFromLine(line)
if line % 2 == 0 then
editor:SetStyling(lengthLine, 1)
else
editor:SetStyling(lengthLine, 2)
end
end
end