mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
vim-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: vim/vim#13182
900894b09a
Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
This commit is contained in:
parent
9b3045103f
commit
f06af5e669
@ -493,16 +493,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*
|
||||
|
@ -52,14 +52,16 @@ achieve special effects. These options come in three forms:
|
||||
'lines'
|
||||
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}.
|
||||
For numeric options the value can be given in decimal,
|
||||
hex (preceded with 0x) or octal (preceded with '0').
|
||||
The old value can be inserted by typing 'wildchar' (by
|
||||
default this is a <Tab>). See |cmdline-completion|.
|
||||
default this is a <Tab>). Many string options with
|
||||
fixed syntax 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.
|
||||
@ -93,6 +95,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: >
|
||||
|
@ -2213,6 +2213,13 @@ char *expand_get_event_name(expand_T *xp, int idx)
|
||||
return event_names[idx - next_augroup_id].name;
|
||||
}
|
||||
|
||||
/// Function given to ExpandGeneric() to obtain the list of event names. Don't
|
||||
/// include groups.
|
||||
char *get_event_name_no_group(expand_T *xp FUNC_ATTR_UNUSED, int idx)
|
||||
{
|
||||
return event_names[idx].name;
|
||||
}
|
||||
|
||||
/// Check whether given autocommand is supported
|
||||
///
|
||||
/// @param[in] event Event to check.
|
||||
|
@ -69,9 +69,6 @@
|
||||
#include "nvim/vim.h"
|
||||
#include "nvim/window.h"
|
||||
|
||||
/// Type used by ExpandGeneric()
|
||||
typedef char *(*CompleteListItemGetter)(expand_T *, int);
|
||||
|
||||
/// Type used by call_user_expand_func
|
||||
typedef void *(*user_expand_func_T)(const char *, int, typval_T *);
|
||||
|
||||
@ -107,6 +104,8 @@ static bool cmdline_fuzzy_completion_supported(const expand_T *const xp)
|
||||
&& xp->xp_context != EXPAND_HELP
|
||||
&& xp->xp_context != EXPAND_LUA
|
||||
&& 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
|
||||
@ -2694,8 +2693,7 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
||||
return OK;
|
||||
}
|
||||
if (xp->xp_context == EXPAND_OLD_SETTING) {
|
||||
ExpandOldSetting(numMatches, matches);
|
||||
return OK;
|
||||
return ExpandOldSetting(numMatches, matches);
|
||||
}
|
||||
if (xp->xp_context == EXPAND_BUFFERS) {
|
||||
return ExpandBufnames(pat, numMatches, matches, options);
|
||||
@ -2765,6 +2763,10 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
||||
if (xp->xp_context == EXPAND_SETTINGS
|
||||
|| xp->xp_context == EXPAND_BOOL_SETTINGS) {
|
||||
ret = ExpandSettings(xp, ®match, pat, numMatches, matches, fuzzy);
|
||||
} else if (xp->xp_context == EXPAND_STRING_SETTING) {
|
||||
ret = ExpandStringSetting(xp, ®match, numMatches, matches);
|
||||
} else if (xp->xp_context == EXPAND_SETTING_SUBTRACT) {
|
||||
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_USER_DEFINED) {
|
||||
@ -2788,9 +2790,8 @@ static int ExpandFromContext(expand_T *xp, char *pat, char ***matches, int *numM
|
||||
/// program. Matching strings are copied into an array, which is returned.
|
||||
///
|
||||
/// @param func returns a string from the list
|
||||
static void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch,
|
||||
char ***matches, int *numMatches, CompleteListItemGetter func,
|
||||
int escaped)
|
||||
void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regmatch, char ***matches,
|
||||
int *numMatches, CompleteListItemGetter func, bool escaped)
|
||||
{
|
||||
const bool fuzzy = cmdline_fuzzy_complete(pat);
|
||||
*matches = NULL;
|
||||
@ -2863,6 +2864,7 @@ static void ExpandGeneric(const char *const pat, expand_T *xp, regmatch_T *regma
|
||||
// in the specified order.
|
||||
const bool sort_matches = !fuzzy
|
||||
&& xp->xp_context != EXPAND_MENUNAMES
|
||||
&& xp->xp_context != EXPAND_STRING_SETTING
|
||||
&& xp->xp_context != EXPAND_MENUS
|
||||
&& xp->xp_context != EXPAND_SCRIPTNAMES;
|
||||
|
||||
@ -3221,8 +3223,7 @@ void globpath(char *path, char *file, garray_T *ga, int expand_options, bool dir
|
||||
|
||||
char **p;
|
||||
int num_p = 0;
|
||||
(void)ExpandFromContext(&xpc, buf, &p, &num_p,
|
||||
WILD_SILENT | expand_options);
|
||||
(void)ExpandFromContext(&xpc, buf, &p, &num_p, WILD_SILENT | expand_options);
|
||||
if (num_p > 0) {
|
||||
ExpandEscape(&xpc, buf, num_p, p, WILD_SILENT | expand_options);
|
||||
|
||||
|
@ -41,6 +41,9 @@ enum {
|
||||
BUF_DIFF_FILTER = 0x2000,
|
||||
};
|
||||
|
||||
/// Type used by ExpandGeneric()
|
||||
typedef char *(*CompleteListItemGetter)(expand_T *, int);
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
# include "cmdexpand.h.generated.h"
|
||||
#endif
|
||||
|
@ -2467,6 +2467,7 @@ int diffopt_changed(void)
|
||||
|
||||
char *p = p_dip;
|
||||
while (*p != NUL) {
|
||||
// Note: Keep this in sync with p_dip_values
|
||||
if (strncmp(p, "filler", 6) == 0) {
|
||||
p += 6;
|
||||
diff_flags_new |= DIFF_FILLER;
|
||||
@ -2513,6 +2514,7 @@ int diffopt_changed(void)
|
||||
p += 8;
|
||||
diff_flags_new |= DIFF_INTERNAL;
|
||||
} 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) {
|
||||
p += 5;
|
||||
|
@ -2766,6 +2766,7 @@ int check_opt_wim(void)
|
||||
}
|
||||
|
||||
for (char *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] != ':') {
|
||||
return FAIL;
|
||||
|
@ -35,6 +35,8 @@ local redraw_flags={
|
||||
local list_flags={
|
||||
comma='P_COMMA',
|
||||
onecomma='P_ONECOMMA',
|
||||
commacolon='P_COMMA|P_COLON',
|
||||
onecommacolon='P_ONECOMMA|P_COLON',
|
||||
flags='P_FLAGLIST',
|
||||
flagscomma='P_COMMA|P_FLAGLIST',
|
||||
}
|
||||
@ -166,6 +168,9 @@ local function dump_option(i, o)
|
||||
if o.cb then
|
||||
w(' .opt_did_set_cb=' .. o.cb)
|
||||
end
|
||||
if o.expand_cb then
|
||||
w(' .opt_expand_cb=' .. o.expand_cb)
|
||||
end
|
||||
if o.enable_if then
|
||||
w('#else')
|
||||
w(' .var=NULL')
|
||||
|
@ -760,6 +760,7 @@ bool briopt_check(win_T *wp)
|
||||
|
||||
char *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] == '-' && ascii_isdigit(p[7])) || ascii_isdigit(p[6]))) {
|
||||
p += 6;
|
||||
|
@ -2830,3 +2830,14 @@ void f_charclass(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
|
||||
}
|
||||
rettv->vval.v_number = mb_get_class(argvars[0].vval.v_string);
|
||||
}
|
||||
|
||||
/// Function given to ExpandGeneric() to obtain the possible arguments of the
|
||||
/// encoding options.
|
||||
char *get_encoding_name(expand_T *xp FUNC_ATTR_UNUSED, int idx)
|
||||
{
|
||||
if (idx >= (int)ARRAY_SIZE(enc_canon_table)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (char *)enc_canon_table[idx].name;
|
||||
}
|
||||
|
@ -888,7 +888,7 @@ static char *stropt_copy_value(char *origval, char **argp, set_op_T op,
|
||||
// For MS-Windows 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 && !ascii_iswhite(*arg)) {
|
||||
if (*arg == '\\' && arg[1] != NUL
|
||||
#ifdef BACKSLASH_IN_FILENAME
|
||||
@ -5305,8 +5305,10 @@ void set_imsearch_global(buf_T *buf)
|
||||
}
|
||||
|
||||
static int expand_option_idx = -1;
|
||||
static int expand_option_start_col = 0;
|
||||
static char expand_option_name[5] = { 't', '_', NUL, NUL, NUL };
|
||||
static int expand_option_flags = 0;
|
||||
static bool expand_option_append = false;
|
||||
|
||||
/// @param opt_flags OPT_GLOBAL and/or OPT_LOCAL
|
||||
void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
|
||||
@ -5405,7 +5407,15 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
|
||||
}
|
||||
}
|
||||
// handle "-=" and "+="
|
||||
expand_option_append = false;
|
||||
bool 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 = '=';
|
||||
}
|
||||
@ -5414,28 +5424,51 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
|
||||
xp->xp_context = EXPAND_UNSUCCESSFUL;
|
||||
return;
|
||||
}
|
||||
if (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.
|
||||
if (options[opt_idx].var == &p_syn) {
|
||||
xp->xp_context = EXPAND_OWNSYNTAX;
|
||||
return;
|
||||
}
|
||||
if (options[opt_idx].var == &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;
|
||||
if (p == (char *)&p_bdir
|
||||
@ -5451,8 +5484,6 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
|
||||
} else {
|
||||
xp->xp_backslash = XP_BS_ONE;
|
||||
}
|
||||
} else if (p == (char *)&p_ft) {
|
||||
xp->xp_context = EXPAND_FILETYPE;
|
||||
} else {
|
||||
xp->xp_context = EXPAND_FILES;
|
||||
// for 'tags' need three backslashes for a space
|
||||
@ -5464,27 +5495,45 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
|
||||
}
|
||||
}
|
||||
|
||||
// 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--) {
|
||||
// count number of backslashes before ' ' or ','
|
||||
if (*p == ' ' || *p == ',') {
|
||||
char *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)) {
|
||||
xp->xp_pattern = p + 1;
|
||||
break;
|
||||
// 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)) {
|
||||
for (p = arg + strlen(arg) - 1; p > xp->xp_pattern; p--) {
|
||||
// count number of backslashes before ' ' or ','
|
||||
if (*p == ' ' || *p == ',' || (*p == ':' && (flags & P_COLON))) {
|
||||
char *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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for 'spellsuggest' start at "file:"
|
||||
if (options[opt_idx].var == &p_sps
|
||||
&& strncmp(p, "file:", 5) == 0) {
|
||||
xp->xp_pattern = p + 5;
|
||||
break;
|
||||
// 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.
|
||||
// for 'spellsuggest' start at "file:"
|
||||
if (options[opt_idx].var == &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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5503,9 +5552,9 @@ void set_context_in_set_cmd(expand_T *xp, char *arg, int opt_flags)
|
||||
///
|
||||
/// 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 bool match_str(char *const str, regmatch_T *const regmatch, char **const matches,
|
||||
const int idx, const bool test_only, const bool fuzzy,
|
||||
const char *const fuzzystr, fuzmatch_str_T *const fuzmatch)
|
||||
bool match_str(char *const str, regmatch_T *const regmatch, char **const matches, const int idx,
|
||||
const bool test_only, const bool fuzzy, const char *const fuzzystr,
|
||||
fuzmatch_str_T *const fuzmatch)
|
||||
{
|
||||
if (!fuzzy) {
|
||||
if (vim_regexec(regmatch, str, (colnr_T)0)) {
|
||||
@ -5609,7 +5658,33 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, char *fuzzystr, int *numM
|
||||
return OK;
|
||||
}
|
||||
|
||||
void ExpandOldSetting(int *numMatches, char ***matches)
|
||||
/// 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 *escape_option_str_cmdline(char *var)
|
||||
{
|
||||
// A backslash is required before some characters. This is the reverse of
|
||||
// what happens in do_set().
|
||||
char *buf = vim_strsave_escaped(var, escape_chars);
|
||||
|
||||
#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((uint8_t)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 ***matches)
|
||||
{
|
||||
char *var = NULL;
|
||||
|
||||
@ -5629,26 +5704,149 @@ void ExpandOldSetting(int *numMatches, char ***matches)
|
||||
var = "";
|
||||
}
|
||||
|
||||
// A backslash is required before some characters. This is the reverse of
|
||||
// what happens in do_set().
|
||||
char *buf = vim_strsave_escaped(var, escape_chars);
|
||||
char *buf = escape_option_str_cmdline(var);
|
||||
|
||||
#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((uint8_t)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 ***matches)
|
||||
{
|
||||
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 = {
|
||||
.oe_varp = get_varp_scope(&options[expand_option_idx], expand_option_flags),
|
||||
.oe_append = expand_option_append,
|
||||
.oe_regmatch = regmatch,
|
||||
.oe_xp = xp,
|
||||
.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);
|
||||
char *var = NameBuff;
|
||||
char *buf = escape_option_str_cmdline(var);
|
||||
args.oe_opt_value = buf;
|
||||
|
||||
int num_ret = options[expand_option_idx].opt_expand_cb(&args, numMatches, matches);
|
||||
|
||||
xfree(buf);
|
||||
return num_ret;
|
||||
}
|
||||
|
||||
/// Expansion handler for :set-=
|
||||
int ExpandSettingSubtract(expand_T *xp, regmatch_T *regmatch, int *numMatches, char ***matches)
|
||||
{
|
||||
if (expand_option_idx < 0) {
|
||||
// term option
|
||||
return ExpandOldSetting(numMatches, matches);
|
||||
}
|
||||
|
||||
char *option_val = *(char **)get_option_varp_scope_from(expand_option_idx,
|
||||
expand_option_flags,
|
||||
curbuf, curwin);
|
||||
|
||||
uint32_t 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.
|
||||
|
||||
if (*option_val == NUL) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
// Make a copy as we need to inject null characters destructively.
|
||||
char *option_copy = xstrdup(option_val);
|
||||
char *next_val = option_copy;
|
||||
|
||||
garray_T ga;
|
||||
ga_init(&ga, sizeof(char *), 10);
|
||||
|
||||
do {
|
||||
char *item = next_val;
|
||||
char *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 *buf = escape_option_str_cmdline(item);
|
||||
GA_APPEND(char *, &ga, buf);
|
||||
} while (next_val != NULL);
|
||||
|
||||
xfree(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;
|
||||
}
|
||||
|
||||
size_t num_flags = strlen(option_val);
|
||||
if (num_flags == 0) {
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
*matches = xmalloc(sizeof(char *) * (num_flags + 1));
|
||||
|
||||
int count = 0;
|
||||
|
||||
(*matches)[count++] = xstrdup(option_val);
|
||||
|
||||
if (num_flags > 1) {
|
||||
// If more than one flags, split the flags up and expose each
|
||||
// character as individual choice.
|
||||
for (char *flag = option_val; *flag != NUL; flag++) {
|
||||
(*matches)[count++] = xstrnsave(flag, 1);
|
||||
}
|
||||
}
|
||||
|
||||
*numMatches = count;
|
||||
return OK;
|
||||
}
|
||||
|
||||
return ExpandOldSetting(numMatches, matches);
|
||||
}
|
||||
|
||||
/// Get the value for the numeric or string option///opp in a nice format into
|
||||
@ -5772,6 +5970,7 @@ int fill_culopt_flags(char *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;
|
||||
culopt_flags_new |= CULOPT_LINE;
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "nvim/eval/typval_defs.h"
|
||||
#include "nvim/ex_cmds_defs.h"
|
||||
#include "nvim/option_defs.h"
|
||||
#include "nvim/search.h"
|
||||
|
||||
/// The options that are local to a window or buffer have "indir" set to one of
|
||||
/// these values. Special values:
|
||||
@ -45,7 +46,15 @@ typedef struct vimoption {
|
||||
///< local option: indirect option index
|
||||
///< callback function to invoke after an option is modified to validate and
|
||||
///< apply the new value.
|
||||
|
||||
/// callback function to invoke after an option is modified to validate and
|
||||
/// apply the new value.
|
||||
opt_did_set_cb_T opt_did_set_cb;
|
||||
|
||||
/// callback function to invoke when expanding possible values on the
|
||||
/// cmdline. Only useful for string options.
|
||||
opt_expand_cb_T opt_expand_cb;
|
||||
|
||||
void *def_val; ///< default values for variable (neovim!!)
|
||||
LastSet last_set; ///< script in which the option was last set
|
||||
} vimoption_T;
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "nvim/api/private/defs.h"
|
||||
#include "nvim/eval/typval_defs.h"
|
||||
#include "nvim/regexp_defs.h"
|
||||
#include "nvim/types.h"
|
||||
|
||||
/// Option value type
|
||||
@ -80,4 +81,40 @@ typedef struct {
|
||||
/// Otherwise returns an error message.
|
||||
typedef const char *(*opt_did_set_cb_T)(optset_T *args);
|
||||
|
||||
/// 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 *oe_varp;
|
||||
/// The original option value, escaped.
|
||||
char *oe_opt_value;
|
||||
|
||||
/// true if using set+= instead of set=
|
||||
bool oe_append;
|
||||
/// true if we would like to add the original option value as the first choice.
|
||||
bool 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 *oe_set_arg;
|
||||
} optexpand_T;
|
||||
|
||||
/// 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 ***matches);
|
||||
|
||||
#endif // NVIM_OPTION_DEFS_H
|
||||
|
@ -16,6 +16,7 @@
|
||||
///< the same.
|
||||
#define P_EXPAND 0x10U ///< environment expansion. NOTE: P_EXPAND can
|
||||
///< never be used for local or hidden options
|
||||
#define P_NO_DEF_EXP 0x20U ///< do not expand default value
|
||||
#define P_NODEFAULT 0x40U ///< don't set to default value
|
||||
#define P_DEF_ALLOCED 0x80U ///< default value is in allocated memory, must
|
||||
///< use free() when assigning new value
|
||||
@ -51,8 +52,7 @@
|
||||
#define P_RWINONLY 0x10000000U ///< only redraw current window
|
||||
#define P_MLE 0x20000000U ///< under control of 'modelineexpr'
|
||||
#define P_FUNC 0x40000000U ///< accept a function reference or a lambda
|
||||
|
||||
#define P_NO_DEF_EXP 0x80000000U ///< Do not expand default value.
|
||||
#define P_COLON 0x80000000U ///< values use colons to create sublists
|
||||
|
||||
#define HIGHLIGHT_INIT \
|
||||
"8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText,d:Directory,e:ErrorMsg," \
|
||||
@ -183,7 +183,7 @@
|
||||
#define CPO_VI "aAbBcCdDeEfFiIJKlLmMnoOpPqrRsStuvWxXyZ$!%+>;_"
|
||||
|
||||
// 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
|
||||
@ -757,9 +757,9 @@ extern char *p_vfile; ///< 'verbosefile'
|
||||
EXTERN int p_warn; ///< 'warn'
|
||||
EXTERN char *p_wop; ///< 'wildoptions'
|
||||
EXTERN unsigned wop_flags;
|
||||
#define WOP_TAGFILE 0x01
|
||||
#define WOP_PUM 0x02
|
||||
#define WOP_FUZZY 0x04
|
||||
#define WOP_FUZZY 0x01
|
||||
#define WOP_TAGFILE 0x02
|
||||
#define WOP_PUM 0x04
|
||||
EXTERN OptInt p_window; ///< 'window'
|
||||
EXTERN char *p_wak; ///< 'winaltkeys'
|
||||
EXTERN char *p_wig; ///< 'wildignore'
|
||||
|
@ -6,7 +6,7 @@
|
||||
--- @field varname? string
|
||||
--- @field pv_name? string
|
||||
--- @field type 'bool'|'number'|'string'
|
||||
--- @field list? 'comma'|'onecomma'|'flags'|'flagscomma'
|
||||
--- @field list? 'comma'|'onecomma'|'commacolon'|'onecommacolon'|'flags'|'flagscomma'
|
||||
--- @field scope vim.option_scope[]
|
||||
--- @field deny_duplicates? boolean
|
||||
--- @field enable_if? string|false
|
||||
@ -25,6 +25,7 @@
|
||||
--- @field alloced? true
|
||||
--- @field redraw? vim.option_redraw[]
|
||||
--- @field cb? string
|
||||
--- @field expand_cb? string
|
||||
--- @field tags? string[]
|
||||
|
||||
--- @class vim.option_defaults
|
||||
@ -192,6 +193,7 @@ return {
|
||||
set to one of CJK locales. See Unicode Standard Annex #11
|
||||
(https://www.unicode.org/reports/tr11).
|
||||
]=],
|
||||
expand_cb = 'expand_set_ambiwidth',
|
||||
full_name = 'ambiwidth',
|
||||
redraw = { 'all_windows', 'ui_option' },
|
||||
scope = { 'global' },
|
||||
@ -331,6 +333,7 @@ return {
|
||||
option, you must load syntax.vim again to see the result. This can be
|
||||
done with ":syntax on".
|
||||
]=],
|
||||
expand_cb = 'expand_set_background',
|
||||
full_name = 'background',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('"dark" or "light", used for highlight colors'),
|
||||
@ -357,6 +360,7 @@ return {
|
||||
When the value is empty, Vi compatible backspacing is used, none of
|
||||
the ways mentioned for the items above are possible.
|
||||
]=],
|
||||
expand_cb = 'expand_set_backspace',
|
||||
full_name = 'backspace',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -453,6 +457,7 @@ return {
|
||||
the system may refuse to do this. In that case the "auto" value will
|
||||
again not rename the file.
|
||||
]=],
|
||||
expand_cb = 'expand_set_backupcopy',
|
||||
full_name = 'backupcopy',
|
||||
list = 'onecomma',
|
||||
scope = { 'global', 'buffer' },
|
||||
@ -621,6 +626,7 @@ return {
|
||||
indicate that an error occurred. It can be silenced by adding the
|
||||
"error" keyword.
|
||||
]=],
|
||||
expand_cb = 'expand_set_belloff',
|
||||
full_name = 'belloff',
|
||||
list = 'comma',
|
||||
scope = { 'global' },
|
||||
@ -763,6 +769,7 @@ return {
|
||||
added for the 'showbreak' setting.
|
||||
(default: off)
|
||||
]=],
|
||||
expand_cb = 'expand_set_breakindentopt',
|
||||
full_name = 'breakindentopt',
|
||||
list = 'onecomma',
|
||||
redraw = { 'current_buffer' },
|
||||
@ -816,6 +823,7 @@ return {
|
||||
This option is used together with 'buftype' and 'swapfile' to specify
|
||||
special kinds of buffers. See |special-buffers|.
|
||||
]=],
|
||||
expand_cb = 'expand_set_bufhidden',
|
||||
full_name = 'bufhidden',
|
||||
noglob = true,
|
||||
scope = { 'buffer' },
|
||||
@ -893,6 +901,7 @@ return {
|
||||
without saving. For writing there must be matching |BufWriteCmd|,
|
||||
|FileWriteCmd| or |FileAppendCmd| autocommands.
|
||||
]=],
|
||||
expand_cb = 'expand_set_buftype',
|
||||
full_name = 'buftype',
|
||||
noglob = true,
|
||||
scope = { 'buffer' },
|
||||
@ -917,6 +926,7 @@ return {
|
||||
case mapping, the current locale is not effective.
|
||||
This probably only matters for Turkish.
|
||||
]=],
|
||||
expand_cb = 'expand_set_casemap',
|
||||
full_name = 'casemap',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -1183,6 +1193,7 @@ return {
|
||||
"*". See |clipboard|.
|
||||
]=],
|
||||
deny_duplicates = true,
|
||||
expand_cb = 'expand_set_clipboard',
|
||||
full_name = 'clipboard',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -1369,6 +1380,7 @@ return {
|
||||
based expansion (e.g., dictionary |i_CTRL-X_CTRL-K|, included patterns
|
||||
|i_CTRL-X_CTRL-I|, tags |i_CTRL-X_CTRL-]| and normal expansions).
|
||||
]=],
|
||||
expand_cb = 'expand_set_complete',
|
||||
full_name = 'complete',
|
||||
list = 'onecomma',
|
||||
scope = { 'buffer' },
|
||||
@ -1399,7 +1411,9 @@ return {
|
||||
Keep in mind that the cursor position is not always where it's
|
||||
displayed. E.g., when moving vertically it may change column.
|
||||
]=],
|
||||
expand_cb = 'expand_set_concealcursor',
|
||||
full_name = 'concealcursor',
|
||||
list = 'flags',
|
||||
redraw = { 'current_window' },
|
||||
scope = { 'window' },
|
||||
short_desc = N_('whether concealable text is hidden in cursor line'),
|
||||
@ -1492,6 +1506,7 @@ return {
|
||||
select one from the menu. Only works in combination with
|
||||
"menu" or "menuone".
|
||||
]=],
|
||||
expand_cb = 'expand_set_completeopt',
|
||||
full_name = 'completeopt',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -1517,6 +1532,7 @@ return {
|
||||
command line completion the global value is used.
|
||||
]=],
|
||||
enable_if = 'BACKSLASH_IN_FILENAME',
|
||||
expand_cb = 'expand_set_completeslash',
|
||||
full_name = 'completeslash',
|
||||
scope = { 'buffer' },
|
||||
type = 'string',
|
||||
@ -1797,6 +1813,7 @@ return {
|
||||
_ When using |cw| on a word, do not include the
|
||||
whitespace following the word in the motion.
|
||||
]=],
|
||||
expand_cb = 'expand_set_cpoptions',
|
||||
full_name = 'cpoptions',
|
||||
list = 'flags',
|
||||
redraw = { 'all_windows' },
|
||||
@ -1878,6 +1895,7 @@ return {
|
||||
|
||||
"line" and "screenline" cannot be used together.
|
||||
]=],
|
||||
expand_cb = 'expand_set_cursorlineopt',
|
||||
full_name = 'cursorlineopt',
|
||||
list = 'onecomma',
|
||||
redraw = { 'current_window_only' },
|
||||
@ -1900,6 +1918,7 @@ return {
|
||||
"msg" and "throw" are useful for debugging 'foldexpr', 'formatexpr' or
|
||||
'indentexpr'.
|
||||
]=],
|
||||
expand_cb = 'expand_set_debug',
|
||||
full_name = 'debug',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('to "msg" to see all error messages'),
|
||||
@ -2140,8 +2159,9 @@ return {
|
||||
:set diffopt-=internal " do NOT use the internal diff parser
|
||||
<
|
||||
]=],
|
||||
expand_cb = 'expand_set_diffopt',
|
||||
full_name = 'diffopt',
|
||||
list = 'onecomma',
|
||||
list = 'onecommacolon',
|
||||
redraw = { 'current_window' },
|
||||
scope = { 'global' },
|
||||
short_desc = N_('options for using diff mode'),
|
||||
@ -2242,6 +2262,7 @@ return {
|
||||
The "@" character can be changed by setting the "lastline" item in
|
||||
'fillchars'. The character is highlighted with |hl-NonText|.
|
||||
]=],
|
||||
expand_cb = 'expand_set_display',
|
||||
full_name = 'display',
|
||||
list = 'onecomma',
|
||||
redraw = { 'all_windows' },
|
||||
@ -2260,6 +2281,7 @@ return {
|
||||
hor horizontally, height of windows is not affected
|
||||
both width and height of windows is affected
|
||||
]=],
|
||||
expand_cb = 'expand_set_eadirection',
|
||||
full_name = 'eadirection',
|
||||
scope = { 'global' },
|
||||
short_desc = N_("in which direction 'equalalways' works"),
|
||||
@ -2470,6 +2492,7 @@ return {
|
||||
:set ei=WinEnter,WinLeave
|
||||
<
|
||||
]=],
|
||||
expand_cb = 'expand_set_eventignore',
|
||||
full_name = 'eventignore',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -2558,6 +2581,7 @@ return {
|
||||
|
||||
This option cannot be changed when 'modifiable' is off.
|
||||
]=],
|
||||
expand_cb = 'expand_set_encoding',
|
||||
full_name = 'fileencoding',
|
||||
no_mkrc = true,
|
||||
redraw = { 'statuslines', 'current_buffer' },
|
||||
@ -2619,6 +2643,7 @@ return {
|
||||
Setting this option does not have an effect until the next time a file
|
||||
is read.
|
||||
]=],
|
||||
expand_cb = 'expand_set_encoding',
|
||||
full_name = 'fileencodings',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -2651,6 +2676,7 @@ return {
|
||||
option is set, because the file would be different when written.
|
||||
This option cannot be changed when 'modifiable' is off.
|
||||
]=],
|
||||
expand_cb = 'expand_set_fileformat',
|
||||
full_name = 'fileformat',
|
||||
no_mkrc = true,
|
||||
redraw = { 'curswant', 'statuslines' },
|
||||
@ -2714,6 +2740,7 @@ return {
|
||||
used.
|
||||
Also see |file-formats|.
|
||||
]=],
|
||||
expand_cb = 'expand_set_fileformat',
|
||||
full_name = 'fileformats',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -2846,6 +2873,7 @@ return {
|
||||
eob EndOfBuffer |hl-EndOfBuffer|
|
||||
lastline NonText |hl-NonText|
|
||||
]=],
|
||||
expand_cb = 'expand_set_chars_option',
|
||||
full_name = 'fillchars',
|
||||
list = 'onecomma',
|
||||
redraw = { 'current_window' },
|
||||
@ -2884,6 +2912,7 @@ return {
|
||||
its level is higher than 'foldlevel'. Useful if you want folds to
|
||||
automatically close when moving out of them.
|
||||
]=],
|
||||
expand_cb = 'expand_set_foldclose',
|
||||
full_name = 'foldclose',
|
||||
list = 'onecomma',
|
||||
redraw = { 'current_window' },
|
||||
@ -3045,6 +3074,7 @@ return {
|
||||
|fold-syntax| syntax Syntax highlighting items specify folds.
|
||||
|fold-diff| diff Fold text that is not changed.
|
||||
]=],
|
||||
expand_cb = 'expand_set_foldmethod',
|
||||
full_name = 'foldmethod',
|
||||
redraw = { 'current_window' },
|
||||
scope = { 'window' },
|
||||
@ -3122,6 +3152,7 @@ return {
|
||||
To close folds you can re-apply 'foldlevel' with the |zx| command or
|
||||
set the 'foldclose' option to "all".
|
||||
]=],
|
||||
expand_cb = 'expand_set_foldopen',
|
||||
full_name = 'foldopen',
|
||||
list = 'onecomma',
|
||||
redraw = { 'curswant' },
|
||||
@ -3218,6 +3249,7 @@ return {
|
||||
To avoid problems with flags that are added in the future, use the
|
||||
"+=" and "-=" feature of ":set" |add-option-flags|.
|
||||
]=],
|
||||
expand_cb = 'expand_set_formatoptions',
|
||||
full_name = 'formatoptions',
|
||||
list = 'flags',
|
||||
scope = { 'buffer' },
|
||||
@ -4451,6 +4483,7 @@ return {
|
||||
|alternate-file| or using |mark-motions| try to
|
||||
restore the |mark-view| in which the action occurred.
|
||||
]=],
|
||||
expand_cb = 'expand_set_jumpoptions',
|
||||
full_name = 'jumpoptions',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -4495,6 +4528,7 @@ return {
|
||||
Special keys in this context are the cursor keys, <End>, <Home>,
|
||||
<PageUp> and <PageDown>.
|
||||
]=],
|
||||
expand_cb = 'expand_set_keymodel',
|
||||
full_name = 'keymodel',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -4779,6 +4813,7 @@ return {
|
||||
Note that when using 'indentexpr' the `=` operator indents all the
|
||||
lines, otherwise the first line is not indented (Vi-compatible).
|
||||
]=],
|
||||
expand_cb = 'expand_set_lispoptions',
|
||||
full_name = 'lispoptions',
|
||||
list = 'onecomma',
|
||||
pv_name = 'p_lop',
|
||||
@ -4933,6 +4968,7 @@ return {
|
||||
"precedes". |hl-Whitespace| for "nbsp", "space", "tab", "multispace",
|
||||
"lead" and "trail".
|
||||
]=],
|
||||
expand_cb = 'expand_set_chars_option',
|
||||
full_name = 'listchars',
|
||||
list = 'onecomma',
|
||||
redraw = { 'current_window' },
|
||||
@ -5015,6 +5051,7 @@ return {
|
||||
:set makeencoding=char " system locale is used
|
||||
<
|
||||
]=],
|
||||
expand_cb = 'expand_set_encoding',
|
||||
full_name = 'makeencoding',
|
||||
scope = { 'global', 'buffer' },
|
||||
short_desc = N_('Converts the output of external commands'),
|
||||
@ -5377,6 +5414,7 @@ return {
|
||||
'mousehide' hide mouse pointer while typing text
|
||||
'selectmode' whether to start Select mode or Visual mode
|
||||
]=],
|
||||
expand_cb = 'expand_set_mouse',
|
||||
full_name = 'mouse',
|
||||
list = 'flags',
|
||||
scope = { 'global' },
|
||||
@ -5468,6 +5506,7 @@ return {
|
||||
"g<LeftMouse>" is "<C-LeftMouse> (jump to tag under mouse click)
|
||||
"g<RightMouse>" is "<C-RightMouse> ("CTRL-T")
|
||||
]=],
|
||||
expand_cb = 'expand_set_mousemodel',
|
||||
full_name = 'mousemodel',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('changes meaning of mouse buttons'),
|
||||
@ -5645,6 +5684,7 @@ return {
|
||||
considered decimal. This also happens for numbers that are not
|
||||
recognized as octal or hex.
|
||||
]=],
|
||||
expand_cb = 'expand_set_nrformats',
|
||||
full_name = 'nrformats',
|
||||
list = 'onecomma',
|
||||
scope = { 'buffer' },
|
||||
@ -6307,6 +6347,7 @@ return {
|
||||
This is useful for languages such as Hebrew, Arabic and Farsi.
|
||||
The 'rightleft' option must be set for 'rightleftcmd' to take effect.
|
||||
]=],
|
||||
expand_cb = 'expand_set_rightleftcmd',
|
||||
full_name = 'rightleftcmd',
|
||||
redraw = { 'current_window' },
|
||||
scope = { 'window' },
|
||||
@ -6634,6 +6675,7 @@ return {
|
||||
When 'diff' mode is active there always is vertical scroll binding,
|
||||
even when "ver" isn't there.
|
||||
]=],
|
||||
expand_cb = 'expand_set_scrollopt',
|
||||
full_name = 'scrollopt',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -6687,6 +6729,7 @@ return {
|
||||
backwards, you cannot include the last character of a line, when
|
||||
starting in Normal mode and 'virtualedit' empty.
|
||||
]=],
|
||||
expand_cb = 'expand_set_selection',
|
||||
full_name = 'selection',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('what type of selection to use'),
|
||||
@ -6707,6 +6750,7 @@ return {
|
||||
cmd when using "v", "V" or CTRL-V
|
||||
See |Select-mode|.
|
||||
]=],
|
||||
expand_cb = 'expand_set_selectmode',
|
||||
full_name = 'selectmode',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -6758,6 +6802,7 @@ return {
|
||||
If you leave out "options" many things won't work well after restoring
|
||||
the session.
|
||||
]=],
|
||||
expand_cb = 'expand_set_sessionoptions',
|
||||
full_name = 'sessionoptions',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -7292,6 +7337,7 @@ return {
|
||||
shm=a Abbreviation, but no loss of information.
|
||||
shm=at Abbreviation, and truncate message when necessary.
|
||||
]=],
|
||||
expand_cb = 'expand_set_shortmess',
|
||||
full_name = 'shortmess',
|
||||
list = 'flags',
|
||||
scope = { 'global' },
|
||||
@ -7368,6 +7414,7 @@ return {
|
||||
place the text. Without a custom 'statusline' or 'tabline' it will be
|
||||
displayed in a convenient location.
|
||||
]=],
|
||||
expand_cb = 'expand_set_showcmdloc',
|
||||
full_name = 'showcmdloc',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('change location of partial command'),
|
||||
@ -7530,6 +7577,7 @@ return {
|
||||
This is done in order for the signcolumn appearance not appear weird
|
||||
during line deletion.
|
||||
]=],
|
||||
expand_cb = 'expand_set_signcolumn',
|
||||
full_name = 'signcolumn',
|
||||
redraw = { 'current_window' },
|
||||
scope = { 'window' },
|
||||
@ -7828,6 +7876,7 @@ return {
|
||||
security reasons.
|
||||
]=],
|
||||
expand = true,
|
||||
expand_cb = 'expand_set_spellsuggest',
|
||||
full_name = 'spellsuggest',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -7852,7 +7901,7 @@ return {
|
||||
designated regions of the buffer are spellchecked in
|
||||
this case.
|
||||
]=],
|
||||
expand = true,
|
||||
expand_cb = 'expand_set_spelloptions',
|
||||
full_name = 'spelloptions',
|
||||
list = 'onecomma',
|
||||
redraw = { 'current_buffer' },
|
||||
@ -7892,6 +7941,7 @@ return {
|
||||
with the previous cursor position. For "screen", the text cannot always
|
||||
be kept on the same screen line when 'wrap' is enabled.
|
||||
]=],
|
||||
expand_cb = 'expand_set_splitkeep',
|
||||
full_name = 'splitkeep',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('determines scroll behavior for split windows'),
|
||||
@ -8326,6 +8376,7 @@ return {
|
||||
uselast If included, jump to the previously used window when
|
||||
jumping to errors with |quickfix| commands.
|
||||
]=],
|
||||
expand_cb = 'expand_set_switchbuf',
|
||||
full_name = 'switchbuf',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -8580,6 +8631,7 @@ return {
|
||||
match Match case
|
||||
smart Ignore case unless an upper case letter is used
|
||||
]=],
|
||||
expand_cb = 'expand_set_tagcase',
|
||||
full_name = 'tagcase',
|
||||
scope = { 'global', 'buffer' },
|
||||
short_desc = N_('how to handle case when searching in tags files'),
|
||||
@ -9275,6 +9327,7 @@ return {
|
||||
slash |deprecated| Always enabled. Uses "/" in filenames.
|
||||
unix |deprecated| Always enabled. Uses "\n" line endings.
|
||||
]=],
|
||||
expand_cb = 'expand_set_sessionoptions',
|
||||
full_name = 'viewoptions',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -9331,6 +9384,7 @@ return {
|
||||
not get a warning for it.
|
||||
When combined with other words, "none" is ignored.
|
||||
]=],
|
||||
expand_cb = 'expand_set_virtualedit',
|
||||
full_name = 'virtualedit',
|
||||
list = 'onecomma',
|
||||
redraw = { 'curswant' },
|
||||
@ -9395,6 +9449,7 @@ return {
|
||||
line (not an empty line) then it will not move to the next line. This
|
||||
makes "dl", "cl", "yl" etc. work normally.
|
||||
]=],
|
||||
expand_cb = 'expand_set_whichwrap',
|
||||
full_name = 'whichwrap',
|
||||
list = 'flagscomma',
|
||||
scope = { 'global' },
|
||||
@ -9578,8 +9633,9 @@ return {
|
||||
< Complete longest common string, then list alternatives.
|
||||
More info here: |cmdline-completion|.
|
||||
]=],
|
||||
expand_cb = 'expand_set_wildmode',
|
||||
full_name = 'wildmode',
|
||||
list = 'onecomma',
|
||||
list = 'onecommacolon',
|
||||
scope = { 'global' },
|
||||
short_desc = N_("mode for 'wildchar' command-line expansion"),
|
||||
type = 'string',
|
||||
@ -9609,6 +9665,7 @@ return {
|
||||
d #define
|
||||
f function
|
||||
]=],
|
||||
expand_cb = 'expand_set_wildoptions',
|
||||
full_name = 'wildoptions',
|
||||
list = 'onecomma',
|
||||
scope = { 'global' },
|
||||
@ -9637,6 +9694,7 @@ return {
|
||||
key is never used for the menu.
|
||||
This option is not used for <F10>; on Win32.
|
||||
]=],
|
||||
expand_cb = 'expand_set_winaltkeys',
|
||||
full_name = 'winaltkeys',
|
||||
scope = { 'global' },
|
||||
short_desc = N_('when the windows system handles ALT keys'),
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,7 @@
|
||||
#define NVIM_OPTIONSTR_H
|
||||
|
||||
#include "nvim/buffer_defs.h"
|
||||
#include "nvim/cmdexpand.h"
|
||||
#include "nvim/option_defs.h"
|
||||
|
||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||
|
@ -403,6 +403,7 @@ int spell_check_sps(void)
|
||||
if (*s != NUL && !ascii_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) {
|
||||
|
@ -164,6 +164,8 @@ enum {
|
||||
EXPAND_BREAKPOINT,
|
||||
EXPAND_SCRIPTNAMES,
|
||||
EXPAND_RUNTIME,
|
||||
EXPAND_STRING_SETTING,
|
||||
EXPAND_SETTING_SUBTRACT,
|
||||
EXPAND_CHECKHEALTH,
|
||||
EXPAND_LUA,
|
||||
};
|
||||
|
@ -299,11 +299,11 @@ func Test_set_completion()
|
||||
call assert_equal('"set tabstop thesaurus thesaurusfunc', @:)
|
||||
|
||||
" 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')
|
||||
@ -364,13 +364,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'
|
||||
@ -386,6 +390,284 @@ 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(['lastline', 'truncate', 'uhex', 'msgsep'], getcompletion('set display=', 'cmdline'))
|
||||
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(['uhex,lastline', 'lastline', 'truncate', 'uhex', 'msgsep'], getcompletion('set display=', 'cmdline'))
|
||||
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'])
|
||||
call assert_equal(['uhex', 'lastline', 'truncate', 'msgsep'], getcompletion('set display=', 'cmdline'))
|
||||
" 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'])
|
||||
call assert_equal(['lastline', 'truncate', 'uhex', 'msgsep'], getcompletion('set display=', 'cmdline'))
|
||||
" Test escaping of the values
|
||||
" call assert_equal(getcompletion('set fillchars=', 'cmdline')[0], 'vert:\|,fold:-,eob:~,lastline:@')
|
||||
call assert_equal('vert:\|,foldsep:\|,fold:-', getcompletion('set fillchars=', 'cmdline')[0])
|
||||
|
||||
" 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])
|
||||
call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[0])
|
||||
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:')
|
||||
@ -1433,7 +1715,7 @@ func Test_opt_cdhome()
|
||||
set cdhome&
|
||||
endfunc
|
||||
|
||||
func Test_set_completion_2()
|
||||
func Test_set_completion_fuzzy()
|
||||
CheckOption termguicolors
|
||||
|
||||
" Test default option completion
|
||||
|
Loading…
Reference in New Issue
Block a user