Lua scripts in Skink: init.lua commands and events
Write Lua in ~/.config/skink/init.lua (%APPDATA%\skink\init.lua on Windows). It runs when Skink starts.
skink.add_command("reviewed", function() skink.insert("// reviewed\n")end)
skink.on("save", function(path) skink.message("saved " .. path)end)Restart Skink, then run :reviewed.
The API
Section titled “The API”| Call | Does |
|---|---|
skink.add_command(name, fn) |
:name ARGS calls fn(ARGS...) |
skink.on(event, fn) |
"open", "save" and "change" (after a typing pause) get the path. "key" gets an unbound key like "Ctrl-Alt-J"; return true to take it |
skink.text() skink.path() skink.lang() skink.selection() |
Read the file |
skink.cursor() / skink.set_cursor(line [, col]) |
Cursor position, 1-based |
skink.insert(text) / skink.set_text(text) |
Type at the cursors / replace the whole text |
skink.action("Save") / skink.command("goto 10") |
Run any action or command |
skink.message(text) |
Show a message. print() shows a toast |
skink.set_status(name, text) |
An item on the right of the status line (nil removes it) |
skink.pick(title, items, fn) |
A list; fn(label, index) runs on Enter |
All the edits of one call undo as one step.
Three complete examples are in docs/scripts: a word count in the status line, trim trailing spaces on save, and a TODO picker.
Limits
Section titled “Limits”- Lua 5.4 with
table,string,mathandutf8. Noiooros: files and processes go through editor commands. No coroutines. - Each call may run for 250 ms, string patterns included, then it is stopped. All scripts share 32 MB.
- Errors show as a toast; the editor keeps running.
Project scripts
Section titled “Project scripts”A project can ship .skink/init.lua. Skink asks before running it:
This project has a script (.skink/init.lua) that can edit files and run commands. Run it? (t)rust / (n)oIt asks again whenever the file changes. Scripts that come with packages are asked about the same way, once per version.