feat(completion): support completing more string options

This commit is contained in:
zeertzjq 2023-10-01 19:07:16 +08:00
parent 5821c857e0
commit 01c51a4913
7 changed files with 69 additions and 9 deletions

View File

@ -105,6 +105,8 @@ The following new APIs and features were added.
• |nvim_set_keymap()| and |nvim_del_keymap()| now support abbreviations.
• Better cmdline completion for string option value. |complete-set-option|
• Builtin TUI can now recognize "super" (|<D-|) and "meta" (|<T-|) modifiers in a
terminal emulator that supports |tui-csiu|.

View File

@ -287,13 +287,12 @@ Options:
'diffopt' "linematch" feature
'exrc' searches for ".nvim.lua", ".nvimrc", or ".exrc" files. The
user is prompted whether to trust the file.
'fillchars' flags: "msgsep", "horiz", "horizup",
"horizdown", "vertleft", "vertright", "verthoriz"
'fillchars' flags: "msgsep", "horiz", "horizup", "horizdown",
"vertleft", "vertright", "verthoriz"
'foldcolumn' supports up to 9 dynamic/fixed columns
'guicursor' works in the terminal (TUI)
'inccommand' shows interactive results for |:substitute|-like commands
and |:command-preview| commands
'jumpoptions' "stack" behavior
'jumpoptions' "view" tries to restore the |mark-view| when moving through
the |jumplist|, |changelist|, |alternate-file| or using |mark-motions|.
'laststatus' global statusline support
@ -304,6 +303,7 @@ Options:
'signcolumn' supports up to 9 dynamic/fixed columns
'statuscolumn' full control of columns using 'statusline' format
'tabline' %@Func@foo%X can call any function on mouse-click
'termpastefilter'
'ttimeout', 'ttimeoutlen' behavior was simplified
'winblend' pseudo-transparency in floating windows |api-floatwin|
'winhighlight' window-local highlights
@ -382,6 +382,7 @@ Upstreamed features *nvim-upstreamed*
These Nvim features were later integrated into Vim.
- 'fillchars' flags: "eob"
- 'jumpoptions' "stack" behavior
- 'wildoptions' flags: "pum" enables popupmenu for wildmode completion
- |<Cmd>|
- |WinClosed|

View File

@ -2598,7 +2598,7 @@ static int ExpandOther(char *pat, expand_T *xp, regmatch_T *rmp, char ***matches
{ EXPAND_MENUNAMES, get_menu_names, false, true },
{ EXPAND_SYNTAX, get_syntax_name, true, true },
{ EXPAND_SYNTIME, get_syntime_arg, true, true },
{ EXPAND_HIGHLIGHT, (ExpandFunc)get_highlight_name, true, false },
{ EXPAND_HIGHLIGHT, get_highlight_name, true, false },
{ EXPAND_EVENTS, expand_get_event_name, true, false },
{ EXPAND_AUGROUP, expand_get_augroup_name, true, false },
{ EXPAND_SIGN, get_sign_name, true, true },

View File

@ -2283,10 +2283,10 @@ static void highlight_list_two(int cnt, int attr)
}
/// Function given to ExpandGeneric() to obtain the list of group names.
const char *get_highlight_name(expand_T *const xp, int idx)
char *get_highlight_name(expand_T *const xp, int idx)
FUNC_ATTR_WARN_UNUSED_RESULT
{
return get_highlight_name_ext(xp, idx, true);
return (char *)get_highlight_name_ext(xp, idx, true);
}
/// Obtain a highlight group name.

View File

@ -2935,6 +2935,7 @@ return {
"[1-9]": to display a fixed number of columns
See |folding|.
]=],
expand_cb = 'expand_set_foldcolumn',
full_name = 'foldcolumn',
redraw = { 'current_window' },
scope = { 'window' },
@ -4082,6 +4083,7 @@ return {
'redrawtime') then 'inccommand' is automatically disabled until
|Command-line-mode| is done.
]=],
expand_cb = 'expand_set_inccommand',
full_name = 'inccommand',
scope = { 'global' },
short_desc = N_('Live preview of substitution'),
@ -5552,6 +5554,7 @@ return {
< Will make Nvim scroll 5 lines at a time when scrolling vertically, and
scroll 2 columns at a time when scrolling horizontally.
]=],
expand_cb = 'expand_set_mousescroll',
full_name = 'mousescroll',
list = 'comma',
scope = { 'global' },
@ -8780,6 +8783,7 @@ return {
C1 Control characters 0x80...0x9F
]=],
expand_cb = 'expand_set_termpastefilter',
full_name = 'termpastefilter',
list = 'onecomma',
scope = { 'global' },
@ -9749,7 +9753,7 @@ return {
{
abbreviation = 'winhl',
alloced = true,
cb = 'did_set_winhl',
cb = 'did_set_winhighlight',
defaults = { if_true = '' },
deny_duplicates = true,
desc = [=[
@ -9771,8 +9775,9 @@ return {
set winhighlight=Normal:MyNormal,NormalNC:MyNormalNC
<
]=],
expand_cb = 'expand_set_winhighlight',
full_name = 'winhighlight',
list = 'onecomma',
list = 'onecommacolon',
redraw = { 'current_window' },
scope = { 'window' },
short_desc = N_('Setup window-local highlights'),

View File

@ -1538,6 +1538,15 @@ const char *did_set_foldcolumn(optset_T *args)
return NULL;
}
int expand_set_foldcolumn(optexpand_T *args, int *numMatches, char ***matches)
{
return expand_set_opt_string(args,
p_fdc_values,
ARRAY_SIZE(p_fdc_values) - 1,
numMatches,
matches);
}
/// The 'foldexpr' option is changed.
const char *did_set_foldexpr(optset_T *args)
{
@ -1691,6 +1700,15 @@ const char *did_set_inccommand(optset_T *args FUNC_ATTR_UNUSED)
return did_set_opt_strings(p_icm, p_icm_values, false);
}
int expand_set_inccommand(optexpand_T *args, int *numMatches, char ***matches)
{
return expand_set_opt_string(args,
p_icm_values,
ARRAY_SIZE(p_icm_values) - 1,
numMatches,
matches);
}
/// The 'isident' or the 'iskeyword' or the 'isprint' or the 'isfname' option is
/// changed.
const char *did_set_isopt(optset_T *args)
@ -1943,6 +1961,16 @@ const char *did_set_mousescroll(optset_T *args FUNC_ATTR_UNUSED)
return NULL;
}
int expand_set_mousescroll(optexpand_T *args, int *numMatches, char ***matches)
{
static char *(p_mousescroll_values[]) = { "hor:", "ver:", NULL };
return expand_set_opt_string(args,
p_mousescroll_values,
ARRAY_SIZE(p_mousescroll_values) - 1,
numMatches,
matches);
}
/// The 'nrformats' option is changed.
const char *did_set_nrformats(optset_T *args)
{
@ -2412,6 +2440,15 @@ const char *did_set_termpastefilter(optset_T *args FUNC_ATTR_UNUSED)
return did_set_opt_flags(p_tpf, p_tpf_values, &tpf_flags, true);
}
int expand_set_termpastefilter(optexpand_T *args, int *numMatches, char ***matches)
{
return expand_set_opt_string(args,
p_tpf_values,
ARRAY_SIZE(p_tpf_values) - 1,
numMatches,
matches);
}
/// The 'titlestring' or the 'iconstring' option is changed.
static const char *did_set_titleiconstring(optset_T *args, int flagval)
{
@ -2625,7 +2662,8 @@ const char *did_set_winbar(optset_T *args)
return did_set_statustabline_rulerformat(args, false, false);
}
const char *did_set_winhl(optset_T *args)
/// The 'winhighlight' option is changed.
const char *did_set_winhighlight(optset_T *args)
{
win_T *win = (win_T *)args->os_win;
if (!parse_winhl_opt(win)) {
@ -2634,6 +2672,11 @@ const char *did_set_winhl(optset_T *args)
return NULL;
}
int expand_set_winhighlight(optexpand_T *args, int *numMatches, char ***matches)
{
return expand_set_opt_generic(args, get_highlight_name, numMatches, matches);
}
// When 'syntax' is set, load the syntax of that name
static void do_syntax_autocmd(buf_T *buf, bool value_changed)
{

View File

@ -941,6 +941,15 @@ describe('completion', function()
end)
end)
it('cmdline completion supports various string options', function()
eq('auto', funcs.getcompletion('set foldcolumn=', 'cmdline')[2])
eq({'nosplit', 'split'}, funcs.getcompletion('set inccommand=', 'cmdline'))
eq({'ver:3,hor:6', 'hor:', 'ver:'}, funcs.getcompletion('set mousescroll=', 'cmdline'))
eq('BS', funcs.getcompletion('set termpastefilter=', 'cmdline')[2])
eq('SpecialKey', funcs.getcompletion('set winhighlight=', 'cmdline')[1])
eq('SpecialKey', funcs.getcompletion('set winhighlight=NonText:', 'cmdline')[1])
end)
describe('from the commandline window', function()
it('is cleared after CTRL-C', function ()
feed('q:')