Repository navigation
Lua scripts
bluerig can be extended with Lua 5.3 or newer. Lua is not linked into the
program: the runtime is a plugin, mc-lua.so, loaded only when it is there and
switched on, so a build without Lua is the same editor with fewer extras.
Scripts add actions on keys and in menus, react to what happens in the editor,
open dialogs and full-screen views, and render files for the
Preview.
| Script | What it does |
|---|---|
render-markdown |
Draws markdown in the Preview, mermaid diagrams included |
render-json |
Draws JSON and JSON Lines in the Preview |
render-xml |
Draws XML in the Preview |
sort-selection |
Alt-t: sort the marked lines |
format-paragraph |
Alt-p: format the paragraph to a width |
insert-command-output |
Alt-u: insert the output of a shell command |
insert-literal |
Ctrl-Q: insert a key, or a code point as U+XXXX
|
insert-datetime |
Insert the date and time in a format of your choice |
base64-decode |
F11 on a block: encode or decode it as base64 |
draw-table |
The Drawing menu: draw boxes and tables with Shift and the arrows |
Options > Lua scripts lists them, the system ones and yours, and switches
each one on and off for the next start. bluerig --no-lua runs without any Lua
for once; enabled=false in [Lua] of ~/.config/bluerig/ini for good.
A script is a directory under ~/.local/share/bluerig/lua/scripts/ with a
manifest and an entry file:
~/.local/share/bluerig/lua/scripts/hello/lua.ini
~/.local/share/bluerig/lua/scripts/hello/init.lua
lua.ini:
[Lua]
id=hello
api_version=1
name=Say hello
entry=init.lua
provides=macrosinit.lua, an action on a key and in the Command menu:
mc.macro {
id = "hello",
area = "editor",
key = "Alt-z",
description = "Insert a greeting",
menu = { path = "Command", label = "Say hello" },
action = function (ev)
ev.editor:insert("Hello from Lua!")
return mc.CONSUME
end,
}A script can also listen to events (editor.open, editor.save,
editor.change, editor.cursor, editor.key, startup, shutdown), run a
process, open a dialog or a full-screen screen, and use the services of the
plugins: the viewer, for one, opens windows that show any text of the script.
A user script with the same id as a system one replaces it, which is how to change one of those above. Scripts run with your permissions: install only scripts you trust. bluerig refuses a script whose directory is a symbolic link, belongs to someone else, or can be written by others.
-
doc/LUA_PLUGINS.md: the layout of a script, events, macros, processes, screens, services. -
doc/LUA_API_REFERENCE.md: every function of themctable. -
doc/PLUGINS: the editor plugins in C that project, build, debugger, git and the others are built on.
bluerig on GitHub |
Issues |
F1 in the editor and man bluerig have the full reference.
The editor
Beside the text
Extending
About the wiki