vim-patch:9.1.1509: patch 9.1.1505 was not good

Problem:  Patch 9.1.1505 was not good
Solution: Revert "patch 9.1.1505: not possible to return completion type
          for :ex command" and instead add the getcompletiontype()
          function (Hirohito Higashi).

related: vim/vim#17606
closes: vim/vim#17662

96b3ef2389

Cherry-pick Test_multibyte_expression() from Vim, as it passes.

Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
This commit is contained in:
zeertzjq
2025-07-06 08:41:41 +08:00
parent 6ebcb4a4d6
commit 9c04eb02ad
8 changed files with 121 additions and 59 deletions

View File

@ -3838,6 +3838,30 @@ theend:
ExpandCleanup(&xpc);
}
/// "getcompletiontype()" function
void f_getcompletiontype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
if (tv_check_for_string_arg(argvars, 0) == FAIL) {
return;
}
const char *pat = tv_get_string(&argvars[0]);
expand_T xpc;
ExpandInit(&xpc);
int cmdline_len = (int)strlen(pat);
set_cmd_context(&xpc, (char *)pat, cmdline_len, cmdline_len, false);
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
xpc.xp_col = cmdline_len;
rettv->vval.v_string = get_cmdline_completion(&xpc);
ExpandCleanup(&xpc);
}
/// "cmdcomplete_info()" function
void f_cmdcomplete_info(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{

View File

@ -3751,22 +3751,22 @@ M.funcs = {
signature = 'getcmdcomplpat()',
},
getcmdcompltype = {
args = { 0, 1 },
base = 1,
desc = [=[
Return the type of command-line completion using {pat}.
If {pat} is omited, only works when the command line is being
edited, thus requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
Return the type of the current command-line completion.
Only works when the command line is being edited, thus
requires use of |c_CTRL-\_e| or |c_CTRL-R_=|.
See |:command-completion| for the return string.
Also see |getcmdtype()|, |setcmdpos()|, |getcmdline()|,
|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()|.
]=],
name = 'getcmdcompltype',
params = { { 'pat', 'string' } },
params = {},
returns = 'string',
signature = 'getcmdcompltype([{pat}])',
signature = 'getcmdcompltype()',
},
getcmdline = {
desc = [=[
@ -3943,6 +3943,21 @@ M.funcs = {
returns = 'string[]',
signature = 'getcompletion({pat}, {type} [, {filtered}])',
},
getcompletiontype = {
args = 1,
base = 1,
desc = [=[
Return the type of the command-line completion using {pat}.
When no corresponding completion type is found, an empty
string is returned.
To get the current command-line completion type, use
|getcmdcompltype()|.
]=],
name = 'getcompletiontype',
params = { { 'pat', 'string' } },
returns = 'string',
signature = 'getcompletiontype({pat})',
},
getcurpos = {
args = { 0, 1 },
base = 1,

View File

@ -4197,8 +4197,8 @@ static char *get_cmdline_completion_pattern(void)
return xstrdup(compl_pat);
}
/// Get the current command-line completion type.
static char *get_cmdline_completion(expand_T *xpc)
/// Get the command-line completion type.
char *get_cmdline_completion(expand_T *xpc)
{
int xp_context = xpc->xp_context;
if (xp_context == EXPAND_NOTHING) {
@ -4235,34 +4235,15 @@ void f_getcmdcomplpat(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
/// "getcmdcompltype()" function
void f_getcmdcompltype(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
{
if (tv_check_for_opt_string_arg(argvars, 0) == FAIL) {
rettv->v_type = VAR_STRING;
rettv->vval.v_string = NULL;
CmdlineInfo *p = get_ccline_ptr();
if (cmdline_star > 0 || p == NULL || p->xpc == NULL) {
return;
}
rettv->v_type = VAR_STRING;
if (argvars[0].v_type != VAR_UNKNOWN) {
char *pat = (char *)tv_get_string(&argvars[0]);
expand_T xpc;
ExpandInit(&xpc);
int cmdline_len = (int)strlen(pat);
set_cmd_context(&xpc, pat, cmdline_len, cmdline_len, false);
xpc.xp_pattern_len = strlen(xpc.xp_pattern);
xpc.xp_col = cmdline_len;
rettv->v_type = VAR_STRING;
rettv->vval.v_string = get_cmdline_completion(&xpc);
ExpandCleanup(&xpc);
} else {
CmdlineInfo *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(p->xpc);
}
/// "getcmdline()" function