Add support for user-created commands

Plugins can now create their own commands using the `MakeCommand`
function. Plugins can also now create their own keybindings with the
`BindKey` function. See the go plugin for an example of `MakeCommand`.
This commit is contained in:
Zachary Yedidia
2016-05-30 13:38:50 -04:00
parent 68189fd406
commit 7adcb13c08
8 changed files with 439 additions and 350 deletions

View File

@@ -152,6 +152,9 @@ Here are the possible commands that you can use.
* `run sh-command`: runs the given shell command in the background. The
command's output will be displayed in one line when it finishes running.
* `bind key action`: creates a keybinding from key to action. See the sections on
keybindings above for more info about what keys and actions are available.
### Options
Micro stores all of the user configuration in its configuration directory.

View File

@@ -5,6 +5,9 @@ if GetOption("gofmt") == nil then
AddOption("gofmt", true)
end
MakeCommand("goimports", "go_goimports")
MakeCommand("gofmt", "go_gofmt")
function go_onSave()
if views[mainView+1].Buf.FileType == "Go" then
if GetOption("goimports") then
@@ -12,21 +15,25 @@ function go_onSave()
elseif GetOption("gofmt") then
go_gofmt()
end
views[mainView+1]:ReOpen()
end
end
function go_gofmt()
views[mainView+1]:Save()
local handle = io.popen("gofmt -w " .. views[mainView+1].Buf.Path)
local result = handle:read("*a")
handle:close()
views[mainView+1]:ReOpen()
end
function go_goimports()
views[mainView+1]:Save()
local handle = io.popen("goimports -w " .. views[mainView+1].Buf.Path)
local result = go_split(handle:read("*a"), ":")
handle:close()
views[mainView+1]:ReOpen()
end
function go_split(str, sep)