mirror of
https://github.com/zyedidia/micro.git
synced 2026-03-29 22:27:13 +09:00
Add hooks for every action that's bindable
This commit is contained in:
@@ -9,7 +9,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/mitchellh/go-homedir"
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/yuin/gopher-lua"
|
|
||||||
"github.com/zyedidia/clipboard"
|
"github.com/zyedidia/clipboard"
|
||||||
"github.com/zyedidia/tcell"
|
"github.com/zyedidia/tcell"
|
||||||
)
|
)
|
||||||
@@ -614,16 +613,6 @@ func (v *View) Save() bool {
|
|||||||
} else {
|
} else {
|
||||||
messenger.Message("Saved " + v.Buf.Path)
|
messenger.Message("Saved " + v.Buf.Path)
|
||||||
}
|
}
|
||||||
for _, pl := range loadedPlugins {
|
|
||||||
if err := L.CallByParam(lua.P{
|
|
||||||
Fn: L.GetGlobal(pl + "_onSave"),
|
|
||||||
NRet: 0,
|
|
||||||
Protect: true,
|
|
||||||
}); err != nil {
|
|
||||||
// The function isn't defined by this plugin
|
|
||||||
messenger.Error(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/yuin/gopher-lua"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -10,6 +11,22 @@ var preInstalledPlugins = []string{
|
|||||||
"go",
|
"go",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call calls the lua function 'function'
|
||||||
|
// If it does not exist nothing happens, if there is an error,
|
||||||
|
// the error is returned
|
||||||
|
func Call(function string) error {
|
||||||
|
luaFunc := L.GetGlobal(function)
|
||||||
|
if luaFunc.String() == "nil" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
err := L.CallByParam(lua.P{
|
||||||
|
Fn: luaFunc,
|
||||||
|
NRet: 0,
|
||||||
|
Protect: true,
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// LoadPlugins loads the pre-installed plugins and the plugins located in ~/.config/micro/plugins
|
// LoadPlugins loads the pre-installed plugins and the plugins located in ~/.config/micro/plugins
|
||||||
func LoadPlugins() {
|
func LoadPlugins() {
|
||||||
files, _ := ioutil.ReadDir(configDir + "/plugins")
|
files, _ := ioutil.ReadDir(configDir + "/plugins")
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@@ -266,6 +268,13 @@ func (v *View) HandleEvent(event tcell.Event) {
|
|||||||
for key, action := range bindings {
|
for key, action := range bindings {
|
||||||
if e.Key() == key {
|
if e.Key() == key {
|
||||||
relocate = action(v)
|
relocate = action(v)
|
||||||
|
for _, pl := range loadedPlugins {
|
||||||
|
funcName := strings.Split(runtime.FuncForPC(reflect.ValueOf(action).Pointer()).Name(), ".")
|
||||||
|
err := Call(pl + "_on" + funcName[len(funcName)-1])
|
||||||
|
if err != nil {
|
||||||
|
TermMessage(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user