Repository navigation
Plugin Lifecycle
This page explains what happens to a plugin from discovery to shutdown.
FerrisPad scans ~/.config/ferrispad/plugins/ at startup. Directories are sorted alphabetically. A directory is recognized as a plugin only if it contains init.lua.
All plugins share a single Lua runtime. There is one Lua instance for the entire plugin system, not one per plugin.
For each discovered plugin:
-
init.luais read and executed in the sandboxed environment - The script must return a table (the module table, conventionally
M) -
plugin.tomlis parsed for metadata, permissions, menu items, and config - The returned table is stored and reused for all future hook calls
The table returned by init.lua is the core of your plugin. It persists across all hook calls for the entire session.
local M = {}
-- This variable persists between hook calls
M.call_count = 0
function M:on_document_save(api, path, content)
M.call_count = M.call_count + 1
api:log("Save #" .. M.call_count)
end
return MLocal variables in init.lua also persist — they live in the module's closure:
local cache = {} -- persists across hooks, private to this plugin
local M = {}
function M:on_document_open(api, path)
cache[path] = os.clock()
end
return Minit(api) is called once after all plugins are loaded, before any other hook. Use it for setup — checking tool availability, initializing state, logging.
function M:init(api)
M.has_ruff = api:command_exists("ruff")
api:log("Plugin ready, ruff: " .. tostring(M.has_ruff))
endinit is not called for disabled plugins.
After init, hooks are called as the user interacts with the editor. Each hook call:
- Resets the instruction counter (fresh 1M instruction budget)
- Looks up the hook function on your module table
- If the function exists, calls it with the appropriate arguments
- If it doesn't exist, skips silently — not an error
Hooks are called on all enabled plugins in alphabetical order. For fields like status_message or split_view, the last plugin to return a value wins. For diagnostics and line_annotations, results accumulate from all plugins.
When a plugin is toggled off via Plugins > {name}:
-
enabledis set tofalse - Hook calls skip the plugin
- Widget sessions are cleared
- The module table stays in memory — state is preserved
- No shutdown hook is called
When toggled back on, the plugin resumes with its existing state. No re-initialization happens.
Plugins > Reload All destroys and recreates all plugin state:
- Current disabled list, approved commands, and config are saved
- All plugin tables are dropped
- Lua garbage collection runs
- All
init.luafiles are re-read and re-executed from disk - Disabled list, commands, and config are restored
-
init(api)is called on all enabled plugins
Module state does not survive a reload. This is useful for development — edit your init.lua, hit Reload All, and your changes take effect.
The Lua runtime instance itself persists, but all plugin tables are fresh.
shutdown(api) is called once when FerrisPad is quitting, before the application exits. Use it for cleanup if needed.
function M:shutdown(api)
api:log("Plugin shutting down")
endNo hooks are called after shutdown.
All plugins share one Lua runtime and therefore one global namespace _G. Accessing or modifying _G is forbidden.
- The static source scanner blocks any
_Greference —_G.foo = bar,rawset(_G, ...),rawget(_G, ...), etc. - Plugins containing
_Gin non-comment lines will not load — neither via Plugin Manager install nor when loaded from the plugins directory at startup - Official plugins will never be accepted with any
_Gusage - Community plugins using
_Gwill be rejected during security review
Use module-local variables or fields on your module table (M.state = {}) to store state. This keeps your plugin isolated and safe across reloads.
| Resource | Limit | Scope |
|---|---|---|
| Instructions | 1,000,000 per hook call | Resets each hook |
| Memory | 16 MB | Shared across all plugins |
| Command timeout | 30 seconds | Per run_command call |
Exceeding the instruction or memory limit aborts the current hook call with an error. The plugin stays loaded and future hooks will still be called.