diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 43c6bd6918..57d9eb5b43 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -9280,7 +9280,10 @@ win_getid([{win} [, {tab}]]) *win_getid()* win_gettype([{nr}]) *win_gettype()* Return the type of the window: + "aucmdwin" autocommand window. Temporary window + used to execute autocommands. "popup" popup window |popup| + "preview" preview window |preview-window| "command" command-line window |cmdwin| (empty) normal window "unknown" window {nr} not found diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 090133c868..d07efc297e 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -11006,7 +11006,11 @@ static void f_win_gettype(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } } - if (wp->w_floating) { + if (wp == aucmd_win) { + rettv->vval.v_string = vim_strsave((char_u *)"aucmdwin"); + } else if (wp->w_p_pvw) { + rettv->vval.v_string = vim_strsave((char_u *)"preview"); + } else if (wp->w_floating) { rettv->vval.v_string = vim_strsave((char_u *)"popup"); } else if (wp == curwin && cmdwin_type != 0) { rettv->vval.v_string = vim_strsave((char_u *)"command"); diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 22f03e1076..a2695ec354 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -1934,4 +1934,26 @@ func Test_autocmd_sigusr1() unlet g:sigusr1_passed endfunc +" Test for the temporary internal window used to execute autocmds +func Test_autocmd_window() + %bw! + edit one.txt + tabnew two.txt + let g:blist = [] + augroup aucmd_win_test + au! + au BufEnter * call add(g:blist, [expand(''), + \ win_gettype(bufwinnr(expand('')))]) + augroup END + + doautoall BufEnter + call assert_equal([['one.txt', 'aucmdwin'], ['two.txt', '']], g:blist) + + augroup aucmd_win_test + au! + augroup END + augroup! aucmd_win_test + %bw! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_preview.vim b/src/nvim/testdir/test_preview.vim index 91923fb1e9..6c4ae414d3 100644 --- a/src/nvim/testdir/test_preview.vim +++ b/src/nvim/testdir/test_preview.vim @@ -11,3 +11,47 @@ func Test_Psearch() call assert_equal(wincount, winnr('$')) bwipe endfunc + +func Test_window_preview() + " Open a preview window + pedit Xa + call assert_equal(2, winnr('$')) + call assert_equal(0, &previewwindow) + + " Go to the preview window + wincmd P + call assert_equal(1, &previewwindow) + call assert_equal('preview', win_gettype()) + + " Close preview window + wincmd z + call assert_equal(1, winnr('$')) + call assert_equal(0, &previewwindow) + + call assert_fails('wincmd P', 'E441:') +endfunc + +func Test_window_preview_from_help() + filetype on + call writefile(['/* some C code */'], 'Xpreview.c') + help + pedit Xpreview.c + wincmd P + call assert_equal(1, &previewwindow) + call assert_equal('c', &filetype) + wincmd z + + filetype off + close + call delete('Xpreview.c') +endfunc + +func Test_multiple_preview_windows() + new + set previewwindow + new + call assert_fails('set previewwindow', 'E590:') + %bw! +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 500e3ff088..c630e678fd 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -172,39 +172,6 @@ func Test_window_split_edit_bufnr() %bw! endfunc -func Test_window_preview() - " Open a preview window - pedit Xa - call assert_equal(2, winnr('$')) - call assert_equal(0, &previewwindow) - - " Go to the preview window - wincmd P - call assert_equal(1, &previewwindow) - - " Close preview window - wincmd z - call assert_equal(1, winnr('$')) - call assert_equal(0, &previewwindow) - - call assert_fails('wincmd P', 'E441:') -endfunc - -func Test_window_preview_from_help() - filetype on - call writefile(['/* some C code */'], 'Xpreview.c') - help - pedit Xpreview.c - wincmd P - call assert_equal(1, &previewwindow) - call assert_equal('c', &filetype) - wincmd z - - filetype off - close - call delete('Xpreview.c') -endfunc - func Test_window_exchange() e Xa