diff options
author | Yee Cheng Chin <ychin.git@gmail.com> | 2023-10-14 11:46:51 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-10-14 11:46:51 +0200 |
commit | 989426be6e9ae23d2413943890206cbe15d9df38 (patch) | |
tree | 3931aedc70ed18a7e3ea0f735359995fb26d1ef5 /src/cmdexpand.c | |
parent | bd734c3bead9e167eb6875f62cc06fab2379c422 (diff) |
patch 9.0.2025: no cmdline completion for ++opt argsv9.0.2025
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>
Diffstat (limited to 'src/cmdexpand.c')
-rw-r--r-- | src/cmdexpand.c | 76 |
1 files changed, 69 insertions, 7 deletions
diff --git a/src/cmdexpand.c b/src/cmdexpand.c index 20f3069ce2..d27e039443 100644 --- a/src/cmdexpand.c +++ b/src/cmdexpand.c @@ -1769,6 +1769,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, ®match, numMatches, matches); else if (xp->xp_context == EXPAND_MAPPINGS) ret = ExpandMappings(pat, ®match, numMatches, matches); + else if (xp->xp_context == EXPAND_ARGOPT) + ret = expand_argopt(pat, xp, ®match, matches, numMatches); +#if defined(FEAT_TERMINAL) + else if (xp->xp_context == EXPAND_TERMINALOPT) + ret = expand_terminal_opt(pat, xp, ®match, matches, numMatches); +#endif #if defined(FEAT_EVAL) else if (xp->xp_context == EXPAND_USER_DEFINED) ret = ExpandUserDefined(pat, xp, ®match, 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. |