mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-28 22:08:12 +09:00
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:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user