diff options
| author | Josh Rahm <joshuarahm@gmail.com> | 2026-10-13 22:11:33 -0600 |
|---|---|---|
| committer | Josh Rahm <joshuarahm@gmail.com> | 2026-10-18 00:28:27 -0600 |
| commit | 22d8bf3861234480aa6afed90a1faaaac3d49520 (patch) | |
| tree | 097100fc5481f0a614c42f5409ed2ec1fa6d8b17 /runtime/lua/vim/_extregs.lua | |
| parent | 0851e7dabed9fc9c019e22088029f36e9f3ec3e3 (diff) | |
| download | rneovim-22d8bf3861234480aa6afed90a1faaaac3d49520.tar.gz rneovim-22d8bf3861234480aa6afed90a1faaaac3d49520.tar.bz2 rneovim-22d8bf3861234480aa6afed90a1faaaac3d49520.zip | |
[feat] extregisters
Implements "extended registers"
Extended registers provide access to a separate namespace of registers
backed by custom lua callback functions.
A new special register ("~) is introduced, which prompts the user for
the name of an extregistr to yank or paste from.
This enables file-backed or cloud-synced or other arbitrary register
behavior.
One can now use:
`"~file_extreg<cr>yy`
to yank into the "file_extreg" register.
AI-assisted: Qwen3-Coder
Diffstat (limited to 'runtime/lua/vim/_extregs.lua')
| -rw-r--r-- | runtime/lua/vim/_extregs.lua | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/runtime/lua/vim/_extregs.lua b/runtime/lua/vim/_extregs.lua new file mode 100644 index 0000000000..c03e8fda23 --- /dev/null +++ b/runtime/lua/vim/_extregs.lua @@ -0,0 +1,69 @@ +-- vim._extregs: Extended Register system API +-- Internal Lua bindings for the extregister C API + +local M = {} + +--- Register a new extregister provider +---@param name string Provider name +---@param text_yanked_cb? fun(content:table) Callback for yank operations +---@param text_put_cb? fun():table Callback for put operations +---@return integer Provider ID on success, 0 on failure +function M.register(name, text_yanked_cb, text_put_cb) + local ty_ref = text_yanked_cb and nlua_push_lref(global_lstate, text_yanked_cb, true) or LUA_NOREF + local tp_ref = text_put_cb and nlua_push_lref(global_lstate, text_put_cb, true) or LUA_NOREF + return vim._C._extregs.register(name, ty_ref, tp_ref) +end + +--- Unregister an extregister provider +---@param name string Provider name to unregister +---@return boolean true on success, false if not found +function M.unregister(name) + return vim._C._extregs.unregister(name) +end + +--- Bind a character to an extregister provider +---@param alias string Character to bind (e.g., "@") +---@param provider_name string Name of provider to bind to +---@return boolean true on success, false on failure +function M.bind(alias, provider_name) + return vim._C._extregs.bind(alias, provider_name) +end + +--- Unbind a character from an extregister provider +---@param alias string Character to unbind +---@return boolean true on success, false if not bound +function M.unbind(alias) + return vim._C._extregs.unbind(alias) +end + +--- Check if a character is bound to an extregister +---@param alias string Character to check +---@return boolean true if bound, false otherwise +function M.is_alias(alias) + return vim._C._extregs.is_alias(alias) +end + +--- Get provider ID for an alias +---@param alias string Bound character +---@return integer Provider ID on success, 0 if not bound +function M.get_provider_id(alias) + return vim._C._extregs.get_provider_id(alias) +end + +--- Get provider by ID +---@param id integer Provider ID (1-based index) +---@return any? Provider on success, nil if not found +function M.get_provider_by_id(id) + local prov = vim._C._extregs.get_provider_by_id(id) + return prov or nil +end + +--- Get provider by name +---@param name string Provider name +---@return any? Provider on success, nil if not found +function M.get_provider(name) + local prov = vim._C._extregs.get_provider(name) + return prov or nil +end + +return M |