mirror of
https://github.com/neovim/neovim.git
synced 2026-05-24 05:40:08 +00:00
refactor: introduce nvim_on internally #39883
Problem: `nvim_create_autocmd` is too verbose and its `callback` requires extra "nesting". Solution: Introduce `nvim_on`. Start using it internally. Then we can get a feel for how it should look before making it public.
This commit is contained in:
@@ -28,18 +28,19 @@ function M.request(payload, opts, on_response)
|
||||
timer = assert(vim.uv.new_timer())
|
||||
end
|
||||
|
||||
local id = vim.api.nvim_create_autocmd('TermResponse', {
|
||||
group = opts.group,
|
||||
nested = true,
|
||||
callback = function(ev)
|
||||
local id = require('vim._core.util').nvim_on(
|
||||
'TermResponse',
|
||||
opts.group,
|
||||
{ nested = true },
|
||||
function(ev)
|
||||
local stop = on_response(ev.data.sequence)
|
||||
-- If on_response is done, cancel the timeout so on_timeout doesn't fire spuriously.
|
||||
if stop and timer and not timer:is_closing() then
|
||||
timer:close()
|
||||
end
|
||||
return stop
|
||||
end,
|
||||
})
|
||||
end
|
||||
)
|
||||
|
||||
if payload ~= '' then
|
||||
vim.api.nvim_ui_send(payload)
|
||||
|
||||
Reference in New Issue
Block a user