Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lua/plugins/complete-word.lua
Original file line number Diff line number Diff line change
@@ -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, "<C-n>", function()
local win = vis.win
local file = win.file
Expand All @@ -17,6 +26,13 @@ vis:map(vis.modes.INSERT, "<C-n>", 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
Expand Down
5 changes: 5 additions & 0 deletions lua/vis-std.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
Loading