mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-21 00:07:16 +09:00
Add boolean option to actions to disable the lua callback
This commit is contained in:
@@ -20,8 +20,8 @@ function onRune(r)
|
||||
local curLine = v.Buf:Line(v.Cursor.Y)
|
||||
|
||||
if charAt(curLine, v.Cursor.X+1) == charAt(autoclosePairs[i], 2) then
|
||||
v:Backspace()
|
||||
v:CursorRight()
|
||||
v:Backspace(false)
|
||||
v:CursorRight(false)
|
||||
break
|
||||
end
|
||||
|
||||
@@ -57,7 +57,7 @@ function onInsertNewline()
|
||||
for i = 1, #autoNewlinePairs do
|
||||
if curRune == charAt(autoNewlinePairs[i], 1) then
|
||||
if nextRune == charAt(autoNewlinePairs[i], 2) then
|
||||
v:InsertTab()
|
||||
v:InsertTab(false)
|
||||
v.Buf:Insert(-v.Cursor.Loc, "\n")
|
||||
end
|
||||
end
|
||||
@@ -74,7 +74,7 @@ function preBackspace()
|
||||
for i = 1, #autoclosePairs do
|
||||
local curLine = v.Buf:Line(v.Cursor.Y)
|
||||
if charAt(curLine, v.Cursor.X+1) == charAt(autoclosePairs[i], 2) and charAt(curLine, v.Cursor.X) == charAt(autoclosePairs[i], 1) then
|
||||
v:Delete()
|
||||
v:Delete(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ if GetOption("gofmt") == nil then
|
||||
AddOption("gofmt", true)
|
||||
end
|
||||
|
||||
MakeCommand("goimports", "go.save", 0)
|
||||
MakeCommand("gofmt", "go.save", 0)
|
||||
MakeCommand("goimports", "go.goimports", 0)
|
||||
MakeCommand("gofmt", "go.gofmt", 0)
|
||||
|
||||
function onSave()
|
||||
if CurView().Buf.FileType == "Go" then
|
||||
@@ -19,6 +19,7 @@ function onSave()
|
||||
end
|
||||
|
||||
function gofmt()
|
||||
CurView():Save(false)
|
||||
local handle = io.popen("gofmt -w " .. CurView().Buf.Path)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
@@ -27,6 +28,7 @@ function gofmt()
|
||||
end
|
||||
|
||||
function goimports()
|
||||
CurView():Save(false)
|
||||
local handle = io.popen("goimports -w " .. CurView().Buf.Path)
|
||||
local result = split(handle:read("*a"), ":")
|
||||
handle:close()
|
||||
@@ -34,11 +36,6 @@ function goimports()
|
||||
CurView():ReOpen()
|
||||
end
|
||||
|
||||
function save()
|
||||
-- This will trigger onSave and cause gofmt or goimports to run
|
||||
CurView():Save()
|
||||
end
|
||||
|
||||
function split(str, sep)
|
||||
local result = {}
|
||||
local regex = ("([^%s]+)"):format(sep)
|
||||
|
||||
@@ -2,30 +2,37 @@ if GetOption("linter") == nil then
|
||||
AddOption("linter", true)
|
||||
end
|
||||
|
||||
MakeCommand("lint", "linter.runLinter", 0)
|
||||
|
||||
function runLinter()
|
||||
CurView():Save(false)
|
||||
local ft = CurView().Buf.FileType
|
||||
local file = CurView().Buf.Path
|
||||
local devnull = "/dev/null"
|
||||
if OS == "windows" then
|
||||
devnull = "NUL"
|
||||
end
|
||||
if ft == "Go" then
|
||||
lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
|
||||
lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
|
||||
elseif ft == "Lua" then
|
||||
lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
|
||||
elseif ft == "Python" then
|
||||
lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
|
||||
elseif ft == "C" then
|
||||
lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
|
||||
elseif ft == "D" then
|
||||
lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
|
||||
elseif ft == "Java" then
|
||||
lint("javac", "javac " .. file, "%f:%l: error: %m")
|
||||
elseif ft == "JavaScript" then
|
||||
lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
|
||||
end
|
||||
end
|
||||
|
||||
function onSave()
|
||||
if GetOption("linter") then
|
||||
local ft = CurView().Buf.FileType
|
||||
local file = CurView().Buf.Path
|
||||
local devnull = "/dev/null"
|
||||
if OS == "windows" then
|
||||
devnull = "NUL"
|
||||
end
|
||||
if ft == "Go" then
|
||||
lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
|
||||
lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
|
||||
elseif ft == "Lua" then
|
||||
lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
|
||||
elseif ft == "Python" then
|
||||
lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
|
||||
elseif ft == "C" then
|
||||
lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
|
||||
elseif ft == "D" then
|
||||
lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
|
||||
elseif ft == "Java" then
|
||||
lint("javac", "javac " .. file, "%f:%l: error: %m")
|
||||
elseif ft == "JavaScript" then
|
||||
lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
|
||||
end
|
||||
runLinter()
|
||||
else
|
||||
CurView():ClearAllGutterMessages()
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user