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:
Zachary Yedidia
2016-06-21 17:49:57 -04:00
parent c1dadbd0c7
commit 77b6c2c486
5 changed files with 48 additions and 33 deletions

View File

@@ -3,6 +3,7 @@ package main
import (
"errors"
"io/ioutil"
"strings"
"github.com/layeh/gopher-luar"
"github.com/yuin/gopher-lua"
@@ -19,7 +20,17 @@ var preInstalledPlugins = []string{
// If it does not exist nothing happens, if there is an error,
// the error is returned
func Call(function string, args []string) error {
luaFunc := L.GetGlobal(function)
var luaFunc lua.LValue
if strings.Contains(function, ".") {
plugin := L.GetGlobal(strings.Split(function, ".")[0])
if plugin.String() == "nil" {
return errors.New("function does not exist: " + function)
}
luaFunc = L.GetField(plugin, strings.Split(function, ".")[1])
} else {
luaFunc = L.GetGlobal(function)
}
if luaFunc.String() == "nil" {
return errors.New("function does not exist: " + function)
}
@@ -78,7 +89,10 @@ func LoadPlugins() {
files, _ := ioutil.ReadDir(configDir + "/plugins/" + pluginName)
for _, f := range files {
if f.Name() == pluginName+".lua" {
if err := L.DoFile(configDir + "/plugins/" + pluginName + "/" + f.Name()); err != nil {
data, _ := ioutil.ReadFile(configDir + "/plugins/" + pluginName + "/" + f.Name())
pluginDef := "\nlocal P = {}\n" + pluginName + " = P\nsetmetatable(" + pluginName + ", {__index = _G})\nsetfenv(1, P)\n"
if err := L.DoString(pluginDef + string(data)); err != nil {
TermMessage(err)
continue
}
@@ -95,7 +109,8 @@ func LoadPlugins() {
TermMessage("Error loading pre-installed plugin: " + pluginName)
continue
}
if err := L.DoString(string(data)); err != nil {
pluginDef := "\nlocal P = {}\n" + pluginName + " = P\nsetmetatable(" + pluginName + ", {__index = _G})\nsetfenv(1, P)\n"
if err := L.DoString(pluginDef + string(data)); err != nil {
TermMessage(err)
continue
}

View File

@@ -260,7 +260,7 @@ func runtimeHelpHelpMd() (*asset, error) {
return a, nil
}
var _runtimePluginsGoGoLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xa4\x52\xdd\x6a\xdb\x30\x14\xbe\xf7\x53\x1c\x04\x03\x69\xf3\xfc\x00\x86\x5c\x6c\x81\xe5\x6a\x64\x6c\x63\x37\x63\x1b\x9a\x7d\x1c\x8b\xca\x92\x91\xe4\xa6\xa5\xf4\xdd\x7b\xfc\x93\x54\x76\x5c\x4a\xa8\x6e\x8c\x8f\xbe\xf3\xfd\x21\x55\xc1\x0e\xc3\xbe\x0d\xca\x1a\xce\x0e\x56\x35\xad\x75\xc1\x33\x01\x9b\x0d\x18\xa5\x21\xd4\x68\x12\xa0\xf3\xa9\x2c\x2f\x61\x29\x54\x52\x7b\x14\x09\x9a\x32\x59\x72\x55\x4d\x78\x8d\xa7\x87\xa4\x10\x5c\x37\x51\x24\x5f\xe5\x0d\x6e\x6d\xd3\x48\x53\xce\x75\xe8\xe7\x5f\x64\x6f\x09\x1c\x89\x46\xd0\xa0\x9b\x24\x55\x67\x8a\x5e\x07\x68\x68\xcd\x0f\x79\x8b\x5c\x0c\x0e\xc8\xe7\xb6\x73\xbf\x14\x1e\xb9\xc8\x3e\x77\x55\xf6\x45\x69\xfc\x79\xdf\x62\xef\x95\xed\x2c\x7b\x36\x3b\xc1\x5f\xa8\x68\x06\xeb\x4f\xec\x71\x12\xeb\x0f\x52\x45\xeb\xe5\xac\x33\xd0\x5d\xbc\x4d\xbd\x9c\xbe\x43\x47\x71\xb0\x18\x7c\x0e\x95\x47\x61\xb5\x2d\xa4\x86\x9a\x6a\xd2\x94\x0f\x94\xcd\x5a\xdb\xe2\xc9\x02\x7c\x3c\x02\x83\x2c\x5b\x14\xf2\x4d\x86\x3a\x5e\x77\xe8\x3b\x1d\x68\x7d\xe4\xc9\x1d\x4a\x6a\xfd\xbd\x64\x23\x68\x9a\x16\xda\xfa\x5e\x76\x61\xe6\x3b\xee\x7b\x41\xb1\x66\x7e\xde\xd5\xb5\x01\xa6\xed\x6b\x43\x90\xb2\x6f\xb5\x0a\xfc\x22\x0d\xbd\xa0\xfc\x8d\x99\x46\x66\x1f\x5c\x0a\x1e\xdb\x55\xfd\x87\xc7\xd9\xf4\x80\x77\x34\xe4\x8c\xff\xfe\xfb\xce\xff\xf9\x20\x98\xc8\x2b\xeb\x1a\x49\x2c\x27\x02\xfa\x07\x94\x45\x0d\xca\x00\x51\xe7\x07\xba\x2d\x6a\x3e\xec\x0a\x28\xed\xf9\xad\x04\xf9\x5f\x63\xa6\x8c\x47\x17\xf8\x28\x98\x0e\x9b\x22\x89\x9f\x92\xc3\xd0\x39\x33\x39\x1a\x32\x3c\x05\x00\x00\xff\xff\x06\xfe\xea\x24\x08\x04\x00\x00")
var _runtimePluginsGoGoLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x94\x52\xdf\xca\xd3\x30\x14\xbf\xef\x53\x1c\x02\x42\xa2\xb5\x0f\x50\xd8\x85\x0e\xdc\xd5\x98\xa8\x78\x23\x0a\xb1\x3d\x6d\x83\x69\x52\x92\xd4\x29\xe2\xbb\x7b\xd2\x76\xb5\xed\xfa\xf1\xb1\xdc\x6c\x3d\xf9\x9d\xdf\x3f\xa2\x2a\x38\x61\xb8\x74\x41\x59\xc3\x59\x6d\x55\xdb\x59\x17\x3c\x13\x70\x38\x80\x51\x1a\x42\x83\x26\x01\x3a\x6f\xca\xf2\x1e\x96\x42\x25\xb5\x47\x91\xa0\x29\x93\x2d\x57\xd5\x86\xe7\x78\x22\x24\x85\xe0\xfa\x89\x22\x39\xcb\x1f\x78\xb4\x6d\x2b\x4d\xb9\xd6\xa1\x8f\x6c\x61\x6f\x0b\x1c\x89\x46\xd0\xa0\x9b\x24\x55\x6f\x8a\xa8\x03\xd6\x7c\x94\x3f\x91\x8b\x41\x9e\x4c\x1e\x7b\xf7\x59\xe1\x95\x8b\xec\x6d\x5f\x65\xef\x94\xc6\x4f\xbf\x3b\x8c\x46\xd9\xc9\xb2\xff\x4e\x27\xf8\x13\xfd\xac\x60\xf1\xcc\x97\x93\x52\x3c\x48\xe5\xec\xd7\xb2\xb3\x4e\x17\xcb\x55\xaa\xe3\xf6\x3b\x54\x33\xe7\x59\x22\xe7\x2c\xf9\x22\xa3\xb6\x85\xd4\xd0\x50\x35\x9a\x62\x81\xb2\x59\x67\x3b\xbc\x89\xc3\xeb\x2b\x30\xc8\xb2\x4d\x0f\xef\x65\x68\x96\xeb\x0e\x7d\xaf\x03\xad\x8f\x3c\xb9\x43\x49\x4d\xbf\x94\x6c\x04\x4d\xd3\x42\x5b\x1f\x65\x37\x66\x3e\xe0\x25\x0a\x8a\x3b\xe7\xeb\x8a\x1e\x75\x3f\x6d\x3f\x9a\xc0\x77\x5a\x05\x7e\x97\x83\xde\x4b\xfe\x58\x9a\x38\x6e\xd1\x7b\x34\x35\xba\xfc\x4c\xff\x64\x8d\x7c\xcf\xc5\x3a\xf7\x68\xc0\x07\x97\x82\xc7\x6e\xd7\xe3\x9f\xbf\xab\x69\x8d\xbf\x68\xc8\x19\xff\xf2\xed\x85\xff\xfa\x4a\x30\x91\x57\xd6\xb5\x92\x58\x6e\x04\xf4\x0d\x28\x8b\x06\x14\x09\x04\x97\xd7\x74\x5b\x34\x7c\xd8\x15\x50\xda\xf9\x25\x05\xf9\x5d\x63\xa6\x8c\x47\x17\xf8\x28\x98\x0e\x9b\x22\x59\x3e\x34\x87\xa1\x77\x66\x72\x34\x04\xf8\x17\x00\x00\xff\xff\x9b\x88\x7c\xa9\x1d\x04\x00\x00")
func runtimePluginsGoGoLuaBytes() ([]byte, error) {
return bindataRead(
@@ -275,12 +275,12 @@ func runtimePluginsGoGoLua() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "runtime/plugins/go/go.lua", size: 1032, mode: os.FileMode(420), modTime: time.Unix(1465426148, 0)}
info := bindataFileInfo{name: "runtime/plugins/go/go.lua", size: 1053, mode: os.FileMode(420), modTime: time.Unix(1466545678, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _runtimePluginsLinterLinterLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x55\x5d\x8f\xa3\x36\x14\x7d\xcf\xaf\xb0\xac\x22\xc1\x0e\x30\xd2\x3e\x46\xca\xc3\x76\xda\x8e\xb4\xda\x76\x57\xca\xb6\xfb\xd0\x8f\x91\x03\x97\xc4\x1d\x63\x23\xdb\x4c\x12\x55\xfd\xef\xbd\xb6\x09\x01\x86\x0c\x45\xbb\xb1\xc7\xdc\x7b\xce\xfd\x38\x5c\xf3\x8a\x3c\x82\xfd\xdc\x58\xae\x64\x4c\x05\x97\x16\x34\x4d\xc8\x66\x43\x24\x17\xc4\x1e\x40\xae\x08\x3e\x1f\xca\x72\x62\x93\x12\xab\x5b\x48\x56\x20\xcb\xd5\xaa\x6a\x65\xe1\xde\x92\xf0\xf2\x49\xc9\x2d\x7b\x81\x38\xf1\xbe\x37\x28\x7a\x6c\xf7\x08\x55\x30\x41\x2a\x4b\x36\xe4\xa1\xd5\xbf\x71\x38\xc6\x49\xfe\x7d\x5b\xe5\x3f\x71\x01\x5f\xcf\x0d\x4c\x2d\xf1\xf8\x95\xed\x17\x66\x0f\x13\xbb\x12\x5e\x64\x2b\x04\x9a\xd2\x7b\xdc\xdf\xbb\x3f\x68\x6f\x83\x91\x7d\xde\xba\x5c\xe9\x91\xcb\x52\x1d\x0d\x1d\x47\xe5\x9e\x01\xc2\x2f\xbf\x7e\xba\xfa\xba\xbc\x07\x38\x2e\x74\x34\x79\x54\x33\x10\x5d\x51\xdc\x12\xd3\xbd\xda\xb5\x5c\x94\x58\x3f\xdc\x12\xbf\x27\x99\x22\x94\xe4\xf9\x85\x0b\x5f\x45\xd5\x3a\x12\x6b\x12\xd5\x34\x79\x0b\xca\xad\x01\xc9\xed\x02\xc8\xeb\x9a\xf4\x78\x51\x79\x37\xc1\x04\x61\xe0\x1a\xfd\xa7\x96\x2d\x85\x2f\x5a\x56\x1c\xa0\x78\x76\xac\x97\x3d\xc9\x32\xa9\xb2\x42\x09\xa5\x43\x08\xae\x3b\xff\x9b\xf4\xcb\xd9\x1e\x94\x5c\xe2\x6d\xce\x95\x60\xcf\x60\x1c\xef\x65\x3f\x43\xf6\x16\xd1\xc3\x62\x6b\x8a\xc2\x17\xb3\x28\x48\x56\x99\xb3\xb4\xec\x94\x29\x29\xce\x24\xfb\xc6\x50\x01\xd9\x37\x38\x59\xcd\x6e\xa4\x98\xbf\x9d\xe5\x0f\x4b\xe4\x65\xed\x35\x81\x0b\x09\xa5\xdc\xa8\xaa\x42\x65\x64\x24\x3b\xe2\x3f\x8e\xa7\x13\xe6\x28\x8e\x44\x94\x2c\x11\x7f\x64\x2f\x8b\x4d\xfd\x1b\x6d\x7c\xea\x7e\x33\x57\x56\xd0\x5a\xe9\x45\x9e\x6d\xa1\x79\x63\x17\xd9\xcc\xa1\x93\x6d\xd8\x4d\xf9\x9c\x35\x90\x48\xa4\xf9\x5d\x3a\x61\xec\xbe\x39\xc7\xdc\x1f\xf6\x7a\x5f\x3f\x08\x60\xfa\x83\x10\x8f\xad\x45\xb6\x9f\xc1\x18\xb6\x07\xd3\x4d\x21\xe7\x3b\x3b\xab\x7c\x50\x61\x9f\x92\xa2\x2e\xd3\x90\x6c\xa5\x74\xcd\x6c\xf0\x9d\x50\x4c\xf0\x83\x6f\xb2\xf2\xa6\x1f\xd5\x6e\x6b\x99\xb6\xb1\x47\xa2\xb4\xfb\xdf\xcf\xc5\x1f\x4f\xdc\xa5\x7e\xe1\x1b\x51\xdd\x18\xa5\xce\x25\x56\xad\x6d\x5a\x7b\xc3\xd1\x97\xd8\xcf\x3b\x57\x3a\x83\xb3\xaa\x73\x36\x8d\x18\xf8\xd2\x3f\x24\xed\xc2\x0c\xd6\x1a\xf6\x70\x42\xeb\x01\xd8\x7a\x6f\xda\x5d\x4c\xa3\xa8\x72\x61\xc7\xf9\x5d\x42\x93\xfe\x4c\xf8\x33\x54\xfb\xf0\xb0\xbe\x1a\x7a\x68\xc4\x21\x4f\xa9\xef\x21\x97\x84\x37\x8c\x6b\x5f\x23\x30\x09\x29\x55\xdf\xb6\x2c\x23\x5f\x35\xaf\xc9\xf1\xc0\x2d\x98\x86\x15\x83\x11\xef\x7c\x7d\x0e\xb0\xc6\x90\x8a\x43\x4c\xff\x8a\xcc\x3b\xc7\x81\xcb\x77\x03\x41\xa0\xfc\x8c\xd5\x5c\xee\xf3\x0a\x07\xb8\x67\x49\x43\x56\xc9\x8c\x08\xfb\x9b\xc3\x97\x11\x7f\x6b\xb3\x47\x9e\x0e\x21\x30\x0d\x21\x46\xde\x48\xd5\x15\x75\xc7\x0c\x48\x56\x43\xfc\x7a\xd2\xfa\x8b\x73\x6a\xe6\x18\x67\xc2\x19\x0b\x6b\xa4\xa9\x5e\x8e\x56\xc9\xb6\xde\x81\xf6\x61\x25\x3e\xe0\x94\xbc\x1f\x07\x36\xbc\x88\xfa\x0f\xe4\x96\xd8\x83\x20\x30\xe3\x94\x18\x68\x92\x91\x16\x4c\x2b\xdc\xfd\xfb\xcf\xbf\x33\x0a\x89\x69\xfc\x3b\xf6\xe0\x4f\xdf\xf9\xa0\x94\xb8\x07\x70\x1d\x07\xbc\x0a\x5c\xbf\x11\x7a\xbd\x0f\xa5\xec\xfa\x30\xe8\xb9\x65\x3b\x01\x39\x97\x06\xf0\x03\x09\x84\xa9\xf7\xbc\x7e\xa2\x6e\xd5\x60\x5b\x2d\xbb\x88\xe6\xf3\x18\x17\x77\x10\xb0\x3b\xbc\xf6\xd4\x6b\xb4\x9b\x2c\x71\xfe\xee\x3e\xc1\x9f\xc4\xe9\x35\x7a\xdf\xa9\xa8\xe3\x72\x6e\x9e\xe9\xbf\x00\x00\x00\xff\xff\xed\x68\xe6\x7c\x10\x09\x00\x00")
var _runtimePluginsLinterLinterLua = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x55\x4d\x6f\xe3\x36\x10\xbd\xfb\x57\x10\x44\x05\x48\x1b\x49\x01\xf6\x68\xc0\x87\x6d\xda\x06\x58\xa4\x4d\x00\xa7\xcd\xa1\x5f\xa0\xa5\x91\xcd\x86\x22\x05\x92\x8a\x6d\x14\xfd\xef\x1d\x92\xb2\x2c\xc9\x56\xb2\x42\x62\xd2\xe4\xcc\x7b\xf3\xf1\x3c\xe2\x15\xb9\x07\xfb\xd8\x58\xae\x64\x4c\x05\x97\x16\x34\x4d\xc8\x6a\x45\x24\x17\xc4\xee\x40\x2e\x08\x3e\x5f\xca\x72\x62\x93\x12\xab\x5b\x48\x16\x20\xcb\xc5\xa2\x6a\x65\xe1\x6e\x89\x92\x6b\xf6\x06\x71\xe2\x9d\x66\xb0\x7b\x50\xf7\x08\x55\x30\x41\x2a\x4b\x56\xe4\xae\xd5\xbf\x71\xd8\xc7\x49\xfe\x7d\x5b\xe5\x3f\x71\x01\xcf\xc7\x06\xa6\x96\x78\x7c\x61\xfb\xc4\xec\x6e\x62\x57\xc2\x9b\x6c\x85\x40\x53\x7a\x8b\xfb\x5b\xf7\x85\xf6\x36\x18\xd9\xe3\xda\x25\x49\xf7\x5c\x96\x6a\x6f\xe8\x38\x2a\xf7\x0c\x10\x7e\xf9\xf5\xe1\xec\xeb\x12\x1e\xe0\xb8\xd0\xd1\xe4\x5e\x5d\x81\x70\x29\xc7\x74\xab\x36\x2d\x17\x25\x56\x0c\xb7\xc4\xef\x49\xa6\x08\x25\x79\x7e\x22\xc1\xab\xa8\x5a\x46\x62\x49\xa2\x9a\x26\x57\x31\xdc\x1a\x20\xdc\x2e\x78\x5f\x56\xa1\x07\x8a\xca\x9b\x09\x18\x08\x03\xe7\x78\x1f\x5a\x36\x1b\xb0\x68\x59\xb1\x83\xe2\xd5\xd1\x9d\xf6\x24\xcb\xa4\xca\x0a\x25\x94\x0e\xdc\xae\x11\xdf\xcc\xf6\x74\xb4\x3b\x25\x67\x09\x9b\x63\x25\xd8\x2b\x18\x47\x78\xda\x5f\x61\x79\x8f\xe1\x6e\xbe\xfc\x45\xe1\xeb\x56\x14\x24\xab\xcc\x51\x5a\x76\xc8\x94\x14\x47\x92\xbd\x30\x6c\x6f\xf6\x02\x07\xab\xd9\x4c\x52\xf9\xfb\x79\xfd\x30\xcb\x5a\xd6\xbe\xe1\xb8\x90\x50\xb5\x95\xaa\x2a\x6c\x7b\x46\xb2\x3d\xfe\x71\x3c\x9d\x50\x46\x71\x24\xa2\xe4\x23\xc6\xaf\xec\x6d\xbe\x71\xff\xe0\xa5\x4f\xd6\x6f\xae\x55\x10\xb4\x56\xfa\x43\x82\x75\xa1\x79\x63\xe7\x69\xcc\xae\x13\x63\xd8\x4d\x89\x9c\x19\x90\x48\xa4\xf9\x4d\x3a\xa1\xea\x7e\x3b\x8e\xb2\x3f\xec\x55\xbc\xbc\x13\xc0\xf4\x17\x21\xee\x5b\x8b\xa3\xe2\x67\x30\x86\x6d\xc1\x74\xd3\xc4\xf9\x8e\x87\x8d\x8f\x26\x8c\x95\x94\x14\x75\x99\x86\xf4\x2a\xa5\x6b\x66\x83\xd3\x04\x7b\x02\x1c\x7c\x93\x85\x37\xfd\xaa\x36\x6b\xcb\xb4\x8d\x3d\x12\xa5\xdd\x7f\xb0\xc9\x95\xfc\xf1\xc0\x5d\xce\x27\xbe\x11\xd5\x74\x08\x3a\xdb\x58\xb5\xb6\x69\xed\x8c\x87\xaf\xa6\x9f\x54\xae\x58\x06\xa7\x8c\x69\xc4\xc0\x89\xfe\x21\x69\x17\x58\x30\xd3\xb0\x85\x03\x9a\x0d\x50\x96\x5b\xd3\x6e\x62\x1a\x45\x95\x0b\x34\xce\x6f\x12\x9a\xf4\x67\xc2\x9f\xa1\x86\x87\x87\xf5\xd9\xd0\x43\x23\x0e\xf9\x3b\xf5\xed\xe2\x92\xf0\x86\x71\xed\xab\x02\x26\x21\xa5\xea\x3b\x94\x65\xe4\x59\xf3\x9a\xec\x77\xdc\x82\x69\x58\x31\x98\xca\xce\x77\xe5\x97\x25\x86\x54\xec\x62\xfa\x57\x64\x3e\x39\x0e\x5c\xbe\x1b\xf4\x1e\x25\x66\xac\xe6\x72\x9b\x57\x38\x73\x3d\x4b\x1a\xb2\x4a\xae\x08\xad\x1f\xf6\xbe\x7e\xf8\x59\x9b\xad\x2b\x52\x40\x08\x4c\x43\x88\x91\x37\x52\x6d\x98\x01\xc9\x6a\x88\x2f\x67\xa4\x7f\xbb\xf5\xf7\x8e\xe3\x4a\x00\x63\xf1\x8c\x74\xd3\x4b\xce\x2a\xd9\xd6\x1b\xd0\x3e\x90\xc4\x87\x98\x92\xcf\xe3\x50\x86\x6f\x8b\x5e\xfd\x17\x4a\x0e\xbd\xc7\xe4\x52\x62\xa0\x49\x46\x6d\x37\xad\x70\x6f\xc7\x7f\xff\xbb\x22\x86\x98\xc6\xbf\x63\xb9\xff\xf4\x4d\x0e\xa2\x88\x7b\x00\xd7\x5c\xc0\xe9\xed\x5a\x8b\xd0\xcb\x6d\xa8\x5a\x57\xf2\x41\x7b\x2d\xdb\x08\xc8\xb9\x34\x80\xea\x0f\x84\xa9\xf7\x3c\xff\xf0\xdc\xaa\xc1\xb6\x5a\x76\x11\x4d\x12\x18\x97\x73\x10\xa9\x3b\x3c\xf7\xcd\xeb\xb0\x1b\x14\x71\xfe\xe9\x36\xc1\x8f\xc4\x69\x32\xfa\xdc\x29\xa5\x23\x71\x6e\x9e\xe2\xff\x00\x00\x00\xff\xff\xa2\xe0\x7e\x83\xa0\x08\x00\x00")
func runtimePluginsLinterLinterLuaBytes() ([]byte, error) {
return bindataRead(
@@ -295,7 +295,7 @@ func runtimePluginsLinterLinterLua() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "runtime/plugins/linter/linter.lua", size: 2320, mode: os.FileMode(420), modTime: time.Unix(1466003634, 0)}
info := bindataFileInfo{name: "runtime/plugins/linter/linter.lua", size: 2208, mode: os.FileMode(420), modTime: time.Unix(1466545278, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}

View File

@@ -312,7 +312,7 @@ func (v *View) HandleEvent(event tcell.Event) {
relocate = action(v) || relocate
for _, pl := range loadedPlugins {
funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
err := Call(pl+"_on"+funcName[len(funcName)-1], nil)
err := Call(pl+".on"+funcName[len(funcName)-1], nil)
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
TermMessage(err)
}

View File

@@ -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

View File

@@ -2,7 +2,7 @@ if GetOption("linter") == nil then
AddOption("linter", true)
end
function linter_onSave()
function onSave()
if GetOption("linter") then
local ft = CurView().Buf.FileType
local file = CurView().Buf.Path
@@ -11,34 +11,34 @@ function linter_onSave()
devnull = "NUL"
end
if ft == "Go" then
linter_lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
linter_lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
lint("gobuild", "go build -o " .. devnull, "%f:%l: %m")
lint("golint", "golint " .. CurView().Buf.Path, "%f:%l:%d+: %m")
elseif ft == "Lua" then
linter_lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
lint("luacheck", "luacheck --no-color " .. file, "%f:%l:%d+: %m")
elseif ft == "Python" then
linter_lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
lint("pyflakes", "pyflakes " .. file, "%f:%l: %m")
elseif ft == "C" then
linter_lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
lint("gcc", "gcc -fsyntax-only -Wall -Wextra " .. file, "%f:%l:%d+:.+: %m")
elseif ft == "D" then
linter_lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
lint("dmd", "dmd -color=off -o- -w -wi -c " .. file, "%f%(%l%):.+: %m")
elseif ft == "Java" then
linter_lint("javac", "javac " .. file, "%f:%l: error: %m")
lint("javac", "javac " .. file, "%f:%l: error: %m")
elseif ft == "JavaScript" then
linter_lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
lint("jshint", "jshint " .. file, "%f: line %l,.+, %m")
end
else
CurView():ClearAllGutterMessages()
end
end
function linter_lint(linter, cmd, errorformat)
function lint(linter, cmd, errorformat)
CurView():ClearGutterMessages(linter)
JobStart(cmd, "", "", "linter_onExit", linter, errorformat)
JobStart(cmd, "", "", "linter.onExit", linter, errorformat)
end
function linter_onExit(output, linter, errorformat)
local lines = linter_split(output, "\n")
function onExit(output, linter, errorformat)
local lines = split(output, "\n")
local regex = errorformat:gsub("%%f", "(.+)"):gsub("%%l", "(%d+)"):gsub("%%m", "(.+)")
for _,line in ipairs(lines) do
@@ -46,14 +46,14 @@ function linter_onExit(output, linter, errorformat)
line = line:match("^%s*(.+)%s*$")
if string.find(line, regex) then
local file, line, msg = string.match(line, regex)
if linter_basename(CurView().Buf.Path) == linter_basename(file) then
if basename(CurView().Buf.Path) == basename(file) then
CurView():GutterMessage(linter, tonumber(line), msg, 2)
end
end
end
end
function linter_split(str, sep)
function split(str, sep)
local result = {}
local regex = ("([^%s]+)"):format(sep)
for each in str:gmatch(regex) do
@@ -62,7 +62,7 @@ function linter_split(str, sep)
return result
end
function linter_basename(file)
function basename(file)
local name = string.gsub(file, "(.*/)(.*)", "%2")
return name
end