mirror of
https://github.com/zyedidia/micro.git
synced 2026-02-13 02:20:31 +09:00
This commit puts in place the ability for multiple views (splits). This commit also removes the editor bindings so that all bindings can be rebound by the user. I also added some more comments This fixes #109
67 lines
2.3 KiB
Lua
67 lines
2.3 KiB
Lua
if GetOption("linter") == nil then
|
|
AddOption("linter", true)
|
|
end
|
|
|
|
function linter_onSave()
|
|
if GetOption("linter") then
|
|
local ft = views[mainView+1].Buf.FileType
|
|
local file = views[mainView+1].Buf.Path
|
|
local devnull = "/dev/null"
|
|
if OS == "windows" then
|
|
devnull = "NUL"
|
|
end
|
|
if ft == "Go" then
|
|
linter_lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
|
|
linter_lint("golint", "golint " .. views[mainView+1].Buf.Path, "%f:%l:%d+: %m")
|
|
elseif ft == "Lua" then
|
|
linter_lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
|
|
elseif ft == "Python" then
|
|
linter_lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
|
|
elseif ft == "C" then
|
|
linter_lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
|
|
elseif ft == "D" then
|
|
linter_lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
|
|
elseif ft == "Java" then
|
|
linter_lint("javac", "javac " .. file, "%f:%l: error: %m")
|
|
elseif ft == "JavaScript" then
|
|
linter_lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
|
|
end
|
|
else
|
|
views[mainView+1]:ClearAllGutterMessages()
|
|
end
|
|
end
|
|
|
|
function linter_lint(linter, cmd, errorformat)
|
|
views[mainView+1]:ClearGutterMessages(linter)
|
|
|
|
local handle = io.popen("(" .. cmd .. ")" .. " 2>&1")
|
|
local lines = linter_split(handle:read("*a"), "\n")
|
|
handle:close()
|
|
|
|
local regex = errorformat:gsub("%%f", "(.+)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
|
|
for _,line in ipairs(lines) do
|
|
-- Trim whitespace
|
|
line = line:match("^%s*(.+)%s*$")
|
|
if string.find(line, regex) then
|
|
local file, line, msg = string.match(line, regex)
|
|
if linter_basename(views[mainView+1].Buf.Path) == linter_basename(file) then
|
|
views[mainView+1]:GutterMessage(linter, tonumber(line), msg, 2)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function linter_split(str, sep)
|
|
local result = {}
|
|
local regex = ("([^%s]+)"):format(sep)
|
|
for each in str:gmatch(regex) do
|
|
table.insert(result, each)
|
|
end
|
|
return result
|
|
end
|
|
|
|
function linter_basename(file)
|
|
local name = string.gsub(file, "(.*/)(.*)", "%2")
|
|
return name
|
|
end
|