mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-19 23:37:13 +09:00
Auto prefix for plugin functions
YOu no longer have to prefix all functions in a plugin with the plugin name (linter_onSave). This will now be done automatically using lua's setfenv. When passing a function as a callback to a editor function, make sure to prefix the plugin name (linter.onExit, or go.goimports) so that micro knows which plugin to call the function from.
This commit is contained in:
@@ -5,20 +5,20 @@ if GetOption("gofmt") == nil then
|
||||
AddOption("gofmt", true)
|
||||
end
|
||||
|
||||
MakeCommand("goimports", "go_goimports")
|
||||
MakeCommand("gofmt", "go_gofmt")
|
||||
MakeCommand("goimports", "go.goimports")
|
||||
MakeCommand("gofmt", "go.gofmt")
|
||||
|
||||
function go_onSave()
|
||||
function onSave()
|
||||
if CurView().Buf.FileType == "Go" then
|
||||
if GetOption("goimports") then
|
||||
go_goimports()
|
||||
goimports()
|
||||
elseif GetOption("gofmt") then
|
||||
go_gofmt()
|
||||
gofmt()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function go_gofmt()
|
||||
function gofmt()
|
||||
CurView():Save()
|
||||
local handle = io.popen("gofmt -w " .. CurView().Buf.Path)
|
||||
local result = handle:read("*a")
|
||||
@@ -27,16 +27,16 @@ function go_gofmt()
|
||||
CurView():ReOpen()
|
||||
end
|
||||
|
||||
function go_goimports()
|
||||
function goimports()
|
||||
CurView():Save()
|
||||
local handle = io.popen("goimports -w " .. CurView().Buf.Path)
|
||||
local result = go_split(handle:read("*a"), ":")
|
||||
local result = split(handle:read("*a"), ":")
|
||||
handle:close()
|
||||
|
||||
CurView():ReOpen()
|
||||
end
|
||||
|
||||
function go_split(str, sep)
|
||||
function split(str, sep)
|
||||
local result = {}
|
||||
local regex = ("([^%s]+)"):format(sep)
|
||||
for each in str:gmatch(regex) do
|
||||
|
||||
Reference in New Issue
Block a user