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>
diff --git a/src/proto/autocmd.pro b/src/proto/autocmd.pro
index 0b61989..4a502da 100644
--- a/src/proto/autocmd.pro
+++ b/src/proto/autocmd.pro
@@ -39,6 +39,7 @@
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);
diff --git a/src/proto/cmdexpand.pro b/src/proto/cmdexpand.pro
index 1e2b148..395eaa6 100644
--- a/src/proto/cmdexpand.pro
+++ b/src/proto/cmdexpand.pro
@@ -9,6 +9,7 @@
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);
diff --git a/src/proto/mbyte.pro b/src/proto/mbyte.pro
index 1bd3aa0..7883b3b 100644
--- a/src/proto/mbyte.pro
+++ b/src/proto/mbyte.pro
@@ -88,4 +88,5 @@
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 : */
diff --git a/src/proto/option.pro b/src/proto/option.pro
index 871efc3..ec0013d 100644
--- a/src/proto/option.pro
+++ b/src/proto/option.pro
@@ -129,6 +129,8 @@
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);
diff --git a/src/proto/optionstr.pro b/src/proto/optionstr.pro
index c1253b1..b4d9dfc 100644
--- a/src/proto/optionstr.pro
+++ b/src/proto/optionstr.pro
@@ -122,6 +122,71 @@
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);
diff --git a/src/proto/screen.pro b/src/proto/screen.pro
index 84b404d..d5792fa 100644
--- a/src/proto/screen.pro
+++ b/src/proto/screen.pro
@@ -57,5 +57,7 @@
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 : */