0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 9.0.1520: completion for option name includes all bool options

Problem:    Completion for option name includes all bool options.
Solution:   Do not recognize the "noinv" prefix.  Prefix "no" or "inv" when
            appropriate.
This commit is contained in:
Bram Moolenaar
2023-05-06 22:21:11 +01:00
parent 0b70aeb49d
commit 048d9d2521
5 changed files with 40 additions and 7 deletions

View File

@@ -1012,14 +1012,31 @@ ExpandOne(
{ {
len = 0; len = 0;
for (i = 0; i < xp->xp_numfiles; ++i) for (i = 0; i < xp->xp_numfiles; ++i)
{
if (i > 0)
{
if (xp->xp_prefix == XP_PREFIX_NO)
len += 2; // prefix "no"
else if (xp->xp_prefix == XP_PREFIX_INV)
len += 3; // prefix "inv"
}
len += (long_u)STRLEN(xp->xp_files[i]) + 1; len += (long_u)STRLEN(xp->xp_files[i]) + 1;
}
ss = alloc(len); ss = alloc(len);
if (ss != NULL) if (ss != NULL)
{ {
*ss = NUL; *ss = NUL;
for (i = 0; i < xp->xp_numfiles; ++i) for (i = 0; i < xp->xp_numfiles; ++i)
{ {
if (i > 0)
{
if (xp->xp_prefix == XP_PREFIX_NO)
STRCAT(ss, "no");
else if (xp->xp_prefix == XP_PREFIX_INV)
STRCAT(ss, "inv");
}
STRCAT(ss, xp->xp_files[i]); STRCAT(ss, xp->xp_files[i]);
if (i != xp->xp_numfiles - 1) if (i != xp->xp_numfiles - 1)
STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " "); STRCAT(ss, (options & WILD_USE_NL) ? "\n" : " ");
} }
@@ -1044,6 +1061,7 @@ ExpandInit(expand_T *xp)
{ {
CLEAR_POINTER(xp); CLEAR_POINTER(xp);
xp->xp_backslash = XP_BS_NONE; xp->xp_backslash = XP_BS_NONE;
xp->xp_prefix = XP_PREFIX_NONE;
xp->xp_numfiles = -1; xp->xp_numfiles = -1;
} }

View File

@@ -7265,11 +7265,13 @@ set_context_in_set_cmd(
if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0) if (STRNCMP(p, "no", 2) == 0 && STRNCMP(p, "novice", 6) != 0)
{ {
xp->xp_context = EXPAND_BOOL_SETTINGS; xp->xp_context = EXPAND_BOOL_SETTINGS;
xp->xp_prefix = XP_PREFIX_NO;
p += 2; p += 2;
} }
if (STRNCMP(p, "inv", 3) == 0) else if (STRNCMP(p, "inv", 3) == 0)
{ {
xp->xp_context = EXPAND_BOOL_SETTINGS; xp->xp_context = EXPAND_BOOL_SETTINGS;
xp->xp_prefix = XP_PREFIX_INV;
p += 3; p += 3;
} }
xp->xp_pattern = arg = p; xp->xp_pattern = arg = p;
@@ -7528,7 +7530,7 @@ ExpandSettings(
if (options[opt_idx].var == NULL) if (options[opt_idx].var == NULL)
continue; continue;
if (xp->xp_context == EXPAND_BOOL_SETTINGS if (xp->xp_context == EXPAND_BOOL_SETTINGS
&& !(options[opt_idx].flags & P_BOOL)) && !(options[opt_idx].flags & P_BOOL))
continue; continue;
is_term_opt = istermoption_idx(opt_idx); is_term_opt = istermoption_idx(opt_idx);
if (is_term_opt && num_normal > 0) if (is_term_opt && num_normal > 0)
@@ -7600,7 +7602,7 @@ ExpandSettings(
name_buf[4] = NUL; name_buf[4] = NUL;
if (match_str(name_buf, regmatch, *matches, count, if (match_str(name_buf, regmatch, *matches, count,
(loop == 0), fuzzy, fuzzystr, fuzmatch)) (loop == 0), fuzzy, fuzzystr, fuzmatch))
{ {
if (loop == 0) if (loop == 0)
num_term++; num_term++;

View File

@@ -578,6 +578,12 @@ typedef struct
buffheader_T sr_old_redobuff; buffheader_T sr_old_redobuff;
} save_redo_T; } save_redo_T;
typedef enum {
XP_PREFIX_NONE, // prefix not used
XP_PREFIX_NO, // "no" prefix for bool option
XP_PREFIX_INV, // "inv" prefix for bool option
} xp_prefix_T;
/* /*
* used for completion on the command line * used for completion on the command line
*/ */
@@ -586,6 +592,7 @@ typedef struct expand
char_u *xp_pattern; // start of item to expand char_u *xp_pattern; // start of item to expand
int xp_context; // type of expansion int xp_context; // type of expansion
int xp_pattern_len; // bytes in xp_pattern before cursor int xp_pattern_len; // bytes in xp_pattern before cursor
xp_prefix_T xp_prefix;
#if defined(FEAT_EVAL) #if defined(FEAT_EVAL)
char_u *xp_arg; // completion function char_u *xp_arg; // completion function
sctx_T xp_script_ctx; // SCTX for completion function sctx_T xp_script_ctx; // SCTX for completion function

View File

@@ -278,13 +278,17 @@ func Test_set_completion()
call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:) call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
" Expand boolean options. When doing :set no<Tab> " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
" vim displays the options names without "no" but completion uses "no...". " names with "no".
call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set nodiff digraph', @:) call assert_equal('"set nodiff nodigraph', @:)
call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set invdiff digraph', @:) call assert_equal('"set invdiff invdigraph', @:)
" Expanding "set noinv" does nothing.
call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set noinv', @:)
" Expand abbreviation of options. " Expand abbreviation of options.
call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')

View File

@@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1520,
/**/ /**/
1519, 1519,
/**/ /**/