Skip to main content

Module lua

Module lua 

Source
Expand description

Lua plugin support using mlua.

This module enables writing plugins in Lua for dynamic behavior beyond what TOML config plugins allow. Lua plugins can have conditional logic, access editor state, and create complex workflows.

§Example Lua Plugin

-- ~/.enya/plugins/my-plugin.lua

-- Plugin metadata (required)
plugin = {
    name = "my-lua-plugin",
    version = "0.1.0",
    description = "A Lua plugin example"
}

-- Register a command
enya.register_command("greet", {
    description = "Greet the user",
    aliases = {"hello", "hi"},
    accepts_args = true
}, function(args)
    if args == "" then
        enya.notify("info", "Hello, World!")
    else
        enya.notify("info", "Hello, " .. args .. "!")
    end
    return true
end)

-- Register a keybinding
enya.keymap("Space+x+g", "greet", "Greet user")

-- Lifecycle hooks (optional)
function on_activate()
    enya.log("info", "Plugin activated!")
end

function on_deactivate()
    enya.log("info", "Plugin deactivated!")
end

§Available API

§Registration Functions (available during load)

  • enya.register_command(name, config, callback) - Register a command
  • enya.keymap(keys, command, description, [modes]) - Register a keybinding

§Runtime Functions (available in callbacks)

  • enya.notify(level, message) - Show notification (“info”, “warn”, “error”)
  • enya.log(level, message) - Log a message
  • enya.request_repaint() - Request UI refresh
  • enya.editor_version() - Get editor version string
  • enya.is_wasm() - Check if running in WASM
  • enya.theme_name() - Get current theme name
  • enya.clipboard_write(text) - Write text to clipboard
  • enya.clipboard_read() - Read text from clipboard (returns nil if empty)
  • enya.execute(command, [args]) - Execute another command
  • enya.http_get(url, [headers]) - HTTP GET, returns {status, body, headers} or {error}
  • enya.http_post(url, body, [headers]) - HTTP POST, returns {status, body, headers} or {error}
  • enya.get_focused_pane() - Get focused pane info {pane_type, title, query, metric_name} or nil

Structs§

LuaPlugin
A Lua-based plugin.

Constants§

EXAMPLE_LUA_PLUGIN
Example Lua plugin template.