1 if GetOption("goimports") == nil then
2 AddOption("goimports", false)
4 if GetOption("gofmt") == nil then
5 AddOption("gofmt", true)
8 MakeCommand("goimports", "go.goimports", 0)
9 MakeCommand("gofmt", "go.gofmt", 0)
11 function onViewOpen(view)
12 if view.Buf:FileType() == "go" then
13 SetLocalOption("tabstospaces", "off", view)
18 if CurView().Buf:FileType() == "go" then
19 if GetOption("goimports") then
21 elseif GetOption("gofmt") then
29 local handle = io.popen("gofmt -w " .. CurView().Buf.Path)
30 local result = handle:read("*a")
38 local handle = io.popen("goimports -w " .. CurView().Buf.Path)
39 local result = split(handle:read("*a"), ":")
45 function split(str, sep)
47 local regex = ("([^%s]+)"):format(sep)
48 for each in str:gmatch(regex) do
49 table.insert(result, each)