diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index f38948c75a..60dbb4799f 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -1,4 +1,4 @@ -*builtin.txt* For Vim version 9.1. Last change: 2025 Jul 05 +*builtin.txt* For Vim version 9.1. Last change: 2025 Jul 06 VIM REFERENCE MANUAL by Bram Moolenaar @@ -4212,8 +4212,8 @@ getcmdcompltype() *getcmdcompltype()* |getcmdprompt()|, |getcmdcomplpat()| and |setcmdline()|. Returns an empty string when completion is not defined. - To get the type of the command-line completion for the - specified string, use |getcompletiontype()|. + To get the type of the command-line completion for a specified + string, use |getcompletiontype()|. Return type: |String| diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 5fa631c22a..b7597ea31e 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -4577,10 +4577,7 @@ f_getcompletiontype(typval_T *argvars, typval_T *rettv) 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->vval.v_string = get_cmdline_completion(&xpc); + rettv->vval.v_string = cmdcomplete_type_to_str(xpc.xp_context, xpc.xp_arg); ExpandCleanup(&xpc); } diff --git a/src/ex_getln.c b/src/ex_getln.c index f2a51ea2c8..f63ac6022f 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -4305,37 +4305,30 @@ get_cmdline_completion_pattern(void) /* * Get the command-line completion type. */ - char_u * -get_cmdline_completion(expand_T *xpc) + static char_u * +get_cmdline_completion(void) { - int xp_context; + cmdline_info_T *p; + int xp_context; - xp_context = xpc->xp_context; + if (cmdline_star > 0) + return NULL; + + p = get_ccline_ptr(); + if (p == NULL || p->xpc == NULL) + return NULL; + + xp_context = p->xpc->xp_context; if (xp_context == EXPAND_NOTHING) { - set_expand_context(xpc); - xp_context = xpc->xp_context; - xpc->xp_context = EXPAND_NOTHING; + set_expand_context(p->xpc); + xp_context = p->xpc->xp_context; + p->xpc->xp_context = EXPAND_NOTHING; } if (xp_context == EXPAND_UNSUCCESSFUL) return NULL; - char_u *cmd_compl = cmdcomplete_type_to_str(xp_context); - if (cmd_compl == NULL) - return NULL; - - if (xp_context == EXPAND_USER_LIST || xp_context == EXPAND_USER_DEFINED) - { - char_u *buffer; - - buffer = alloc(STRLEN(cmd_compl) + STRLEN(xpc->xp_arg) + 2); - if (buffer == NULL) - return NULL; - sprintf((char *)buffer, "%s,%s", cmd_compl, xpc->xp_arg); - return buffer; - } - - return vim_strsave(cmd_compl); + return cmdcomplete_type_to_str(xp_context, p->xpc->xp_arg); } /* @@ -4354,16 +4347,8 @@ f_getcmdcomplpat(typval_T *argvars UNUSED, typval_T *rettv) void f_getcmdcompltype(typval_T *argvars UNUSED, typval_T *rettv) { - cmdline_info_T *p; - rettv->v_type = VAR_STRING; - rettv->vval.v_string = NULL; - - p = get_ccline_ptr(); - if (cmdline_star > 0 || p == NULL || p->xpc == NULL) - return; - - rettv->vval.v_string = get_cmdline_completion(p->xpc); + rettv->vval.v_string = get_cmdline_completion(); } /* diff --git a/src/proto/ex_getln.pro b/src/proto/ex_getln.pro index 9087c837df..6c93ac755a 100644 --- a/src/proto/ex_getln.pro +++ b/src/proto/ex_getln.pro @@ -30,7 +30,6 @@ char_u *vim_strsave_fnameescape(char_u *fname, int what); void escape_fname(char_u **pp); void tilde_replace(char_u *orig_pat, int num_files, char_u **files); cmdline_info_T *get_cmdline_info(void); -char_u *get_cmdline_completion(expand_T *xpc); void f_getcmdcomplpat(typval_T *argvars, typval_T *rettv); void f_getcmdcompltype(typval_T *argvars, typval_T *rettv); void f_getcmdline(typval_T *argvars, typval_T *rettv); diff --git a/src/proto/usercmd.pro b/src/proto/usercmd.pro index d0cd2a3acb..dcf2a1dbe5 100644 --- a/src/proto/usercmd.pro +++ b/src/proto/usercmd.pro @@ -9,7 +9,7 @@ char_u *get_user_cmd_addr_type(expand_T *xp, int idx); char_u *get_user_cmd_flags(expand_T *xp, int idx); char_u *get_user_cmd_nargs(expand_T *xp, int idx); char_u *get_user_cmd_complete(expand_T *xp, int idx); -char_u *cmdcomplete_type_to_str(int expand); +char_u *cmdcomplete_type_to_str(int expand, char_u *arg); int cmdcomplete_str_to_type(char_u *complete_str); char *uc_fun_cmd(void); int parse_compl_arg(char_u *value, int vallen, int *complp, long *argt, char_u **compl_arg); diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index cb0bcf720b..b3d293639a 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -880,12 +880,13 @@ endfunc func Test_getcompletiontype() call assert_fails('call getcompletiontype()', 'E119:') call assert_fails('call getcompletiontype({})', 'E1174:') - call assert_equal(getcompletiontype(''), 'command') - call assert_equal(getcompletiontype('dummy '), '') - call assert_equal(getcompletiontype('cd '), 'dir_in_path') - call assert_equal(getcompletiontype('let v:n'), 'var') - call assert_equal(getcompletiontype('call tag'), 'function') - call assert_equal(getcompletiontype('help '), 'help') + call assert_equal('command', getcompletiontype('')) + call assert_equal('', getcompletiontype('dummy ')) + call assert_equal('', getcompletiontype('ls ')) + call assert_equal('dir_in_path', getcompletiontype('cd ')) + call assert_equal('var', getcompletiontype('let v:n')) + call assert_equal('function', getcompletiontype('call tag')) + call assert_equal('help', getcompletiontype('help ')) endfunc func Test_multibyte_expression() @@ -4202,6 +4203,8 @@ func Test_custom_completion() call feedkeys(":Test1 \=Check_custom_completion()\\", "xt") call feedkeys(":Test2 \=Check_customlist_completion()\\", "xt") + call assert_equal('custom,CustomComplete1', getcompletiontype('Test1 ')) + call assert_equal('customlist,CustomComplete2', getcompletiontype('Test2 ')) call assert_fails("call getcompletion('', 'custom')", 'E475:') call assert_fails("call getcompletion('', 'customlist')", 'E475:') diff --git a/src/usercmd.c b/src/usercmd.c index 9f1efb4b7e..0ed9598d83 100644 --- a/src/usercmd.c +++ b/src/usercmd.c @@ -486,16 +486,33 @@ get_commandtype(int expand) #ifdef FEAT_EVAL /* - * Get the name of completion type "expand" as a string. + * Get the name of completion type "expand" as an allocated string. + * "compl_arg" is the function name for "custom" and "customlist" types. + * Returns NULL if no completion is available or on allocation failure. */ char_u * -cmdcomplete_type_to_str(int expand) +cmdcomplete_type_to_str(int expand, char_u *compl_arg) { keyvalue_T *kv; + char_u *cmd_compl; kv = get_commandtype(expand); + if (kv == NULL || kv->value.string == NULL) + return NULL; - return (kv == NULL) ? NULL : kv->value.string; + cmd_compl = kv->value.string; + if (expand == EXPAND_USER_LIST || expand == EXPAND_USER_DEFINED) + { + char_u *buffer; + + buffer = alloc(STRLEN(cmd_compl) + STRLEN(compl_arg) + 2); + if (buffer == NULL) + return NULL; + sprintf((char *)buffer, "%s,%s", cmd_compl, compl_arg); + return buffer; + } + + return vim_strsave(cmd_compl); } /* diff --git a/src/version.c b/src/version.c index 6bd3f67eeb..ff3b32f392 100644 --- a/src/version.c +++ b/src/version.c @@ -719,6 +719,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1518, /**/ 1517, /**/