aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/eval.txt16
-rw-r--r--src/nvim/eval.lua1
-rw-r--r--src/nvim/eval/funcs.c21
-rw-r--r--src/nvim/testdir/test_cmdline.vim2
4 files changed, 40 insertions, 0 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 7c6013f1b2..43c6bd6918 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2487,6 +2487,7 @@ wait({timeout}, {condition}[, {interval}])
wildmenumode() Number whether 'wildmenu' mode is active
win_findbuf({bufnr}) List find windows containing {bufnr}
win_getid([{win} [, {tab}]]) Number get |window-ID| for {win} in {tab}
+win_gettype([{nr}]) String type of window {nr}
win_gotoid({expr}) Number go to |window-ID| {expr}
win_id2tabwin({expr}) List get tab and window nr from |window-ID|
win_id2win({expr}) Number get window nr from |window-ID|
@@ -9277,6 +9278,21 @@ win_getid([{win} [, {tab}]]) *win_getid()*
number {tab}. The first tab has number one.
Return zero if the window cannot be found.
+win_gettype([{nr}]) *win_gettype()*
+ Return the type of the window:
+ "popup" popup window |popup|
+ "command" command-line window |cmdwin|
+ (empty) normal window
+ "unknown" window {nr} not found
+
+ When {nr} is omitted return the type of the current window.
+ When {nr} is given return the type of this window by number or
+ |window-ID|.
+
+ Also see the 'buftype' option. When running a terminal in a
+ popup window then 'buftype' is "terminal" and win_gettype()
+ returns "popup".
+
win_gotoid({expr}) *win_gotoid()*
Go to window with ID {expr}. This may also change the current
tabpage.
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 6c316bb1fe..9f1994e299 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -385,6 +385,7 @@ return {
wildmenumode={},
win_findbuf={args=1},
win_getid={args={0,2}},
+ win_gettype={args={0,1}},
win_gotoid={args=1},
win_id2tabwin={args=1},
win_id2win={args=1},
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 62a8022734..090133c868 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -10992,6 +10992,27 @@ static void f_win_getid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
rettv->vval.v_number = win_getid(argvars);
}
+/// "win_gettype(nr)" function
+static void f_win_gettype(typval_T *argvars, typval_T *rettv, FunPtr fptr)
+{
+ win_T *wp = curwin;
+
+ rettv->v_type = VAR_STRING;
+ rettv->vval.v_string = NULL;
+ if (argvars[0].v_type != VAR_UNKNOWN) {
+ wp = find_win_by_nr_or_id(&argvars[0]);
+ if (wp == NULL) {
+ rettv->vval.v_string = vim_strsave((char_u *)"unknown");
+ return;
+ }
+ }
+ 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");
+ }
+}
+
/// "win_gotoid()" function
static void f_win_gotoid(typval_T *argvars, typval_T *rettv, FunPtr fptr)
{
diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim
index 400e53d009..81f653c393 100644
--- a/src/nvim/testdir/test_cmdline.vim
+++ b/src/nvim/testdir/test_cmdline.vim
@@ -806,12 +806,14 @@ func Test_cmdwin_cedit()
let g:cmd_wintype = ''
func CmdWinType()
let g:cmd_wintype = getcmdwintype()
+ let g:wintype = win_gettype()
return ''
endfunc
call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
echo input('')
call assert_equal('@', g:cmd_wintype)
+ call assert_equal('command', g:wintype)
set cedit&vim
delfunc CmdWinType