X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=runtime%2Fhelp%2Ftutorial.md;h=bdc4f6dee717073b96dfda625ec6b82e8bacb8a7;hb=d965e8de4f44c190ad27b343bebc0c7dae414837;hp=8aa473da00286f91d1b3442259105f368630332c;hpb=50ff45c213a15428f2b33ca72d6fafb679a09137;p=micro.git diff --git a/runtime/help/tutorial.md b/runtime/help/tutorial.md index 8aa473da..bdc4f6de 100644 --- a/runtime/help/tutorial.md +++ b/runtime/help/tutorial.md @@ -70,31 +70,40 @@ what actions are available, see the `keybindings` help topic (`> help keybinding If you need more power than the json files provide, you can use the `init.lua` file. Create it in `~/.config/micro`. This file is a lua file that is run when -micro starts and is essentially a one-file plugin. +micro starts and is essentially a one-file plugin. The plugin name is `initlua`. -I'll show you how to use the `init.lua` file by giving an example of how to -create a binding to `CtrlR` which will execute `go run` on the current file, +This example will show you how to use the `init.lua` file by creating +a binding to `CtrlR` which will execute the bash command `go run` on the current file, given that the current file is a Go file. You can do that by putting the following in `init.lua`: ```lua -function gorun() - local buf = CurView().Buf -- The current buffer +local config = import("micro/config") +local shell = import("micro/shell") + +function init() + -- true means overwrite any existing binding to CtrlR + -- this will modify the bindings.json file + config.TryBindKey("CtrlR", "lua:initlua.gorun", true) +end + +function gorun(bp) + local buf = bp.Buf if buf:FileType() == "go" then - HandleShellCommand("go run " .. buf.Path, true, true) -- the first true means don't run it in the background + -- the true means run in the foreground + -- the false means send output to stdout (instead of returning it) + shell.RunInteractiveShell("go run " .. buf.Path, true, false) end end - -BindKey("CtrlR", "init.gorun") ``` -Alternatively, you could get rid of the `BindKey` line, and put this line in the +Alternatively, you could get rid of the `TryBindKey` line, and put this line in the `bindings.json` file: ```json { - "CtrlR": "init.gorun" + "CtrlR": "lua:initlua.gorun" } ```