diff options
-rw-r--r-- | runtime/doc/autocmd.txt | 5 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_autocmd.vim | 46 |
3 files changed, 46 insertions, 6 deletions
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt index 6c41dd3b10..2737ac9b9f 100644 --- a/runtime/doc/autocmd.txt +++ b/runtime/doc/autocmd.txt @@ -1002,8 +1002,9 @@ VimResume After Nvim resumes from |suspend| state. *VimSuspend* VimSuspend Before Nvim enters |suspend| state. *WinClosed* -WinClosed After closing a window. <afile> expands to the - |window-ID|. +WinClosed After closing a window. The pattern is + matched against the |window-ID|. Both + <amatch> and <afile> are set to the |window-ID|. After WinLeave. Non-recursive (event cannot trigger itself). See also |ExitPre|, |QuitPre|. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 77bf1d29eb..d88f4f42e8 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -186,7 +186,6 @@ Events: |TermOpen| |UIEnter| |UILeave| - |WinClosed| Functions: |dictwatcheradd()| notifies a callback whenever a |Dict| is modified diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index c350a17236..0c8b8a45d9 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -222,6 +222,7 @@ func Test_win_tab_autocmd() augroup testing au WinNew * call add(g:record, 'WinNew') + au WinClosed * call add(g:record, 'WinClosed') au WinEnter * call add(g:record, 'WinEnter') au WinLeave * call add(g:record, 'WinLeave') au TabNew * call add(g:record, 'TabNew') @@ -238,8 +239,8 @@ func Test_win_tab_autocmd() call assert_equal([ \ 'WinLeave', 'WinNew', 'WinEnter', \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter', - \ 'WinLeave', 'TabLeave', 'TabClosed', 'WinEnter', 'TabEnter', - \ 'WinLeave', 'WinEnter' + \ 'WinLeave', 'TabLeave', 'WinClosed', 'TabClosed', 'WinEnter', 'TabEnter', + \ 'WinLeave', 'WinClosed', 'WinEnter' \ ], g:record) let g:record = [] @@ -250,7 +251,7 @@ func Test_win_tab_autocmd() call assert_equal([ \ 'WinLeave', 'TabLeave', 'WinNew', 'WinEnter', 'TabNew', 'TabEnter', \ 'WinLeave', 'TabLeave', 'WinEnter', 'TabEnter', - \ 'TabClosed' + \ 'WinClosed', 'TabClosed' \ ], g:record) augroup testing @@ -259,6 +260,45 @@ func Test_win_tab_autocmd() unlet g:record endfunc +func Test_WinClosed() + " Test that the pattern is matched against the closed window's ID, and both + " <amatch> and <afile> are set to it. + new + let winid = win_getid() + let g:matched = v:false + augroup test-WinClosed + autocmd! + execute 'autocmd WinClosed' winid 'let g:matched = v:true' + autocmd WinClosed * let g:amatch = str2nr(expand('<amatch>')) + autocmd WinClosed * let g:afile = str2nr(expand('<afile>')) + augroup END + close + call assert_true(g:matched) + call assert_equal(winid, g:amatch) + call assert_equal(winid, g:afile) + + " Test that WinClosed is non-recursive. + new + new + call assert_equal(3, winnr('$')) + let g:triggered = 0 + augroup test-WinClosed + autocmd! + autocmd WinClosed * let g:triggered += 1 + autocmd WinClosed * 2 wincmd c + augroup END + close + call assert_equal(1, winnr('$')) + call assert_equal(1, g:triggered) + + autocmd! test-WinClosed + augroup! test-WinClosed + unlet g:matched + unlet g:amatch + unlet g:afile + unlet g:triggered +endfunc + func s:AddAnAutocmd() augroup vimBarTest au BufReadCmd * echo 'hello' |