diff options
author | zeertzjq <zeertzjq@outlook.com> | 2023-10-01 19:07:16 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2023-10-01 20:00:23 +0800 |
commit | 01c51a491330bd10202c73aff92c0978984c0692 (patch) | |
tree | 489e52a8c585f8f1fccfdddf814ac763ad2b7522 | |
parent | 5821c857e025a292c17bd80192366dc7bfb1fbc6 (diff) | |
download | rneovim-01c51a491330bd10202c73aff92c0978984c0692.tar.gz rneovim-01c51a491330bd10202c73aff92c0978984c0692.tar.bz2 rneovim-01c51a491330bd10202c73aff92c0978984c0692.zip |
feat(completion): support completing more string options
-rw-r--r-- | runtime/doc/news.txt | 2 | ||||
-rw-r--r-- | runtime/doc/vim_diff.txt | 7 | ||||
-rw-r--r-- | src/nvim/cmdexpand.c | 2 | ||||
-rw-r--r-- | src/nvim/highlight_group.c | 4 | ||||
-rw-r--r-- | src/nvim/options.lua | 9 | ||||
-rw-r--r-- | src/nvim/optionstr.c | 45 | ||||
-rw-r--r-- | test/functional/editor/completion_spec.lua | 9 |
7 files changed, 69 insertions, 9 deletions
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index b632cf0932..f82cb7b7e0 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -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|. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index e636746616..3bf844a139 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -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| diff --git a/src/nvim/cmdexpand.c b/src/nvim/cmdexpand.c index 3969162b6e..893deadd13 100644 --- a/src/nvim/cmdexpand.c +++ b/src/nvim/cmdexpand.c @@ -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 }, diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c index 080dc79e0e..d2cdcb2516 100644 --- a/src/nvim/highlight_group.c +++ b/src/nvim/highlight_group.c @@ -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. diff --git a/src/nvim/options.lua b/src/nvim/options.lua index fd7e1586ac..bae9b56ef4 100644 --- a/src/nvim/options.lua +++ b/src/nvim/options.lua @@ -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'), diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index a67b3a77bc..c8a589f96a 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -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) { diff --git a/test/functional/editor/completion_spec.lua b/test/functional/editor/completion_spec.lua index 8c299636cc..ea3397d50d 100644 --- a/test/functional/editor/completion_spec.lua +++ b/test/functional/editor/completion_spec.lua @@ -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:') |