feat(api): enable nvim_exec_autocmds to pass arbitrary data (#18613)

Add a "data" key to nvim_exec_autocmds that passes arbitrary data (API
objects) to autocommand callbacks.
This commit is contained in:
Gregory Anders
2022-05-18 09:51:26 -06:00
committed by GitHub
parent d7dd600716
commit 8a9ab88945
6 changed files with 56 additions and 6 deletions

View File

@@ -230,6 +230,34 @@ describe('autocmd api', function()
}, meths.get_var("autocmd_args"))
end)
it('can receive arbitrary data', function()
local function test(data)
eq(data, exec_lua([[
local input = ...
local output
vim.api.nvim_create_autocmd("User", {
pattern = "Test",
callback = function(args)
output = args.data
end,
})
vim.api.nvim_exec_autocmds("User", {
pattern = "Test",
data = input,
})
return output
]], data))
end
test("Hello")
test(42)
test(true)
test({ "list" })
test({ foo = "bar" })
end)
end)
describe('nvim_get_autocmds', function()