From 7fb2310edb8f2fae1ddd175ef4bd6508ca3ce7e3 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Wed, 30 Mar 2022 11:59:36 -0400 Subject: fix: set nested before executing callback (#17801) --- test/functional/api/autocmd_spec.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test/functional/api') diff --git a/test/functional/api/autocmd_spec.lua b/test/functional/api/autocmd_spec.lua index 3b14ae9bf7..b8fbd4f9a5 100644 --- a/test/functional/api/autocmd_spec.lua +++ b/test/functional/api/autocmd_spec.lua @@ -334,6 +334,33 @@ describe('autocmd api', function() local aus2 = meths.get_autocmds { group = auname, event = "InsertEnter" } eq(0, #aus2) end) + + it('should respect nested', function() + local bufs = exec_lua [[ + local count = 0 + vim.api.nvim_create_autocmd("BufNew", { + once = false, + nested = true, + callback = function() + count = count + 1 + if count > 5 then + return true + end + + vim.cmd(string.format("new README_%s.md", count)) + end + }) + + vim.cmd "new First.md" + + return vim.api.nvim_list_bufs() + ]] + + -- 1 for the first buffer + -- 2 for First.md + -- 3-7 for the 5 we make in the autocmd + eq({1, 2, 3, 4, 5, 6, 7}, bufs) + end) end) describe('groups', function() -- cgit