0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

Add getcompltype()

This commit is contained in:
Shougo Matsushita 2025-06-25 19:12:25 +09:00
parent 20eb68a8f2
commit 8e14d12635
7 changed files with 56 additions and 0 deletions

View File

@ -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<string>
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

View File

@ -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()*

View File

@ -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

View File

@ -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
/*

View File

@ -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,

View File

@ -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 : */

View File

@ -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