mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-16 13:57:07 +09:00
Rewrite gofmt and goimports as plugins
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
go = {}
|
||||
|
||||
function onSave()
|
||||
local handle = io.popen("goimports -w view.go")
|
||||
if settings.GoImports then
|
||||
messenger:Message("Running goimports...")
|
||||
go.goimports()
|
||||
elseif settings.GoFmt then
|
||||
messenger:Message("Running gofmt...")
|
||||
go.gofmt()
|
||||
end
|
||||
end
|
||||
|
||||
function go.gofmt()
|
||||
local handle = io.popen("gofmt -w " .. view.Buf.Path)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
|
||||
view:ReOpen()
|
||||
messenger:Message(result)
|
||||
end
|
||||
|
||||
function go.goimports()
|
||||
local handle = io.popen("goimports -w " .. view.Buf.Path)
|
||||
local result = handle:read("*a")
|
||||
handle:close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user