mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 03:15:39 +00:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user