mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 14:58:18 +00:00
WinClosed: sort auevents.lua; improve tests
- test: reduce verbosity, condense redundancy, improve readability
- auevents.lua: keep events sorted by name. ref afd1d412fa
This commit is contained in:
@@ -576,8 +576,7 @@ ColorSchemePre Before loading a color scheme. |:colorscheme|
|
||||
CompleteChanged *CompleteChanged*
|
||||
After each time the Insert mode completion
|
||||
menu changed. Not fired on popup menu hide,
|
||||
use |CompleteDone| for that. Never triggered
|
||||
recursively.
|
||||
use |CompleteDone| for that.
|
||||
|
||||
Sets these |v:event| keys:
|
||||
completed_item See |complete-items|.
|
||||
@@ -588,7 +587,8 @@ CompleteChanged *CompleteChanged*
|
||||
size total nr of items
|
||||
scrollbar TRUE if visible
|
||||
|
||||
It is not allowed to change the text |textlock|.
|
||||
Non-recursive (event cannot trigger itself).
|
||||
Cannot change the text. |textlock|
|
||||
|
||||
The size and position of the popup are also
|
||||
available by calling |pum_getpos()|.
|
||||
@@ -661,7 +661,7 @@ DirChanged After the |current-directory| was changed.
|
||||
Sets these |v:event| keys:
|
||||
cwd: current working directory
|
||||
scope: "global", "tab", "window"
|
||||
Recursion is ignored.
|
||||
Non-recursive (event cannot trigger itself).
|
||||
*FileAppendCmd*
|
||||
FileAppendCmd Before appending to a file. Should do the
|
||||
appending to the file. Use the '[ and ']
|
||||
@@ -697,6 +697,7 @@ ExitPre When using `:quit`, `:wq` in a way it makes
|
||||
cancelled if there is a modified buffer that
|
||||
isn't automatically saved, use |VimLeavePre|
|
||||
for really exiting.
|
||||
See also |QuitPre|, |WinClosed|.
|
||||
*FileChangedShell*
|
||||
FileChangedShell When Vim notices that the modification time of
|
||||
a file has changed since editing started.
|
||||
@@ -841,7 +842,7 @@ TextYankPost Just after a |yank| or |deleting| command, but not
|
||||
and |']| marks can be used to calculate the
|
||||
precise region of the operation.
|
||||
|
||||
Recursion is ignored.
|
||||
Non-recursive (event cannot trigger itself).
|
||||
Cannot change the text. |textlock|
|
||||
*InsertEnter*
|
||||
InsertEnter Just before starting Insert mode. Also for
|
||||
@@ -908,8 +909,8 @@ OptionSet After setting an option (except during
|
||||
always use |:noautocmd| to prevent triggering
|
||||
OptionSet.
|
||||
|
||||
Recursion is ignored, thus |:set| in the
|
||||
autocommand does not trigger OptionSet again.
|
||||
Non-recursive: |:set| in the autocommand does
|
||||
not trigger OptionSet again.
|
||||
|
||||
*QuickFixCmdPre*
|
||||
QuickFixCmdPre Before a quickfix command is run (|:make|,
|
||||
@@ -941,7 +942,7 @@ QuitPre When using `:quit`, `:wq` or `:qall`, before
|
||||
or quits Vim. Can be used to close any
|
||||
non-essential window if the current window is
|
||||
the last ordinary window.
|
||||
Also see |ExitPre|.
|
||||
See also |ExitPre|, ||WinClosed|.
|
||||
*RemoteReply*
|
||||
RemoteReply When a reply from a Vim that functions as
|
||||
server was received |server2client()|. The
|
||||
@@ -1042,8 +1043,8 @@ TabNew When creating a new tab page. |tab-page|
|
||||
TabNewEntered After entering a new tab page. |tab-page|
|
||||
After BufEnter.
|
||||
*TabClosed*
|
||||
TabClosed After closing a tab page. <afile> can be used
|
||||
for the tab page number.
|
||||
TabClosed After closing a tab page. <afile> expands to
|
||||
the tab page number.
|
||||
*TermOpen*
|
||||
TermOpen When a |terminal| job is starting. Can be
|
||||
used to configure the terminal buffer.
|
||||
@@ -1133,7 +1134,10 @@ VimResume After Nvim resumes from |suspend| state.
|
||||
*VimSuspend*
|
||||
VimSuspend Before Nvim enters |suspend| state.
|
||||
*WinClosed*
|
||||
WinClosed After closing a window.
|
||||
WinClosed After closing a window. <afile> expands to the
|
||||
|window-ID|.
|
||||
Non-recursive (event cannot trigger itself).
|
||||
See also |ExitPre|, |QuitPre|.
|
||||
*WinEnter*
|
||||
WinEnter After entering another window. Not done for
|
||||
the first window, when Vim has just started.
|
||||
|
@@ -21,12 +21,12 @@ return {
|
||||
'BufWritePre', -- before writing a buffer
|
||||
'ChanInfo', -- info was received about channel
|
||||
'ChanOpen', -- channel was opened
|
||||
'CmdlineChanged', -- command line was modified
|
||||
'CmdlineEnter', -- after entering cmdline mode
|
||||
'CmdlineLeave', -- before leaving cmdline mode
|
||||
'CmdUndefined', -- command undefined
|
||||
'CmdWinEnter', -- after entering the cmdline window
|
||||
'CmdWinLeave', -- before leaving the cmdline window
|
||||
'CmdlineChanged', -- command line was modified
|
||||
'CmdlineEnter', -- after entering cmdline mode
|
||||
'CmdlineLeave', -- before leaving cmdline mode
|
||||
'ColorScheme', -- after loading a colorscheme
|
||||
'ColorSchemePre', -- before loading a colorscheme
|
||||
'CompleteChanged', -- after popup menu changed
|
||||
@@ -76,8 +76,8 @@ return {
|
||||
'ShellFilterPost', -- after ":1,2!cmd", ":w !cmd", ":r !cmd".
|
||||
'Signal', -- after nvim process received a signal
|
||||
'SourceCmd', -- sourcing a Vim script using command
|
||||
'SourcePre', -- before sourcing a Vim script
|
||||
'SourcePost', -- after sourcing a Vim script
|
||||
'SourcePre', -- before sourcing a Vim script
|
||||
'SpellFileMissing', -- spell file missing
|
||||
'StdinReadPost', -- after reading from stdin
|
||||
'StdinReadPre', -- before reading from stdin
|
||||
@@ -107,10 +107,10 @@ return {
|
||||
'VimResized', -- after Vim window was resized
|
||||
'VimResume', -- after Nvim is resumed
|
||||
'VimSuspend', -- before Nvim is suspended
|
||||
'WinClosed', -- after closing a window
|
||||
'WinEnter', -- after entering a window
|
||||
'WinLeave', -- before leaving a window
|
||||
'WinNew', -- when entering a new window
|
||||
'WinClosed', -- after closing a window
|
||||
},
|
||||
aliases = {
|
||||
BufCreate = 'BufAdd',
|
||||
|
@@ -2695,8 +2695,7 @@ static void do_autocmd_winclosed(win_T *win)
|
||||
return;
|
||||
}
|
||||
recursive = true;
|
||||
|
||||
char_u winid[10];
|
||||
char_u winid[NUMBUFLEN];
|
||||
vim_snprintf((char *)winid, sizeof(winid), "%i", win->handle);
|
||||
apply_autocmds(EVENT_WINCLOSED, winid, winid, false, win->w_buffer);
|
||||
recursive = false;
|
||||
|
@@ -1,8 +1,8 @@
|
||||
local helpers = require('test.functional.helpers')(after_each)
|
||||
local Screen = require('test.functional.ui.screen')
|
||||
|
||||
local assert_visible = helpers.assert_visible
|
||||
local dedent = helpers.dedent
|
||||
local neq = helpers.neq
|
||||
local eq = helpers.eq
|
||||
local eval = helpers.eval
|
||||
local feed = helpers.feed
|
||||
@@ -19,98 +19,86 @@ local source = helpers.source
|
||||
describe('autocmd', function()
|
||||
before_each(clear)
|
||||
|
||||
it(':tabnew triggers events in the correct order', function()
|
||||
it(':tabnew, :split, :close events order, <afile>', function()
|
||||
local expected = {
|
||||
'WinLeave',
|
||||
'TabLeave',
|
||||
'WinEnter',
|
||||
'TabNew',
|
||||
'TabEnter',
|
||||
'BufLeave',
|
||||
'BufEnter'
|
||||
{'WinLeave', ''},
|
||||
{'TabLeave', ''},
|
||||
{'WinEnter', ''},
|
||||
{'TabNew', 'testfile1'}, -- :tabnew
|
||||
{'TabEnter', ''},
|
||||
{'BufLeave', ''},
|
||||
{'BufEnter', 'testfile1'}, -- :split
|
||||
{'WinLeave', 'testfile1'},
|
||||
{'WinEnter', 'testfile1'},
|
||||
{'WinLeave', 'testfile1'},
|
||||
{'WinClosed', '1002'}, -- :close, WinClosed <afile> = window-id
|
||||
{'WinEnter', 'testfile1'},
|
||||
{'WinLeave', 'testfile1'}, -- :bdelete
|
||||
{'WinEnter', 'testfile1'},
|
||||
{'BufLeave', 'testfile1'},
|
||||
{'BufEnter', 'testfile2'},
|
||||
{'WinClosed', '1000'},
|
||||
}
|
||||
command('let g:foo = []')
|
||||
command('autocmd BufEnter * :call add(g:foo, "BufEnter")')
|
||||
command('autocmd BufLeave * :call add(g:foo, "BufLeave")')
|
||||
command('autocmd TabEnter * :call add(g:foo, "TabEnter")')
|
||||
command('autocmd TabLeave * :call add(g:foo, "TabLeave")')
|
||||
command('autocmd TabNew * :call add(g:foo, "TabNew")')
|
||||
command('autocmd WinEnter * :call add(g:foo, "WinEnter")')
|
||||
command('autocmd WinLeave * :call add(g:foo, "WinLeave")')
|
||||
command('tabnew')
|
||||
assert.same(expected, eval('g:foo'))
|
||||
end)
|
||||
|
||||
it(':close triggers WinClosed event', function()
|
||||
command('let g:triggered = 0')
|
||||
command('new')
|
||||
command('autocmd WinClosed <buffer> :let g:triggered+=1')
|
||||
eq(0, eval('g:triggered'))
|
||||
command('let g:evs = []')
|
||||
command('autocmd BufEnter * :call add(g:evs, ["BufEnter", expand("<afile>")])')
|
||||
command('autocmd BufLeave * :call add(g:evs, ["BufLeave", expand("<afile>")])')
|
||||
command('autocmd TabEnter * :call add(g:evs, ["TabEnter", expand("<afile>")])')
|
||||
command('autocmd TabLeave * :call add(g:evs, ["TabLeave", expand("<afile>")])')
|
||||
command('autocmd TabNew * :call add(g:evs, ["TabNew", expand("<afile>")])')
|
||||
command('autocmd WinEnter * :call add(g:evs, ["WinEnter", expand("<afile>")])')
|
||||
command('autocmd WinLeave * :call add(g:evs, ["WinLeave", expand("<afile>")])')
|
||||
command('autocmd WinClosed * :call add(g:evs, ["WinClosed", expand("<afile>")])')
|
||||
command('tabnew testfile1')
|
||||
command('split')
|
||||
command('close')
|
||||
eq(1, eval('g:triggered'))
|
||||
command('new testfile2')
|
||||
command('bdelete 1')
|
||||
eq(expected, eval('g:evs'))
|
||||
end)
|
||||
|
||||
it('WinClosed event exposes window id as <afile>', function()
|
||||
command('new')
|
||||
local id = meths.get_current_win().id
|
||||
helpers.nvim('command', 'au! WinClosed * echom "winclosed:".expand("<afile>").":".expand("<amatch>").":".win_getid()')
|
||||
eq(string.format("winclosed:%s:%s:%s", id, id, id), helpers.nvim('exec', 'close', true))
|
||||
end)
|
||||
|
||||
it(':bdelete triggers WinClosed event', function()
|
||||
it('WinClosed is non-recursive', function()
|
||||
command('let g:triggered = 0')
|
||||
command('autocmd WinClosed <buffer> :let g:triggered+=1')
|
||||
local first_buffer = eval("bufnr('%')")
|
||||
command('new')
|
||||
command('bdelete ' .. first_buffer )
|
||||
command('autocmd WinClosed * :let g:triggered+=1 | :bdelete 2')
|
||||
command('new testfile2')
|
||||
command('new testfile3')
|
||||
|
||||
-- All 3 buffers are visible.
|
||||
assert_visible(1, true)
|
||||
assert_visible(2, true)
|
||||
assert_visible(3, true)
|
||||
|
||||
-- Trigger WinClosed, which also deletes buffer/window 2.
|
||||
command('bdelete 1')
|
||||
|
||||
-- Buffers 1 and 2 were closed but WinClosed was triggered only once.
|
||||
eq(1, eval('g:triggered'))
|
||||
assert_visible(1, false)
|
||||
assert_visible(2, false)
|
||||
assert_visible(3, true)
|
||||
end)
|
||||
|
||||
it(':close triggers WinClosed event in another tab', function()
|
||||
command('let g:triggered = 0')
|
||||
local current_buffer = eval("bufnr('%')")
|
||||
command('autocmd WinClosed <buffer> :let g:triggered+=1')
|
||||
command('tabnew')
|
||||
command('bdelete ' .. current_buffer)
|
||||
eq(1, eval('g:triggered'))
|
||||
end)
|
||||
|
||||
it('WinClosed events are not recursive in different window', function()
|
||||
command('let g:triggered = 0')
|
||||
local first_buffer = eval("bufnr('%')")
|
||||
command('autocmd WinClosed <buffer> :let g:triggered+=1')
|
||||
it('WinClosed from a different tabpage', function()
|
||||
command('let g:evs = []')
|
||||
command('edit tesfile1')
|
||||
command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])')
|
||||
local buf1 = eval("bufnr('%')")
|
||||
command('new')
|
||||
local second_buffer = eval("bufnr('%')")
|
||||
command('autocmd WinClosed <buffer> :bdelete ' .. first_buffer)
|
||||
command('new')
|
||||
neq(-1, funcs.bufwinnr(first_buffer))
|
||||
command('bdelete ' .. second_buffer )
|
||||
eq(0, eval('g:triggered'))
|
||||
|
||||
-- first event was triggered, second wasn't
|
||||
eq(-1, funcs.bufwinnr(first_buffer))
|
||||
end)
|
||||
|
||||
it('WinClosed events are not recursive in the same window', function()
|
||||
command('let g:triggered = 0')
|
||||
command('new')
|
||||
local second_buffer = eval("bufnr('%')")
|
||||
command('autocmd WinClosed <buffer> :let g:triggered+=1 | bdelete ' .. second_buffer)
|
||||
neq(-1, funcs.bufwinnr(second_buffer))
|
||||
eq(0, eval('g:triggered'))
|
||||
command('bdelete ' .. second_buffer )
|
||||
eq(-1, funcs.bufwinnr(second_buffer))
|
||||
eq(1, eval('g:triggered'))
|
||||
end)
|
||||
|
||||
it('WinClosed events are not recursive in different tab', function()
|
||||
command('let g:triggered = 0')
|
||||
command('new')
|
||||
local second_buffer = eval("bufnr('%')")
|
||||
command('autocmd WinClosed <buffer> :let g:triggered+=1 | bdelete ' .. second_buffer)
|
||||
command('tabnew')
|
||||
command('bdelete ' .. second_buffer )
|
||||
eq(1, eval('g:triggered'))
|
||||
local buf2 = eval("bufnr('%')")
|
||||
command('autocmd WinClosed <buffer> :call add(g:evs, ["WinClosed", expand("<abuf>")])'
|
||||
-- Attempt recursion.
|
||||
..' | bdelete '..buf2)
|
||||
command('tabedit testfile2')
|
||||
command('tabedit testfile3')
|
||||
command('bdelete '..buf2)
|
||||
-- Non-recursive: only triggered once.
|
||||
eq({
|
||||
{'WinClosed', '2'},
|
||||
}, eval('g:evs'))
|
||||
command('bdelete '..buf1)
|
||||
eq({
|
||||
{'WinClosed', '2'},
|
||||
{'WinClosed', '1'},
|
||||
}, eval('g:evs'))
|
||||
end)
|
||||
|
||||
it('v:vim_did_enter is 1 after VimEnter', function()
|
||||
|
@@ -597,6 +597,19 @@ function module.assert_alive()
|
||||
assert(2 == module.eval('1+1'), 'crash? request failed')
|
||||
end
|
||||
|
||||
-- Asserts that buffer is loaded and visible in the current tabpage.
|
||||
function module.assert_visible(bufnr, visible)
|
||||
assert(type(visible) == 'boolean')
|
||||
eq(visible, module.bufmeths.is_loaded(bufnr))
|
||||
if visible then
|
||||
assert(-1 ~= module.funcs.bufwinnr(bufnr),
|
||||
'expected buffer to be visible in current tabpage: '..tostring(bufnr))
|
||||
else
|
||||
assert(-1 == module.funcs.bufwinnr(bufnr),
|
||||
'expected buffer NOT visible in current tabpage: '..tostring(bufnr))
|
||||
end
|
||||
end
|
||||
|
||||
local function do_rmdir(path)
|
||||
local mode, errmsg, errcode = lfs.attributes(path, 'mode')
|
||||
if mode == nil then
|
||||
|
Reference in New Issue
Block a user