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:
Justin M. Keyes
2026-05-20 17:33:01 -04:00
committed by GitHub
parent 799cbfff85
commit 9aa4608401
32 changed files with 842 additions and 1040 deletions

View File

@@ -1,4 +1,5 @@
local api = vim.api
local nvim_on = require('vim._core.util').nvim_on
-- TODO(lewis6991): deprecate some top level functions in favour of the submodule version
-- e.g. vim.diagnostic.get_namespace() -> vim.diagnostic.namespace.get()
@@ -1139,14 +1140,12 @@ function M.status(buf)
return result_str
end
api.nvim_create_autocmd('DiagnosticChanged', {
group = api.nvim_create_augroup('nvim.diagnostic.status', {}),
callback = function(ev)
if api.nvim_buf_is_loaded(ev.buf) then
api.nvim__redraw({ buf = ev.buf, statusline = true })
end
end,
nvim_on('DiagnosticChanged', api.nvim_create_augroup('nvim.diagnostic.status', {}), {
desc = 'diagnostics component for the statusline',
})
}, function(ev)
if api.nvim_buf_is_loaded(ev.buf) then
api.nvim__redraw({ buf = ev.buf, statusline = true })
end
end)
return M