Add boolean option to actions to disable the lua callback

This commit is contained in:
Zachary Yedidia
2016-08-17 14:16:27 -04:00
parent 8a58506c72
commit d17cc0f628
11 changed files with 395 additions and 250 deletions

View File

@@ -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)