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

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