patch 9.0.1958: cannot complete option values

Problem:  cannot complete option values
Solution: Add completion functions for several options

Add cmdline tab-completion for setting string options

Add tab-completion for setting string options on the cmdline using
`:set=` (along with `:set+=` and `:set-=`).

The existing tab completion for setting options currently only works
when nothing is typed yet, and it only fills in with the existing value,
e.g. when the user does `:set diffopt=<Tab>` it will be completed to
`set diffopt=internal,filler,closeoff` and nothing else. This isn't too
useful as a user usually wants auto-complete to suggest all the possible
values, such as 'iblank', or 'algorithm:patience'.

For set= and set+=, this adds a new optional callback function for each
option that can be invoked when doing completion. This allows for each
option to have control over how completion works. For example, in
'diffopt', it will suggest the default enumeration, but if `algorithm:`
is selected, it will further suggest different algorithm types like
'meyers' and 'patience'. When using set=, the existing option value will
be filled in as the first choice to preserve the existing behavior. When
using set+= this won't happen as it doesn't make sense.

For flag list options (e.g. 'mouse' and 'guioptions'), completion will
take into account existing typed values (and in the case of set+=, the
existing option value) to make sure it doesn't suggest duplicates.

For set-=, there is a new `ExpandSettingSubtract` function which will
handle flag list and comma-separated options smartly, by only suggesting
values that currently exist in the option.

Note that Vim has some existing code that adds special handling for
'filetype', 'syntax', and misc dir options like 'backupdir'. This change
preserves them as they already work, instead of converting to the new
callback API for each option.

closes: #13182

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-09-29 20:42:32 +02:00
committed by Christian Brabandt
parent 3695d0e41b
commit 900894b09a
29 changed files with 2594 additions and 735 deletions

View File

@ -517,16 +517,26 @@ example, to match only files that end in ".c": >
:e *.c$
This will not match a file ending in ".cpp". Without the "$" it does match.
The old value of an option can be obtained by hitting 'wildchar' just after
the '='. For example, typing 'wildchar' after ":set dir=" will insert the
current value of 'dir'. This overrules file name completion for the options
that take a file name.
If you would like using <S-Tab> for CTRL-P in an xterm, put this command in
your .cshrc: >
xmodmap -e "keysym Tab = Tab Find"
And this in your .vimrc: >
:cmap <Esc>[1~ <C-P>
< *complete-set-option*
When setting an option using |:set=|, the old value of an option can be
obtained by hitting 'wildchar' just after the '='. For example, typing
'wildchar' after ":set dir=" will insert the current value of 'dir'. This
overrules file name completion for the options that take a file name.
When using |:set=|, |:set+=|, or |:set^=|, string options that have
pre-defined names or syntax (e.g. 'diffopt', 'listchars') or are a list of
single-character flags (e.g. 'shortmess') will also present a list of possible
values for completion when using 'wildchar'.
When using |:set-=|, comma-separated options like 'diffopt' or 'backupdir'
will show each item separately. Flag list options like 'shortmess' will show
both the entire old value and the individual flags. Otherwise completion will
just fill in with the entire old value.
==============================================================================
3. Ex command-lines *cmdline-lines*

View File

@ -71,7 +71,7 @@ achieve special effects. These options come in three forms:
'ttytype'
Warning: This may have a lot of side effects.
*:set-args* *E487* *E521*
*:set-args* *:set=* *E487* *E521*
:se[t] {option}={value} or
:se[t] {option}:{value}
Set string or number option to {value}.
@ -79,7 +79,9 @@ achieve special effects. These options come in three forms:
hex (preceded with 0x) or octal (preceded with '0').
The old value can be inserted by typing 'wildchar' (by
default this is a <Tab> or CTRL-E if 'compatible' is
set). See |cmdline-completion|.
set). Many string options with fixed syntax and names
also support completing known values. See
|cmdline-completion| and |complete-set-option|.
White space between {option} and '=' is allowed and
will be ignored. White space between '=' and {value}
is not allowed.
@ -113,6 +115,9 @@ achieve special effects. These options come in three forms:
When the option is a list of flags, {value} must be
exactly as they appear in the option. Remove flags
one by one to avoid problems.
The individual values from a comma separated list or
list of flags can be inserted by typing 'wildchar'.
See |complete-set-option|.
Also see |:set-args| above.
The {option} arguments to ":set" may be repeated. For example: >

View File

@ -3208,6 +3208,7 @@ $quote eval.txt /*$quote*
:set-inv options.txt /*:set-inv*
:set-termcap options.txt /*:set-termcap*
:set-verbose options.txt /*:set-verbose*
:set= options.txt /*:set=*
:set^= options.txt /*:set^=*
:set_env options.txt /*:set_env*
:setf options.txt /*:setf*
@ -6484,6 +6485,7 @@ complete-items insert.txt /*complete-items*
complete-popup insert.txt /*complete-popup*
complete-popuphidden insert.txt /*complete-popuphidden*
complete-script-local-functions cmdline.txt /*complete-script-local-functions*
complete-set-option cmdline.txt /*complete-set-option*
complete_CTRL-E insert.txt /*complete_CTRL-E*
complete_CTRL-Y insert.txt /*complete_CTRL-Y*
complete_add() builtin.txt /*complete_add()*

View File

@ -2737,6 +2737,16 @@ get_event_name(expand_T *xp UNUSED, int idx)
return (char_u *)event_names[idx - augroups.ga_len].name;
}
/*
* Function given to ExpandGeneric() to obtain the list of event names. Don't
* include groups.
*/
char_u *
get_event_name_no_group(expand_T *xp UNUSED, int idx)
{
return (char_u *)event_names[idx].name;
}
#if defined(FEAT_EVAL) || defined(PROTO)
/*

View File

@ -1266,6 +1266,7 @@ did_set_clipboard(optset_T *args UNUSED)
for (p = p_cb; *p != NUL; )
{
// Note: Keep this in sync with p_cb_values.
if (STRNCMP(p, "unnamed", 7) == 0 && (p[7] == ',' || p[7] == NUL))
{
new_unnamed |= CLIP_UNNAMED;

View File

@ -15,9 +15,6 @@
static int cmd_showtail; // Only show path tail in lists ?
static int ExpandGeneric(char_u *pat, expand_T *xp, regmatch_T *regmatch,
char_u ***matches, int *numMatches,
char_u *((*func)(expand_T *, int)), int escaped);
static int ExpandFromContext(expand_T *xp, char_u *, char_u ***, int *, int);
static char_u *showmatches_gettail(char_u *s);
static int expand_showtail(expand_T *xp);
@ -54,6 +51,8 @@ cmdline_fuzzy_completion_supported(expand_T *xp)
&& xp->xp_context != EXPAND_FILETYPE
&& xp->xp_context != EXPAND_HELP
&& xp->xp_context != EXPAND_OLD_SETTING
&& xp->xp_context != EXPAND_STRING_SETTING
&& xp->xp_context != EXPAND_SETTING_SUBTRACT
&& xp->xp_context != EXPAND_OWNSYNTAX
&& xp->xp_context != EXPAND_PACKADD
&& xp->xp_context != EXPAND_RUNTIME
@ -3093,6 +3092,10 @@ ExpandFromContext(
if (xp->xp_context == EXPAND_SETTINGS
|| xp->xp_context == EXPAND_BOOL_SETTINGS)
ret = ExpandSettings(xp, &regmatch, pat, numMatches, matches, fuzzy);
else if (xp->xp_context == EXPAND_STRING_SETTING)
ret = ExpandStringSetting(xp, &regmatch, numMatches, matches);
else if (xp->xp_context == EXPAND_SETTING_SUBTRACT)
ret = ExpandSettingSubtract(xp, &regmatch, numMatches, matches);
else if (xp->xp_context == EXPAND_MAPPINGS)
ret = ExpandMappings(pat, &regmatch, numMatches, matches);
#if defined(FEAT_EVAL)
@ -3121,7 +3124,7 @@ ExpandFromContext(
*
* Returns OK when no problems encountered, FAIL for error (out of memory).
*/
static int
int
ExpandGeneric(
char_u *pat,
expand_T *xp,
@ -3226,6 +3229,7 @@ ExpandGeneric(
// applies to the completion context. Menus and scriptnames should be kept
// in the specified order.
if (!fuzzy && xp->xp_context != EXPAND_MENUNAMES
&& xp->xp_context != EXPAND_STRING_SETTING
&& xp->xp_context != EXPAND_MENUS
&& xp->xp_context != EXPAND_SCRIPTNAMES)
sort_matches = TRUE;

View File

@ -2266,6 +2266,7 @@ diffopt_changed(void)
p = p_dip;
while (*p != NUL)
{
// Note: Keep this in sync with p_dip_values
if (STRNCMP(p, "filler", 6) == 0)
{
p += 6;
@ -2343,6 +2344,7 @@ diffopt_changed(void)
}
else if (STRNCMP(p, "algorithm:", 10) == 0)
{
// Note: Keep this in sync with p_dip_algorithm_values.
p += 10;
if (STRNCMP(p, "myers", 5) == 0)
{

View File

@ -2650,6 +2650,7 @@ check_opt_wim(void)
for (p = p_wim; *p; ++p)
{
// Note: Keep this in sync with p_wim_values.
for (i = 0; ASCII_ISALPHA(p[i]); ++i)
;
if (p[i] != NUL && p[i] != ',' && p[i] != ':')

View File

@ -3814,6 +3814,7 @@ highlight_changed(void)
if (attr > HL_ALL) // Combination with ':' is not allowed.
return FAIL;
// Note: Keep this in sync with expand_set_highlight().
switch (*p)
{
case 'b': attr |= HL_BOLD;

View File

@ -871,6 +871,7 @@ briopt_check(win_T *wp)
p = wp->w_p_briopt;
while (*p != NUL)
{
// Note: Keep this in sync with p_briopt_values
if (STRNCMP(p, "shift:", 6) == 0
&& ((p[6] == '-' && VIM_ISDIGIT(p[7])) || VIM_ISDIGIT(p[6])))
{

View File

@ -5782,3 +5782,16 @@ f_charclass(typval_T *argvars, typval_T *rettv UNUSED)
rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
}
#endif
/*
* Function given to ExpandGeneric() to obtain the possible arguments of the
* encoding options.
*/
char_u *
get_encoding_name(expand_T *xp UNUSED, int idx)
{
if (idx >= (int)(sizeof(enc_canon_table) / sizeof(enc_canon_table[0])))
return NULL;
return (char_u*)enc_canon_table[idx].name;
}

View File

@ -1632,7 +1632,7 @@ stropt_copy_value(
// For MS-DOS and WIN32 backslashes before normal file name characters
// are not removed, and keep backslash at start, for "\\machine\path",
// but do remove it for "\\\\machine\\path".
// The reverse is found in ExpandOldSetting().
// The reverse is found in escape_option_str_cmdline().
while (*arg != NUL && !VIM_ISWHITE(*arg))
{
int i;
@ -1837,7 +1837,7 @@ stropt_get_newval(
&(options[opt_idx]), OPT_GLOBAL));
else
{
++arg; // jump to after the '=' or ':'
++arg; // joption_value2stringump to after the '=' or ':'
// Set 'keywordprg' to ":help" if an empty
// value was passed to :set by the user.
@ -7232,8 +7232,10 @@ set_imsearch_global(void)
}
static int expand_option_idx = -1;
static int expand_option_start_col = 0;
static char_u expand_option_name[5] = {'t', '_', NUL, NUL, NUL};
static int expand_option_flags = 0;
static int expand_option_append = FALSE;
void
set_context_in_set_cmd(
@ -7348,8 +7350,14 @@ set_context_in_set_cmd(
}
}
// handle "-=" and "+="
expand_option_append = FALSE;
int expand_option_subtract = FALSE;
if ((nextchar == '-' || nextchar == '+' || nextchar == '^') && p[1] == '=')
{
if (nextchar == '-')
expand_option_subtract = TRUE;
if (nextchar == '+' || nextchar == '^')
expand_option_append = TRUE;
++p;
nextchar = '=';
}
@ -7359,22 +7367,20 @@ set_context_in_set_cmd(
xp->xp_context = EXPAND_UNSUCCESSFUL;
return;
}
if (xp->xp_context != EXPAND_BOOL_SETTINGS && p[1] == NUL)
{
xp->xp_context = EXPAND_OLD_SETTING;
if (is_term_option)
expand_option_idx = -1;
else
expand_option_idx = opt_idx;
xp->xp_pattern = p + 1;
return;
}
xp->xp_context = EXPAND_NOTHING;
if (is_term_option || (flags & P_NUM))
return;
// Below are for handling expanding a specific option's value after the '='
// or ':'
if (is_term_option)
expand_option_idx = -1;
else
expand_option_idx = opt_idx;
xp->xp_pattern = p + 1;
expand_option_start_col = (int)(p + 1 - xp->xp_line);
// Certain options currently have special case handling to reuse the
// expansion logic with other commands.
#ifdef FEAT_SYN_HL
if (options[opt_idx].var == (char_u *)&p_syn)
{
@ -7382,7 +7388,38 @@ set_context_in_set_cmd(
return;
}
#endif
if (options[opt_idx].var == (char_u *)&p_ft)
{
xp->xp_context = EXPAND_FILETYPE;
return;
}
// Now pick. If the option has a custom expander, use that. Otherwise, just
// fill with the existing option value.
if (expand_option_subtract)
{
xp->xp_context = EXPAND_SETTING_SUBTRACT;
return;
}
else if (expand_option_idx >= 0 &&
options[expand_option_idx].opt_expand_cb != NULL)
{
xp->xp_context = EXPAND_STRING_SETTING;
}
else if (*xp->xp_pattern == NUL)
{
xp->xp_context = EXPAND_OLD_SETTING;
return;
}
else
xp->xp_context = EXPAND_NOTHING;
if (is_term_option || (flags & P_NUM))
return;
// Only string options below
// Options that have P_EXPAND are considered to all use file/dir expansion.
if (flags & P_EXPAND)
{
p = options[opt_idx].var;
@ -7403,10 +7440,6 @@ set_context_in_set_cmd(
else
xp->xp_backslash = XP_BS_ONE;
}
else if (p == (char_u *)&p_ft)
{
xp->xp_context = EXPAND_FILETYPE;
}
else
{
xp->xp_context = EXPAND_FILES;
@ -7418,34 +7451,55 @@ set_context_in_set_cmd(
}
}
// For an option that is a list of file names, find the start of the
// last file name.
for (p = arg + STRLEN(arg) - 1; p > xp->xp_pattern; --p)
// For an option that is a list of file names, or comma/colon-separated
// values, split it by the delimiter and find the start of the current
// pattern, while accounting for backslash-escaped space/commas/colons.
// Triple-backslashed escaped file names (e.g. 'path') can also be
// delimited by space.
if ((flags & P_EXPAND) || (flags & P_COMMA) || (flags & P_COLON))
{
// count number of backslashes before ' ' or ','
if (*p == ' ' || *p == ',')
for (p = arg + STRLEN(arg) - 1; p >= xp->xp_pattern; --p)
{
s = p;
while (s > xp->xp_pattern && *(s - 1) == '\\')
--s;
if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
|| (*p == ',' && (flags & P_COMMA) && ((p - s) & 1) == 0))
// count number of backslashes before ' ' or ',' or ':'
if (*p == ' ' || *p == ',' ||
(*p == ':' && (flags & P_COLON)))
{
xp->xp_pattern = p + 1;
break;
s = p;
while (s > xp->xp_pattern && *(s - 1) == '\\')
--s;
if ((*p == ' ' && (xp->xp_backslash == XP_BS_THREE && (p - s) < 3))
|| (*p == ',' && (flags & P_COMMA) && ((p - s) % 1) == 0)
|| (*p == ':' && (flags & P_COLON)))
{
xp->xp_pattern = p + 1;
break;
}
}
}
#ifdef FEAT_SPELL
// for 'spellsuggest' start at "file:"
if (options[opt_idx].var == (char_u *)&p_sps
&& STRNCMP(p, "file:", 5) == 0)
{
xp->xp_pattern = p + 5;
break;
}
#endif
}
// An option that is a list of single-character flags should always start
// at the end as we don't complete words.
if (flags & P_FLAGLIST)
xp->xp_pattern = arg + STRLEN(arg);
// Some options can either be using file/dir expansions, or custom value
// expansion depending on what the user typed. Unfortunately we have to
// manually handle it here to make sure we have the correct xp_context set.
#ifdef FEAT_SPELL
if (options[opt_idx].var == (char_u *)&p_sps)
{
if (STRNCMP(xp->xp_pattern, "file:", 5) == 0)
{
xp->xp_pattern += 5;
return;
}
else if (options[expand_option_idx].opt_expand_cb != NULL)
{
xp->xp_context = EXPAND_STRING_SETTING;
}
}
#endif
}
/*
@ -7464,7 +7518,7 @@ set_context_in_set_cmd(
* If 'test_only' is FALSE and 'fuzzy' is TRUE and if 'str' fuzzy matches
* 'fuzzystr', then stores the match details in fuzmatch[idx] and returns TRUE.
*/
static int
int
match_str(
char_u *str,
regmatch_T *regmatch,
@ -7711,6 +7765,37 @@ ExpandSettings(
return OK;
}
// Escape an option value that can be used on the command-line with :set.
// Caller needs to free the returned string, unless NULL is returned.
static char_u*
escape_option_str_cmdline(char_u *var)
{
char_u *buf;
// A backslash is required before some characters. This is the reverse of
// what happens in do_set().
buf = vim_strsave_escaped(var, escape_chars);
if (buf == NULL)
return NULL;
#ifdef BACKSLASH_IN_FILENAME
// For MS-Windows et al. we don't double backslashes at the start and
// before a file name character.
// The reverse is found at stropt_copy_value().
for (var = buf; *var != NUL; MB_PTR_ADV(var))
if (var[0] == '\\' && var[1] == '\\'
&& expand_option_idx >= 0
&& (options[expand_option_idx].flags & P_EXPAND)
&& vim_isfilec(var[2])
&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
STRMOVE(var, var + 1);
#endif
return buf;
}
/*
* Expansion handler for :set= when we just want to fill in with the existing value.
*/
int
ExpandOldSetting(int *numMatches, char_u ***matches)
{
@ -7718,7 +7803,7 @@ ExpandOldSetting(int *numMatches, char_u ***matches)
char_u *buf;
*numMatches = 0;
*matches = ALLOC_ONE(char_u *);
*matches = ALLOC_MULT(char_u *, 1);
if (*matches == NULL)
return FAIL;
@ -7739,33 +7824,210 @@ ExpandOldSetting(int *numMatches, char_u ***matches)
else if (var == NULL)
var = (char_u *)"";
// A backslash is required before some characters. This is the reverse of
// what happens in do_set().
buf = vim_strsave_escaped(var, escape_chars);
buf = escape_option_str_cmdline(var);
if (buf == NULL)
{
VIM_CLEAR(*matches);
return FAIL;
}
#ifdef BACKSLASH_IN_FILENAME
// For MS-Windows et al. we don't double backslashes at the start and
// before a file name character.
for (var = buf; *var != NUL; MB_PTR_ADV(var))
if (var[0] == '\\' && var[1] == '\\'
&& expand_option_idx >= 0
&& (options[expand_option_idx].flags & P_EXPAND)
&& vim_isfilec(var[2])
&& (var[2] != '\\' || (var == buf && var[4] != '\\')))
STRMOVE(var, var + 1);
#endif
*matches[0] = buf;
(*matches)[0] = buf;
*numMatches = 1;
return OK;
}
/*
* Expansion handler for :set=/:set+= when the option has a custom expansion handler.
*/
int
ExpandStringSetting(
expand_T *xp,
regmatch_T *regmatch,
int *numMatches,
char_u ***matches)
{
char_u *var = NULL; // init for GCC
char_u *buf;
if (expand_option_idx < 0 ||
options[expand_option_idx].opt_expand_cb == NULL)
{
// Not supposed to reach this. This function is only for options with
// custom expansion callbacks.
return FAIL;
}
optexpand_T args;
args.oe_varp = get_varp_scope(&options[expand_option_idx], expand_option_flags);
args.oe_append = expand_option_append;
args.oe_regmatch = regmatch;
args.oe_xp = xp;
args.oe_set_arg = xp->xp_line + expand_option_start_col;
args.oe_include_orig_val =
!expand_option_append &&
(*args.oe_set_arg == NUL);
// Retrieve the existing value, but escape it as a reverse of setting it.
// We technically only need to do this when oe_append or
// oe_include_orig_val is true.
option_value2string(&options[expand_option_idx], expand_option_flags);
var = NameBuff;
buf = escape_option_str_cmdline(var);
if (buf == NULL)
return FAIL;
args.oe_opt_value = buf;
int num_ret = options[expand_option_idx].opt_expand_cb(&args, numMatches, matches);
vim_free(buf);
return num_ret;
}
/*
* Expansion handler for :set-=
*/
int
ExpandSettingSubtract(
expand_T *xp,
regmatch_T *regmatch,
int *numMatches,
char_u ***matches)
{
if (expand_option_idx < 0)
// term option
return ExpandOldSetting(numMatches, matches);
char_u *option_val = *(char_u**)get_option_varp_scope(
expand_option_idx, expand_option_flags);
long_u option_flags = options[expand_option_idx].flags;
if (option_flags & P_NUM)
return ExpandOldSetting(numMatches, matches);
else if (option_flags & P_COMMA)
{
// Split the option by comma, then present each option to the user if
// it matches the pattern.
// This condition needs to go first, because 'whichwrap' has both
// P_COMMA and P_FLAGLIST.
garray_T ga;
char_u *item;
char_u *option_copy;
char_u *next_val;
char_u *comma;
if (*option_val == NUL)
return FAIL;
// Make a copy as we need to inject null characters destructively.
option_copy = vim_strsave(option_val);
if (option_copy == NULL)
return FAIL;
next_val = option_copy;
ga_init2(&ga, sizeof(char_u *), 10);
do
{
item = next_val;
comma = vim_strchr(next_val, ',');
while (comma != NULL && comma != next_val && *(comma - 1) == '\\')
{
// "\," is interpreted as a literal comma rather than option
// separator when reading options in copy_option_part(). Skip
// it.
comma = vim_strchr(comma + 1, ',');
}
if (comma != NULL)
{
*comma = NUL; // null-terminate this value, required by later functions
next_val = comma + 1;
}
else
next_val = NULL;
if (*item == NUL)
// empty value, don't add to list
continue;
if (!vim_regexec(regmatch, item, (colnr_T)0))
continue;
char_u *buf = escape_option_str_cmdline(item);
if (buf == NULL)
{
vim_free(option_copy);
ga_clear_strings(&ga);
return FAIL;
}
if (ga_add_string(&ga, buf) != OK)
{
vim_free(buf);
break;
}
} while (next_val != NULL);
vim_free(option_copy);
*matches = ga.ga_data;
*numMatches = ga.ga_len;
return OK;
}
else if (option_flags & P_FLAGLIST)
{
// Only present the flags that are set on the option as the other flags
// are not meaningful to do set-= on.
if (*xp->xp_pattern != NUL)
{
// Don't suggest anything if cmdline is non-empty. Vim's set-=
// behavior requires consecutive strings and it's usually
// unintuitive to users if ther try to subtract multiple flags at
// once.
return FAIL;
}
int num_flags = STRLEN(option_val);
if (num_flags == 0)
return FAIL;
*matches = ALLOC_MULT(char_u *, num_flags + 1);
if (*matches == NULL)
return FAIL;
int count = 0;
char_u *p;
p = vim_strsave(option_val);
if (p == NULL)
{
VIM_CLEAR(*matches);
return FAIL;
}
(*matches)[count++] = p;
if (num_flags > 1)
{
// If more than one flags, split the flags up and expose each
// character as individual choice.
for (char_u *flag = option_val; *flag != NUL; flag++)
{
char_u *p = vim_strnsave(flag, 1);
if (p == NULL)
break;
(*matches)[count++] = p;
}
}
*numMatches = count;
return OK;
}
return ExpandOldSetting(numMatches, matches);
}
/*
* Get the value for the numeric or string option *opp in a nice format into
* NameBuff[]. Must not be called with a hidden option!
@ -8097,6 +8359,7 @@ fill_culopt_flags(char_u *val, win_T *wp)
p = val;
while (*p != NUL)
{
// Note: Keep this in sync with p_culopt_values.
if (STRNCMP(p, "line", 4) == 0)
{
p += 4;

View File

@ -60,6 +60,7 @@
#define P_RWINONLY 0x10000000L // only redraw current window
#define P_MLE 0x20000000L // under control of 'modelineexpr'
#define P_FUNC 0x40000000L // accept a function reference or a lambda
#define P_COLON 0x80000000L // values use colons to create sublists
// Returned by get_option_value().
typedef enum {
@ -230,7 +231,7 @@ typedef enum {
#define CPO_ALL "aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\\.;"
// characters for p_ww option:
#define WW_ALL "bshl<>[],~"
#define WW_ALL "bshl<>[]~"
// characters for p_mouse option:
#define MOUSE_NORMAL 'n' // use mouse in Normal mode

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1803,6 +1803,7 @@ parse_popup_option(win_T *wp, int is_preview)
dig = e + 1;
x = getdigits(&dig);
// Note: Keep this in sync with p_popup_option_values.
if (STRNCMP(s, "height:", 7) == 0)
{
if (dig != p)
@ -1840,6 +1841,7 @@ parse_popup_option(win_T *wp, int is_preview)
}
else if (STRNCMP(s, "border:", 7) == 0)
{
// Note: Keep this in sync with p_popup_option_border_values.
char_u *arg = s + 7;
int on = STRNCMP(arg, "on", 2) == 0 && arg + 2 == p;
int off = STRNCMP(arg, "off", 3) == 0 && arg + 3 == p;
@ -1858,6 +1860,7 @@ parse_popup_option(win_T *wp, int is_preview)
}
else if (STRNCMP(s, "align:", 6) == 0)
{
// Note: Keep this in sync with p_popup_option_align_values.
char_u *arg = s + 6;
int item = STRNCMP(arg, "item", 4) == 0 && arg + 4 == p;
int menu = STRNCMP(arg, "menu", 4) == 0 && arg + 4 == p;

View File

@ -39,6 +39,7 @@ int has_autocmd(event_T event, char_u *sfname, buf_T *buf);
char_u *get_augroup_name(expand_T *xp, int idx);
char_u *set_context_in_autocmd(expand_T *xp, char_u *arg, int doautocmd);
char_u *get_event_name(expand_T *xp, int idx);
char_u *get_event_name_no_group(expand_T *xp, int idx);
int autocmd_supported(char_u *name);
int au_exists(char_u *arg);
void f_autocmd_add(typval_T *argvars, typval_T *rettv);

View File

@ -9,6 +9,7 @@ int cmdline_compl_startcol(void);
char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode);
void ExpandInit(expand_T *xp);
void ExpandCleanup(expand_T *xp);
int ExpandGeneric(char_u *pat, expand_T *xp, regmatch_T *regmatch, char_u ***matches, int *numMatches, char_u *((*func)(expand_T *, int)), int escaped);
int showmatches(expand_T *xp, int wildmenu);
char_u *addstar(char_u *fname, int len, int context);
void set_expand_context(expand_T *xp);

View File

@ -88,4 +88,5 @@ char_u *string_convert_ext(vimconv_T *vcp, char_u *ptr, int *lenp, int *unconvle
void f_setcellwidths(typval_T *argvars, typval_T *rettv);
void f_getcellwidths(typval_T *argvars, typval_T *rettv);
void f_charclass(typval_T *argvars, typval_T *rettv);
char_u *get_encoding_name(expand_T *xp, int idx);
/* vim: set ft=c : */

View File

@ -129,6 +129,8 @@ void set_imsearch_global(void);
void set_context_in_set_cmd(expand_T *xp, char_u *arg, int opt_flags);
int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char_u *fuzzystr, int *numMatches, char_u ***matches, int can_fuzzy);
int ExpandOldSetting(int *numMatches, char_u ***matches);
int ExpandStringSetting(expand_T *xp, regmatch_T *regmatch, int *numMatches, char_u ***matches);
int ExpandSettingSubtract(expand_T *xp, regmatch_T *regmatch, int *numMatches, char_u ***matches);
int shortmess(int x);
void vimrc_found(char_u *fname, char_u *envname);
void change_compatible(int on);

View File

@ -122,6 +122,71 @@ char *did_set_wildoptions(optset_T *args);
char *did_set_winaltkeys(optset_T *args);
char *did_set_wincolor(optset_T *args);
char *did_set_string_option(int opt_idx, char_u **varp, char_u *oldval, char_u *value, char *errbuf, int opt_flags, int *value_checked);
int expand_set_ambiwidth(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_background(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_backspace(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_backupcopy(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_belloff(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_breakindentopt(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_browsedir(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_bufhidden(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_buftype(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_casemap(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_chars_option(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_clipboard(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_complete(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_completeopt(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_completeslash(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_concealcursor(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_cpoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_cryptmethod(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_cursorlineopt(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_debug(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_diffopt(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_display(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_eadirection(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_encoding(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_eventignore(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_fileformat(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_foldclose(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_foldmethod(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_foldopen(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_formatoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_guioptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_highlight(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_jumpoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_keymodel(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_keyprotocol(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_lispoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_mouse(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_mousemodel(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_nrformats(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_popupoption(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_printoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_rightleftcmd(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_scrollopt(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_selection(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_selectmode(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_sessionoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_shortmess(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_showcmdloc(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_signcolumn(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_spelloptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_spellsuggest(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_splitkeep(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_swapsync(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_switchbuf(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_tagcase(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_termwintype(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_toolbar(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_toolbariconsize(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_ttymouse(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_virtualedit(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_whichwrap(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_wildmode(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_wildoptions(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_winaltkeys(optexpand_T *args, int *numMatches, char_u ***matches);
int expand_set_wincolor(optexpand_T *args, int *numMatches, char_u ***matches);
int check_ff_value(char_u *p);
void save_clear_shm_value(void);
void restore_shm_value(void);

View File

@ -57,5 +57,7 @@ int screen_screencol(void);
int screen_screenrow(void);
char *set_fillchars_option(win_T *wp, char_u *val, int apply);
char *set_listchars_option(win_T *wp, char_u *val, int apply);
char_u * get_fillchars_name(expand_T *xp, int idx);
char_u * get_listchars_name(expand_T *xp, int idx);
char *check_chars_options(void);
/* vim: set ft=c : */

View File

@ -4658,6 +4658,43 @@ get_encoded_char_adv(char_u **p)
return mb_ptr2char_adv(p);
}
struct charstab
{
int *cp;
char *name;
};
static fill_chars_T fill_chars;
static struct charstab filltab[] =
{
{&fill_chars.stl, "stl"},
{&fill_chars.stlnc, "stlnc"},
{&fill_chars.vert, "vert"},
{&fill_chars.fold, "fold"},
{&fill_chars.foldopen, "foldopen"},
{&fill_chars.foldclosed, "foldclose"},
{&fill_chars.foldsep, "foldsep"},
{&fill_chars.diff, "diff"},
{&fill_chars.eob, "eob"},
{&fill_chars.lastline, "lastline"},
};
static lcs_chars_T lcs_chars;
static struct charstab lcstab[] =
{
{&lcs_chars.eol, "eol"},
{&lcs_chars.ext, "extends"},
{&lcs_chars.nbsp, "nbsp"},
{&lcs_chars.prec, "precedes"},
{&lcs_chars.space, "space"},
{&lcs_chars.tab2, "tab"},
{&lcs_chars.trail, "trail"},
{&lcs_chars.lead, "lead"},
#ifdef FEAT_CONCEAL
{&lcs_chars.conceal, "conceal"},
#else
{NULL, "conceal"},
#endif
};
/*
* Handle setting 'listchars' or 'fillchars'.
* "value" points to either the global or the window-local value.
@ -4677,46 +4714,8 @@ set_chars_option(win_T *wp, char_u *value, int is_listchars, int apply)
int multispace_len = 0; // Length of lcs-multispace string
int lead_multispace_len = 0; // Length of lcs-leadmultispace string
struct charstab
{
int *cp;
char *name;
};
struct charstab *tab;
static fill_chars_T fill_chars;
static struct charstab filltab[] =
{
{&fill_chars.stl, "stl"},
{&fill_chars.stlnc, "stlnc"},
{&fill_chars.vert, "vert"},
{&fill_chars.fold, "fold"},
{&fill_chars.foldopen, "foldopen"},
{&fill_chars.foldclosed, "foldclose"},
{&fill_chars.foldsep, "foldsep"},
{&fill_chars.diff, "diff"},
{&fill_chars.eob, "eob"},
{&fill_chars.lastline, "lastline"},
};
static lcs_chars_T lcs_chars;
struct charstab lcstab[] =
{
{&lcs_chars.eol, "eol"},
{&lcs_chars.ext, "extends"},
{&lcs_chars.nbsp, "nbsp"},
{&lcs_chars.prec, "precedes"},
{&lcs_chars.space, "space"},
{&lcs_chars.tab2, "tab"},
{&lcs_chars.trail, "trail"},
{&lcs_chars.lead, "lead"},
#ifdef FEAT_CONCEAL
{&lcs_chars.conceal, "conceal"},
#else
{NULL, "conceal"},
#endif
};
if (is_listchars)
{
tab = lcstab;
@ -4956,6 +4955,32 @@ set_listchars_option(win_T *wp, char_u *val, int apply)
return set_chars_option(wp, val, TRUE, apply);
}
/*
* Function given to ExpandGeneric() to obtain possible arguments of the
* 'fillchars' option.
*/
char_u *
get_fillchars_name(expand_T *xp UNUSED, int idx)
{
if (idx >= (int)(sizeof(filltab) / sizeof(filltab[0])))
return NULL;
return (char_u*)filltab[idx].name;
}
/*
* Function given to ExpandGeneric() to obtain possible arguments of the
* 'listchars' option.
*/
char_u *
get_listchars_name(expand_T *xp UNUSED, int idx)
{
if (idx >= (int)(sizeof(lcstab) / sizeof(lcstab[0])))
return NULL;
return (char_u*)lcstab[idx].name;
}
/*
* Check all global and local values of 'listchars' and 'fillchars'.
* Return an untranslated error messages if any of them is invalid, NULL

View File

@ -424,6 +424,7 @@ spell_check_sps(void)
if (*s != NUL && !VIM_ISDIGIT(*s))
f = -1;
}
// Note: Keep this in sync with p_sps_values.
else if (STRCMP(buf, "best") == 0)
f = SPS_BEST;
else if (STRCMP(buf, "fast") == 0)

View File

@ -4914,6 +4914,34 @@ typedef struct
char *os_errbuf;
} optset_T;
/*
* Argument for the callback function (opt_expand_cb_T) invoked after a string
* option value is expanded for cmdline completion.
*/
typedef struct
{
// Pointer to the option variable. It's always a string.
char_u *oe_varp;
// The original option value, escaped.
char_u *oe_opt_value;
// TRUE if using set+= instead of set=
int oe_append;
// TRUE if we would like to add the original option value as the first
// choice.
int oe_include_orig_val;
// Regex from the cmdline, for matching potential options against.
regmatch_T *oe_regmatch;
// The expansion context.
expand_T *oe_xp;
// The full argument passed to :set. For example, if the user inputs
// ':set dip=icase,algorithm:my<Tab>', oe_xp->xp_pattern will only have
// 'my', but oe_set_arg will contain the whole 'icase,algorithm:my'.
char_u *oe_set_arg;
} optexpand_T;
/*
* Spell checking variables passed from win_update() to win_line().
*/

View File

@ -1913,6 +1913,7 @@ match_keyprotocol(char_u *term)
*colon = NUL;
keyprot_T prot;
// Note: Keep this in sync with p_kpc_protocol_values.
if (STRCMP(colon + 1, "none") == 0)
prot = KEYPROTOCOL_NONE;
else if (STRCMP(colon + 1, "mok2") == 0)

View File

@ -295,11 +295,11 @@ func Test_set_completion()
call assert_equal('"set tabstop thesaurus thesaurusfunc ttyscroll', @:)
" Expand current value
call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:)
call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:)
call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
" Expand key codes.
call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
@ -360,13 +360,17 @@ func Test_set_completion()
call assert_equal("\"set invtabstop=", @:)
" Expand options for 'spellsuggest'
call feedkeys(":set spellsuggest=best,file:xyz\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set spellsuggest=best,file:xyz", @:)
call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
" Expand value for 'key'
set key=abcd
call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set key=*****', @:)
call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set key-=*****', @:)
set key=
" Expand values for 'filetype'
@ -382,6 +386,278 @@ func Test_set_completion()
call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
endfunc
" Test handling of expanding individual string option values
func Test_set_completion_string_values()
"
" Test basic enum string options that have well-defined enum names
"
call assert_equal(getcompletion('set display=', 'cmdline'), ['lastline', 'truncate', 'uhex'])
call assert_equal(getcompletion('set display=t', 'cmdline'), ['truncate'])
call assert_equal(getcompletion('set display=*ex*', 'cmdline'), ['uhex'])
" Test that if a value is set, it will populate the results, but only if
" typed value is empty.
set display=uhex,lastline
call assert_equal(getcompletion('set display=', 'cmdline'), ['uhex,lastline', 'lastline', 'truncate', 'uhex'])
call assert_equal(getcompletion('set display=u', 'cmdline'), ['uhex'])
" If the set value is part of the enum list, it will show as the first
" result with no duplicate.
set display=uhex
call assert_equal(getcompletion('set display=', 'cmdline'), ['uhex', 'lastline', 'truncate'])
" If empty value, will just show the normal list without an empty item
set display=
call assert_equal(getcompletion('set display=', 'cmdline'), ['lastline', 'truncate', 'uhex'])
" Test escaping of the values
call assert_equal(getcompletion('set fillchars=', 'cmdline')[0], 'vert:\|,fold:-,eob:~,lastline:@')
" Test comma-separated lists will expand after a comma.
call assert_equal(getcompletion('set display=truncate,*ex*', 'cmdline'), ['uhex'])
" Also test the positioning of the expansion is correct
call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set display=truncate,lastline', @:)
set display&
" Test single-value options will not expand after a comma
call assert_equal(getcompletion('set ambw=single,', 'cmdline'), [])
" Test the other simple options to make sure they have basic auto-complete,
" but don't exhaustively validate their results.
call assert_equal(getcompletion('set ambw=', 'cmdline')[0], 'single')
call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
call assert_equal(getcompletion('set backspace=', 'cmdline')[0], 'indent')
call assert_equal(getcompletion('set backupcopy=', 'cmdline')[1], 'yes')
call assert_equal(getcompletion('set belloff=', 'cmdline')[1], 'backspace')
call assert_equal(getcompletion('set briopt=', 'cmdline')[1], 'min:')
if exists('+browsedir')
call assert_equal(getcompletion('set browsedir=', 'cmdline')[1], 'current')
endif
call assert_equal(getcompletion('set bufhidden=', 'cmdline')[1], 'unload')
call assert_equal(getcompletion('set buftype=', 'cmdline')[1], 'nowrite')
call assert_equal(getcompletion('set casemap=', 'cmdline')[1], 'internal')
if exists('+clipboard')
call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
endif
call assert_equal(getcompletion('set complete=', 'cmdline')[1], '.')
call assert_equal(getcompletion('set completeopt=', 'cmdline')[1], 'menu')
if exists('+completeslash')
call assert_equal(getcompletion('set completeslash=', 'cmdline')[1], 'backslash')
endif
if exists('+cryptmethod')
call assert_equal(getcompletion('set cryptmethod=', 'cmdline')[1], 'zip')
endif
if exists('+cursorlineopt')
call assert_equal(getcompletion('set cursorlineopt=', 'cmdline')[1], 'line')
endif
call assert_equal(getcompletion('set debug=', 'cmdline')[1], 'throw')
call assert_equal(getcompletion('set eadirection=', 'cmdline')[1], 'ver')
call assert_equal(getcompletion('set fileformat=', 'cmdline')[2], 'mac')
if exists('+foldclose')
call assert_equal(getcompletion('set foldclose=', 'cmdline')[0], 'all')
endif
if exists('+foldmethod')
call assert_equal(getcompletion('set foldmethod=', 'cmdline')[1], 'expr')
endif
if exists('+foldopen')
call assert_equal(getcompletion('set foldopen=', 'cmdline')[1], 'all')
endif
call assert_equal(getcompletion('set jumpoptions=', 'cmdline')[0], 'stack')
call assert_equal(getcompletion('set keymodel=', 'cmdline')[1], 'stopsel')
call assert_equal(getcompletion('set lispoptions=', 'cmdline')[1], 'expr:1')
call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
call assert_equal(getcompletion('set nrformats=', 'cmdline')[1], 'bin')
if exists('+rightleftcmd')
call assert_equal(getcompletion('set rightleftcmd=', 'cmdline')[0], 'search')
endif
call assert_equal(getcompletion('set scrollopt=', 'cmdline')[1], 'ver')
call assert_equal(getcompletion('set selection=', 'cmdline')[1], 'exclusive')
call assert_equal(getcompletion('set selectmode=', 'cmdline')[1], 'key')
if exists('+ssop')
call assert_equal(getcompletion('set ssop=', 'cmdline')[1], 'buffers')
endif
call assert_equal(getcompletion('set showcmdloc=', 'cmdline')[1], 'statusline')
if exists('+signcolumn')
call assert_equal(getcompletion('set signcolumn=', 'cmdline')[1], 'yes')
endif
if exists('+spelloptions')
call assert_equal(getcompletion('set spelloptions=', 'cmdline')[0], 'camel')
endif
if exists('+spellsuggest')
call assert_equal(getcompletion('set spellsuggest+=', 'cmdline')[0], 'best')
endif
call assert_equal(getcompletion('set splitkeep=', 'cmdline')[1], 'screen')
call assert_equal(getcompletion('set swapsync=', 'cmdline')[1], 'sync')
call assert_equal(getcompletion('set switchbuf=', 'cmdline')[1], 'usetab')
call assert_equal(getcompletion('set tagcase=', 'cmdline')[1], 'ignore')
if exists('+termwintype')
call assert_equal(getcompletion('set termwintype=', 'cmdline')[1], 'conpty')
endif
if exists('+toolbar')
call assert_equal(getcompletion('set toolbar=', 'cmdline')[1], 'text')
endif
if exists('+tbis')
call assert_equal(getcompletion('set tbis=', 'cmdline')[2], 'medium')
endif
if exists('+ttymouse')
set ttymouse=
call assert_equal(getcompletion('set ttymouse=', 'cmdline')[1], 'xterm2')
set ttymouse&
endif
call assert_equal(getcompletion('set virtualedit=', 'cmdline')[1], 'insert')
call assert_equal(getcompletion('set wildmode=', 'cmdline')[1], 'longest')
call assert_equal(getcompletion('set wildmode=list,longest:', 'cmdline')[0], 'full')
call assert_equal(getcompletion('set wildoptions=', 'cmdline')[1], 'tagfile')
if exists('+winaltkeys')
call assert_equal(getcompletion('set winaltkeys=', 'cmdline')[1], 'yes')
endif
" Other string options that queries the system rather than fixed enum names
call assert_equal(getcompletion('set eventignore=', 'cmdline')[0:1], ['all', 'BufAdd'])
call assert_equal(getcompletion('set fileencodings=', 'cmdline')[1], 'latin1')
call assert_equal(getcompletion('set printoptions=', 'cmdline')[0], 'top')
call assert_equal(getcompletion('set wincolor=', 'cmdline')[0], 'SpecialKey')
call assert_equal(getcompletion('set listchars+=', 'cmdline')[0], 'eol')
call assert_equal(getcompletion('setl listchars+=', 'cmdline')[0], 'eol')
call assert_equal(getcompletion('set fillchars+=', 'cmdline')[0], 'stl')
call assert_equal(getcompletion('setl fillchars+=', 'cmdline')[0], 'stl')
"
" Unique string options below
"
" keyprotocol: only auto-complete when after ':' with known protocol types
call assert_equal(getcompletion('set keyprotocol=', 'cmdline'), [&keyprotocol])
call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set keyprotocol+=someterm:mok2', @:)
set keyprotocol&
" previewpopup / completepopup
call assert_equal(getcompletion('set previewpopup=', 'cmdline')[0], 'height:')
call assert_equal(getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0], 'EndOfBuffer')
call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set previewpopup+=border:on', @:)
call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set completepopup=height:10,align:item', @:)
call assert_equal(getcompletion('set completepopup=bogusname:', 'cmdline'), [])
set previewpopup& completepopup&
" diffopt: special handling of algorithm:<alg_list>
call assert_equal(getcompletion('set diffopt+=', 'cmdline')[0], 'filler')
call assert_equal(getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'), [])
call assert_equal(getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0], 'patience')
" highlight: special parsing, including auto-completing highlight groups
" after ':'
call assert_equal(getcompletion('set hl=', 'cmdline')[0:1], [&hl, '8'])
call assert_equal(getcompletion('set hl+=', 'cmdline')[0], '8')
call assert_equal(getcompletion('set hl+=8', 'cmdline')[0:2], ['8:', '8b', '8i'])
call assert_equal(getcompletion('set hl+=8b', 'cmdline')[0], '8bi')
call assert_equal(getcompletion('set hl+=8:No*ext', 'cmdline')[0], 'NonText')
" If all the display modes are used up we should be suggesting nothing. Make
" a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
" and make sure nothing is suggested from that.
let hl_display_modes = join(
\ filter(map(getcompletion('set hl+=8', 'cmdline'),
\ {idx, val -> val[1]}),
\ {idx, val -> val != ':'}),
\ '')
call assert_equal(getcompletion('set hl+=8'..hl_display_modes, 'cmdline'), [])
"
" Test flag lists
"
" Test set=. Show the original value if nothing is typed after '='.
" Otherwise, the list should avoid showing what's already typed.
set mouse=v
call assert_equal(getcompletion('set mouse=', 'cmdline'), ['v','a','n','i','c','h','r'])
set mouse=nvi
call assert_equal(getcompletion('set mouse=', 'cmdline'), ['nvi','a','n','v','i','c','h','r'])
call assert_equal(getcompletion('set mouse=hn', 'cmdline'), ['a','v','i','c','r'])
" Test set+=. Never show original value, and it also tries to avoid listing
" flags that's already in the option value.
call assert_equal(getcompletion('set mouse+=', 'cmdline'), ['a','c','h','r'])
call assert_equal(getcompletion('set mouse+=hn', 'cmdline'), ['a','c','r'])
call assert_equal(getcompletion('set mouse+=acrhn', 'cmdline'), [])
" Test that the position of the expansion is correct (even if there are
" additional values after the current cursor)
call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
call assert_equal('"set mouse=han', @:)
set mouse&
" Test that other flag list options have auto-complete, but don't
" exhaustively validate their results.
if exists('+concealcursor')
call assert_equal(getcompletion('set cocu=', 'cmdline')[0], 'n')
endif
call assert_equal(getcompletion('set cpo=', 'cmdline')[1], 'a')
call assert_equal(getcompletion('set fo=', 'cmdline')[1], 't')
if exists('+guioptions')
call assert_equal(getcompletion('set go=', 'cmdline')[1], '!')
endif
call assert_equal(getcompletion('set shortmess=', 'cmdline')[1], 'r')
call assert_equal(getcompletion('set whichwrap=', 'cmdline')[1], 'b')
"
"Test set-=
"
" Normal single-value option just shows the existing value
set ambiwidth=double
call assert_equal(getcompletion('set ambw-=', 'cmdline'), ['double'])
set ambiwidth&
" Works on numbers and term options as well
call assert_equal(getcompletion('set laststatus-=', 'cmdline'), [string(&laststatus)])
set t_Ce=testCe
call assert_equal(getcompletion('set t_Ce-=', 'cmdline'), ['testCe'])
set t_Ce&
" Comma-separated lists should present each option
set diffopt=context:123,,,,,iblank,iwhiteall
call assert_equal(getcompletion('set diffopt-=', 'cmdline'), ['context:123', 'iblank', 'iwhiteall'])
call assert_equal(getcompletion('set diffopt-=*n*', 'cmdline'), ['context:123', 'iblank'])
call assert_equal(getcompletion('set diffopt-=i', 'cmdline'), ['iblank', 'iwhiteall'])
" Don't present more than one option as it doesn't make sense in set-=
call assert_equal(getcompletion('set diffopt-=iblank,', 'cmdline'), [])
" Test empty option
set diffopt=
call assert_equal(getcompletion('set diffopt-=', 'cmdline'), [])
set diffopt&
" Test escaping output
call assert_equal(getcompletion('set fillchars-=', 'cmdline')[0], 'vert:\|')
" Test files with commas in name are being parsed and escaped properly
set path=has\\\ space,file\\,with\\,comma,normal_file
if exists('+completeslash')
call assert_equal(getcompletion('set path-=', 'cmdline'), ['has\\\ space', 'file\,with\,comma', 'normal_file'])
else
call assert_equal(getcompletion('set path-=', 'cmdline'), ['has\\\ space', 'file\\,with\\,comma', 'normal_file'])
endif
set path&
" Flag list should present orig value, then individual flags
set mouse=v
call assert_equal(getcompletion('set mouse-=', 'cmdline'), ['v'])
set mouse=avn
call assert_equal(getcompletion('set mouse-=', 'cmdline'), ['avn','a','v','n'])
" Don't auto-complete when we have at least one flags already
call assert_equal(getcompletion('set mouse-=n', 'cmdline'), [])
" Test empty option
set mouse=
call assert_equal(getcompletion('set mouse-=', 'cmdline'), [])
set mouse&
" 'whichwrap' is an odd case where it's both flag list and comma-separated
set ww=b,h
call assert_equal(getcompletion('set ww-=', 'cmdline'), ['b','h'])
set ww&
endfunc
func Test_set_option_errors()
call assert_fails('set scroll=-1', 'E49:')
call assert_fails('set backupcopy=', 'E474:')
@ -1447,7 +1723,7 @@ func Test_opt_cdhome()
set cdhome&
endfunc
func Test_set_completion_2()
func Test_set_completion_fuzzy()
CheckOption termguicolors
" Test default option completion

View File

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

View File

@ -822,6 +822,8 @@ extern int (*dyn_libintl_wputenv)(const wchar_t *envstring);
#define EXPAND_BREAKPOINT 51
#define EXPAND_SCRIPTNAMES 52
#define EXPAND_RUNTIME 53
#define EXPAND_STRING_SETTING 54
#define EXPAND_SETTING_SUBTRACT 55
// Values for exmode_active (0 is no exmode)
#define EXMODE_NORMAL 1
@ -2330,6 +2332,20 @@ typedef enum {
*/
typedef char *(*opt_did_set_cb_T)(optset_T *args);
/*
* Type for the callback function that is invoked when expanding possible
* string option values during cmdline completion.
*
* Strings in returned matches will be managed and freed by caller.
*
* Returns OK if the expansion succeeded (numMatches and matches have to be
* set). Otherwise returns FAIL.
*
* Note: If returned FAIL or *numMatches is 0, *matches will NOT be freed by
* caller.
*/
typedef int (*opt_expand_cb_T)(optexpand_T *args, int *numMatches, char_u ***matches);
// Flags for assignment functions.
#define ASSIGN_VAR 0 // ":var" (nothing special)
#define ASSIGN_FINAL 0x01 // ":final"