Allow plugins to add their own runtime files

This commit is contained in:
Zachary Yedidia
2016-09-16 11:02:10 -04:00
parent f7295a25d8
commit 149fea8b76
5 changed files with 23 additions and 5 deletions

View File

@@ -319,6 +319,7 @@ func main() {
// Extension Files
L.SetGlobal("ReadRuntimeFile", luar.New(L, PluginReadRuntimeFile))
L.SetGlobal("ListRuntimeFiles", luar.New(L, PluginListRuntimeFiles))
L.SetGlobal("AddRuntimeFile", luar.New(L, PluginAddRuntimeFile))
LoadPlugins()

View File

@@ -137,8 +137,6 @@ func LoadPlugins() {
continue
}
loadedPlugins = append(loadedPlugins, pluginName)
} else if f.Name() == "help.md" {
AddRuntimeFile(FILE_Help, namedFile{realFile(fullPath), pluginName})
}
}
}

View File

@@ -2,6 +2,7 @@ package main
import (
"io/ioutil"
"os"
"path"
"path/filepath"
)
@@ -142,3 +143,13 @@ func PluginListRuntimeFiles(fileType string) []string {
}
return result
}
func PluginAddRuntimeFile(plugin, filetype, path string) {
fullpath := configDir + "/plugins/" + plugin + "/" + path
if _, err := os.Stat(fullpath); err == nil {
AddRuntimeFile(filetype, realFile(fullpath))
} else {
fullpath = "runtime/plugins/" + plugin + "/" + path
AddRuntimeFile(filetype, assetFile(fullpath))
}
}

File diff suppressed because one or more lines are too long

View File

@@ -4,8 +4,6 @@ Micro supports creating plugins with a simple Lua system. Every plugin has a
main script which is run at startup which should be placed in
`~/.config/micro/plugins/pluginName/pluginName.lua`.
If you want to add a help page for your plugin, place a markdown file in `~/.config/micro/plugins/pluginName/help.md`.
There are a number of callback functions which you can create in your
plugin to run code at times other than startup. The naming scheme is
`onAction(view)`. For example a function which is run every time the user saves
@@ -111,6 +109,16 @@ The possible methods which you can call using the `messenger` variable are:
If you want a standard prompt, just use `messenger.Prompt(prompt, "", 0)`
# Adding help files, syntax files, or colorschemes in your plugin
You can use the `AddRuntimeFile(name, type, path string)` function to add various kinds of
files to your plugin. For example, if you'd like to add a help topic and to your plugin
called `test`, you would create the `test.md` file for example, and runt the function:
```lua
AddRuntimeFile("test", "help", "test.md")
```
# Autocomplete command arguments
See this example to learn how to use `MakeCompletion` and `MakeCommand`