From 9aa4608401384a59ea54e0ba800ce063775e8ae9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 20 May 2026 17:33:01 -0400 Subject: 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. --- runtime/lua/vim/tty.lua | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'runtime/lua/vim/tty.lua') diff --git a/runtime/lua/vim/tty.lua b/runtime/lua/vim/tty.lua index 2693c1bc97..6771efe849 100644 --- a/runtime/lua/vim/tty.lua +++ b/runtime/lua/vim/tty.lua @@ -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) -- cgit