]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/plugin.go
Code optimisation (#1117)
[micro.git] / cmd / micro / plugin.go
index 04e7b78b27b448221b6c382551d3934753491a3a..b335078070ba02a4bb7471efe5b276c9d0061f16 100644 (file)
@@ -61,6 +61,10 @@ func LuaFunctionBinding(function string) func(*View, bool) bool {
        }
 }
 
+// LuaFunctionMouseBinding is a function generator which takes the name of a lua function
+// and creates a function that will call that lua function
+// Specifically it creates a function that can be called as a mouse binding because this is used
+// to bind mouse actions to lua functions
 func LuaFunctionMouseBinding(function string) func(*View, bool, *tcell.EventMouse) bool {
        return func(v *View, _ bool, e *tcell.EventMouse) bool {
                _, err := Call(function, e)
@@ -114,10 +118,13 @@ func LuaFunctionComplete(function string) func(string) []string {
        }
 }
 
+// LuaFunctionJob returns a function that will call the given lua function
+// structured as a job call i.e. the job output and arguments are provided
+// to the lua function
 func LuaFunctionJob(function string) func(string, ...string) {
        return func(output string, args ...string) {
                _, err := Call(function, unpack(append([]string{output}, args...))...)
-               if err != nil {
+               if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
                        TermMessage(err)
                }
        }
@@ -146,7 +153,7 @@ func LoadPlugins() {
 
                pluginLuaName := luaPluginName(pluginName)
 
-               if err := LoadFile(pluginName, pluginName, string(data)); err != nil {
+               if err := LoadFile(pluginLuaName, pluginLuaName, string(data)); err != nil {
                        TermMessage(err)
                        continue
                }
@@ -163,3 +170,15 @@ func LoadPlugins() {
                loadedPlugins["init"] = "init"
        }
 }
+
+// GlobalCall makes a call to a function in every plugin that is currently
+// loaded
+func GlobalPluginCall(function string, args ...interface{}) {
+       for pl := range loadedPlugins {
+               _, err := Call(pl+"."+function, args...)
+               if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
+                       TermMessage(err)
+                       continue
+               }
+       }
+}