diff --git a/lua/plugins/complete-word.lua b/lua/plugins/complete-word.lua index e5a4ed700..98097f482 100644 --- a/lua/plugins/complete-word.lua +++ b/lua/plugins/complete-word.lua @@ -1,5 +1,14 @@ -- complete word at primary selection location using vis-complete(1) +-- Table of hooks other plugins may register to insert their completion +-- candidates. +-- Hooks are called with the current word prefix and MUST return a table +-- containing their completion candidates. +local candidate_hooks = {} +if vis.plugins then + vis.plugins["complete-word"] = {candidate_hooks = candidate_hooks} +end + vis:map(vis.modes.INSERT, "", function() local win = vis.win local file = win.file @@ -17,6 +26,13 @@ vis:map(vis.modes.INSERT, "", function() -- collect words starting with prefix vis:command("x/\\b" .. prefix .. "\\w+/") local candidates = {} + + for _, candidate_hook in ipairs(candidate_hooks) do + for _, candidate in ipairs(candidate_hook(prefix)) do + table.insert(candidates, candidate) + end + end + for sel in win:selections_iterator() do table.insert(candidates, file:content(sel.range)) end diff --git a/lua/vis-std.lua b/lua/vis-std.lua index 1fe93a9d9..f32143147 100644 --- a/lua/vis-std.lua +++ b/lua/vis-std.lua @@ -89,6 +89,11 @@ local modes = { [vis.modes.REPLACE] = 'REPLACE', } +-- Namespace for lua plugins to expose their API and communicate with each other. +-- Each plugin can use its own namespace vis.plugins['plugin-name']. +local plugins = {} +vis.plugins = plugins + vis.events.subscribe(vis.events.WIN_STATUS, function(win) local left_parts = {} local right_parts = {}