-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathsyntaxcheckontype.lua
54 lines (46 loc) · 1.83 KB
/
syntaxcheckontype.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
local lasterr
local markername, marker
local function clean(editor)
ide:GetStatusBar():SetStatusText("")
if marker then editor:MarkerDeleteAll(marker) end -- remove markers
end
local function setmarker(editor, cfgmark)
marker = ide:AddMarker(markername,
cfgmark.ch or wxstc.wxSTC_MARK_CHARACTER+(' '):byte(),
cfgmark.fg or {0, 0, 0},
cfgmark.bg or {255, 192, 192})
if marker then editor:MarkerDefine(ide:GetMarker(markername)) end
end
return {
name = "Syntax check while typing",
description = "Reports syntax errors while typing (on `Enter`).",
author = "Paul Kulchenko",
version = 0.41,
dependencies = 1.11,
-- use the file name as the marker name to avoid conflicts
onRegister = function(self) markername = self:GetFileName() end,
onUnRegister = function(self) ide:RemoveMarker(markername) end,
onEditorNew = function(self, editor) setmarker(editor, self:GetConfig().marker or {}) end,
onEditorLoad = function(self, editor) setmarker(editor, self:GetConfig().marker or {}) end,
onEditorCharAdded = function(self, editor, event)
if lasterr then clean(editor); lasterr = nil end
local keycode = event:GetKey()
if keycode > 255 or string.char(keycode) ~= "\n" then return end
local text = editor:GetText():gsub("^#!.-\n", "\n")
local _, err = loadstring(text, ide:GetDocument(editor):GetFileName())
if err then
local line1, err = err:match(":(%d+)%s*:(.+)")
local line2 = err and err:match("line (%d+)")
if line1 and marker then editor:MarkerAdd(line1-1, marker) end
if line2 and marker then editor:MarkerAdd(line2-1, marker) end
ide:SetStatus(err and "Syntax error: "..err or "")
lasterr = err
end
end,
}
--[[ configuration example:
syntaxcheckontype = {marker =
{ch = wxstc.wxSTC_MARK_CHARACTER+('>'):byte(),
fg = {0, 0, 0}, bg = {192, 192, 255}}
}
--]]