diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 00730a7c3e..ed41313738 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -249,6 +249,8 @@ getcmdtype() String return current command-line type getcmdwintype() String return current command-line window type getcompletion({pat}, {type} [, {filtered}]) List list of cmdline completion matches +getcompltype({pat}) String return the type of command-line + completion getcurpos([{winnr}]) List position of the cursor getcursorcharpos([{winnr}]) List character position of the cursor getcwd([{winnr} [, {tabnr}]]) String get the current working directory @@ -4368,6 +4370,13 @@ getcompletion({pat}, {type} [, {filtered}]) *getcompletion()* < Return type: list + +getcompltype({pat}) *getcompltype()* + Return the type of the {pat} command-line completion. + Returns an empty string when completion is not defined. + + Return type: |String| + *getcurpos()* getcurpos([{winid}]) Get the position of the cursor. This is like getpos('.'), but diff --git a/runtime/doc/tags b/runtime/doc/tags index 71a961697b..4d1e8c7f87 100644 --- a/runtime/doc/tags +++ b/runtime/doc/tags @@ -7975,6 +7975,7 @@ getcmdscreenpos() builtin.txt /*getcmdscreenpos()* getcmdtype() builtin.txt /*getcmdtype()* getcmdwintype() builtin.txt /*getcmdwintype()* getcompletion() builtin.txt /*getcompletion()* +getcompltype() builtin.txt /*getcompltype()* getcurpos() builtin.txt /*getcurpos()* getcursorcharpos() builtin.txt /*getcursorcharpos()* getcwd() builtin.txt /*getcwd()* diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt index ffa6fcb7ae..9147d4fa2e 100644 --- a/runtime/doc/usr_41.txt +++ b/runtime/doc/usr_41.txt @@ -1112,6 +1112,7 @@ Command line: *command-line-functions* getcmdtype() return the current command-line type getcmdwintype() return the current command-line window type getcompletion() list of command-line completion matches + getcompltype() get the type of command-line completion fullcommand() get full command name cmdcomplete_info() get command-line completion information diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 3ff6bd40ad..a4eae117cb 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -4526,6 +4526,38 @@ f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv) list_append_string(li, ccline->xpc->xp_files[idx], -1); } } + +/* + * "getcompltype()" function + */ + void +f_getcompltype(typval_T *argvars, typval_T *rettv) +{ + char_u *pat; + char_u *cmd_compl; + expand_T xpc; + int cmdline_len; + + if (in_vim9script() && check_for_string_arg(argvars, 0) == FAIL) + return; + + pat = tv_get_string(&argvars[0]); + + ExpandInit(&xpc); + + cmdline_len = (int)STRLEN(pat); + set_cmd_context(&xpc, pat, cmdline_len, cmdline_len, FALSE); + xpc.xp_pattern_len = (int)STRLEN(xpc.xp_pattern); + xpc.xp_col = cmdline_len; + + rettv->v_type = VAR_STRING; + + cmd_compl = cmdcomplete_type_to_str(xpc.xp_context); + if (cmd_compl != NULL) + rettv->vval.v_string = vim_strsave(cmd_compl); + + ExpandCleanup(&xpc); +} #endif // FEAT_EVAL /* diff --git a/src/evalfunc.c b/src/evalfunc.c index a31ad1341f..0496604915 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -2280,6 +2280,8 @@ static funcentry_T global_functions[] = ret_string, f_getcmdwintype}, {"getcompletion", 2, 3, FEARG_1, arg3_string_string_bool, ret_list_string, f_getcompletion}, + {"getcompltype", 1, 1, FEARG_1, NULL, + ret_string, f_getcompltype}, {"getcurpos", 0, 1, FEARG_1, arg1_number, ret_list_number, f_getcurpos}, {"getcursorcharpos", 0, 1, FEARG_1, arg1_number, diff --git a/src/proto/cmdexpand.pro b/src/proto/cmdexpand.pro index 92e9dcb024..c277c133e9 100644 --- a/src/proto/cmdexpand.pro +++ b/src/proto/cmdexpand.pro @@ -25,4 +25,5 @@ int wildmenu_process_key(cmdline_info_T *cclp, int key, expand_T *xp); void wildmenu_cleanup(cmdline_info_T *cclp); void f_getcompletion(typval_T *argvars, typval_T *rettv); void f_cmdcomplete_info(typval_T *argvars UNUSED, typval_T *rettv); +void f_getcompltype(typval_T *argvars, typval_T *rettv); /* vim: set ft=c : */ diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index 59c25db75f..22efd45dd7 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -4354,6 +4354,7 @@ func Test_redrawtabpanel_error() call assert_fails(':redrawtabpanel', 'E1547:') endfunc +<<<<<<< HEAD " Test wildcharm completion for '/' and '?' search func Test_search_complete() CheckOption incsearch @@ -4589,4 +4590,13 @@ func Test_range_complete() set wildcharm=0 endfunc +func Test_getcompltype() + call assert_equal(getcompltype(''), 'command') + call assert_equal(getcompltype('dummy '), '') + call assert_equal(getcompltype('cd '), 'dir_in_path') + call assert_equal(getcompltype('let v:n'), 'var') + call assert_equal(getcompltype('call tag'), 'function') + call assert_equal(getcompltype('help '), 'help') +endfunc + " vim: shiftwidth=2 sts=2 expandtab