]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/plugin.go
Rename to tabstospaces for consistency
[micro.git] / cmd / micro / plugin.go
index add2476a6060b92473846b90d039e7720ed42811..4138e3a0c579a9fc07758ce8746186ac01a28665 100644 (file)
@@ -1,11 +1,34 @@
 package main
 
 import (
+       "github.com/yuin/gopher-lua"
        "io/ioutil"
 )
 
 var loadedPlugins []string
 
+var preInstalledPlugins = []string{
+       "go",
+       "linter",
+}
+
+// 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
 func LoadPlugins() {
        files, _ := ioutil.ReadDir(configDir + "/plugins")
        for _, plugin := range files {
@@ -23,4 +46,18 @@ func LoadPlugins() {
                        }
                }
        }
+
+       for _, pluginName := range preInstalledPlugins {
+               plugin := "runtime/plugins/" + pluginName + "/" + pluginName + ".lua"
+               data, err := Asset(plugin)
+               if err != nil {
+                       TermMessage("Error loading pre-installed plugin: " + pluginName)
+                       continue
+               }
+               if err := L.DoString(string(data)); err != nil {
+                       TermMessage(err)
+                       continue
+               }
+               loadedPlugins = append(loadedPlugins, pluginName)
+       }
 }