]> git.lizzy.rs Git - micro.git/blobdiff - runtime/help/plugins.md
updated plugin help
[micro.git] / runtime / help / plugins.md
index e142d020c8d0a4d891fc5738bf488355f1c5cce7..68fed73a5e0f849251a4fed27e6bec477deaa94e 100644 (file)
@@ -66,6 +66,9 @@ as Go's GOOS variable, so `darwin`, `windows`, `linux`, `freebsd`...)
    creates a command with `name` which will call `function` when executed.
    Use 0 for completions to get NoCompletion.
 
+* `MakeCompletion(function string)`:
+   creates a `Completion` to use with `MakeCommand`.
+
 * `CurView()`: returns the current view
 
 * `HandleCommand(cmd string)`: runs the given command
@@ -104,6 +107,36 @@ The possible methods which you can call using the `messenger` variable are:
 
 If you want a standard prompt, just use `messenger.Prompt(prompt, "", 0)`
 
+# Autocomplete command arguments
+
+See this example to learn how to use `MakeCompletion` and `MakeCommand`
+
+```lua
+local function StartsWith(String,Start)
+  String = String:upper()
+  Start = Start:upper() 
+  return string.sub(String,1,string.len(Start))==Start
+end
+
+function complete(input)
+  local allCompletions = {"Hello", "World", "Foo", "Bar"}
+  local result = {}
+   
+  for i,v in pairs(allCompletions) do
+  if StartsWith(v, input) then
+       table.insert(result, v)
+     end
+   end
+   return result
+end
+
+function foo(arg)
+  messenger:Message(arg)
+end
+
+MakeCommand("foo", "example.foo", MakeCompletion("example.complete"))
+```
+
 # Default plugins
 
 For examples of plugins, see the default plugins `linter`, `go`, and `autoclose`.