0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 9.0.2025: no cmdline completion for ++opt args

Problem:  no cmdline completion for ++opt args
Solution: Add cmdline completion for :e ++opt=arg and :terminal
          [++options]

closes: #13319

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
This commit is contained in:
Yee Cheng Chin
2023-10-14 11:46:51 +02:00
committed by Christian Brabandt
parent bd734c3bea
commit 989426be6e
12 changed files with 335 additions and 8 deletions

View File

@@ -1768,6 +1768,45 @@ set_context_for_wildcard_arg(
}
}
/*
* Set the completion context for the "++opt=arg" argument. Always returns
* NULL.
*/
static char_u *
set_context_in_argopt(expand_T *xp, char_u *arg)
{
char_u *p;
p = vim_strchr(arg, '=');
if (p == NULL)
xp->xp_pattern = arg;
else
xp->xp_pattern = p + 1;
xp->xp_context = EXPAND_ARGOPT;
return NULL;
}
#ifdef FEAT_TERMINAL
/*
* Set the completion context for :terminal's [options]. Always returns NULL.
*/
static char_u *
set_context_in_terminalopt(expand_T *xp, char_u *arg)
{
char_u *p;
p = vim_strchr(arg, '=');
if (p == NULL)
xp->xp_pattern = arg;
else
xp->xp_pattern = p + 1;
xp->xp_context = EXPAND_TERMINALOPT;
return NULL;
}
#endif
/*
* Set the completion context for the :filter command. Returns a pointer to the
* next command after the :filter command.
@@ -2491,13 +2530,28 @@ set_one_cmd_context(
arg = skipwhite(p);
// Skip over ++argopt argument
if ((ea.argt & EX_ARGOPT) && *arg != NUL && STRNCMP(arg, "++", 2) == 0)
// Does command allow "++argopt" argument?
if ((ea.argt & EX_ARGOPT) || ea.cmdidx == CMD_terminal)
{
p = arg;
while (*p && !vim_isspace(*p))
MB_PTR_ADV(p);
arg = skipwhite(p);
while (*arg != NUL && STRNCMP(arg, "++", 2) == 0)
{
p = arg + 2;
while (*p && !vim_isspace(*p))
MB_PTR_ADV(p);
// Still touching the command after "++"?
if (*p == NUL)
{
if (ea.argt & EX_ARGOPT)
return set_context_in_argopt(xp, arg + 2);
#ifdef FEAT_TERMINAL
if (ea.cmdidx == CMD_terminal)
return set_context_in_terminalopt(xp, arg + 2);
#endif
}
arg = skipwhite(p);
}
}
if (ea.cmdidx == CMD_write || ea.cmdidx == CMD_update)
@@ -3120,6 +3174,12 @@ ExpandFromContext(
ret = ExpandSettingSubtract(xp, &regmatch, numMatches, matches);
else if (xp->xp_context == EXPAND_MAPPINGS)
ret = ExpandMappings(pat, &regmatch, numMatches, matches);
else if (xp->xp_context == EXPAND_ARGOPT)
ret = expand_argopt(pat, xp, &regmatch, matches, numMatches);
#if defined(FEAT_TERMINAL)
else if (xp->xp_context == EXPAND_TERMINALOPT)
ret = expand_terminal_opt(pat, xp, &regmatch, matches, numMatches);
#endif
#if defined(FEAT_EVAL)
else if (xp->xp_context == EXPAND_USER_DEFINED)
ret = ExpandUserDefined(pat, xp, &regmatch, matches, numMatches);
@@ -3253,7 +3313,9 @@ ExpandGeneric(
if (!fuzzy && xp->xp_context != EXPAND_MENUNAMES
&& xp->xp_context != EXPAND_STRING_SETTING
&& xp->xp_context != EXPAND_MENUS
&& xp->xp_context != EXPAND_SCRIPTNAMES)
&& xp->xp_context != EXPAND_SCRIPTNAMES
&& xp->xp_context != EXPAND_ARGOPT
&& xp->xp_context != EXPAND_TERMINALOPT)
sort_matches = TRUE;
// <SNR> functions should be sorted to the end.