micro
micro copied to clipboard
[Question] How to write a complete for a command
Hello, I would like to know how I could create a complete to use in the commands I am creating in my plugins. I'm trying to get the arguments and the way I got it after observing OptionValueComplete was using the GetArg function.
local buffer = import('micro/buffer')
function complete(buf)
local cmds = { '-h', '--help', 'set', 'lint', 'fmt', 'bind' }
local input, argstart = buffer.GetArg(buf)
local completions = {}
local suggestions = {}
for _, a in pairs(cmds) do
local i, j = a:find(input, 1, true)
if i == 1 then
table.insert(suggestions, a)
table.insert(completions, a:sub(j + 1))
end
end
table.sort(completions)
table.sort(suggestions)
return completions, suggestions
end
However, GetArg is not exposed in the buffer module.
Would there be any other way to get the arguments that were entered by the user?
Commit hash: d8e9d61a OS: Ubuntu 22.04.3 LTS Terminal: terminator