diff options
author | Famiu Haque <famiuhaque@proton.me> | 2023-06-07 06:05:16 +0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-07 08:05:16 +0800 |
commit | b3d5138fd0066fda26ef7724a542ae45eb42fc84 (patch) | |
tree | f9893af238d838408c81c6d4e36655865fe465b0 /src/nvim/eval.c | |
parent | 0370e4def0c0328f8cd09f02c1ca82ed491ecb9a (diff) | |
download | rneovim-b3d5138fd0066fda26ef7724a542ae45eb42fc84.tar.gz rneovim-b3d5138fd0066fda26ef7724a542ae45eb42fc84.tar.bz2 rneovim-b3d5138fd0066fda26ef7724a542ae45eb42fc84.zip |
refactor(options): remove `getoption_T` and introduce `OptVal` (#23850)
Removes the `getoption_T` struct and also introduces the `OptVal` struct
to unify the methods of getting/setting different option value types.
This is the first of many PRs to reduce code duplication in the Vim
option code as well as to make options easier to maintain. It also
increases the flexibility and extensibility of options. Which opens the
door for things like Array and Dictionary options.
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 118c1d3012..72005b1f35 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -58,6 +58,7 @@ #include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/ops.h" #include "nvim/option.h" +#include "nvim/option_defs.h" #include "nvim/optionstr.h" #include "nvim/os/fileio.h" #include "nvim/os/fs_defs.h" @@ -3770,38 +3771,38 @@ int eval_option(const char **const arg, typval_T *const rettv, const bool evalua return OK; } - long numval; - char *stringval; int ret = OK; - + bool hidden; char c = *option_end; *option_end = NUL; - getoption_T opt_type = get_option_value(*arg, &numval, - rettv == NULL ? NULL : &stringval, NULL, scope); + OptVal value = get_option_value(*arg, NULL, scope, &hidden); - if (opt_type == gov_unknown) { - if (rettv != NULL) { + if (rettv != NULL) { + switch (value.type) { + case kOptValTypeNil: semsg(_("E113: Unknown option: %s"), *arg); - } - ret = FAIL; - } else if (rettv != NULL) { - if (opt_type == gov_hidden_string) { - rettv->v_type = VAR_STRING; - rettv->vval.v_string = NULL; - } else if (opt_type == gov_hidden_bool || opt_type == gov_hidden_number) { + ret = FAIL; + break; + case kOptValTypeBoolean: rettv->v_type = VAR_NUMBER; - rettv->vval.v_number = 0; - } else if (opt_type == gov_bool || opt_type == gov_number) { + rettv->vval.v_number = value.data.boolean; + break; + case kOptValTypeNumber: rettv->v_type = VAR_NUMBER; - rettv->vval.v_number = numval; - } else { // string option + rettv->vval.v_number = value.data.number; + break; + case kOptValTypeString: rettv->v_type = VAR_STRING; - rettv->vval.v_string = stringval; + rettv->vval.v_string = value.data.string.data; + break; + } + } else { + // Value isn't being used, free it. + optval_free(value); + + if (value.type == kOptValTypeNil || (working && hidden)) { + ret = FAIL; } - } else if (working && (opt_type == gov_hidden_bool - || opt_type == gov_hidden_number - || opt_type == gov_hidden_string)) { - ret = FAIL; } *option_end = c; // put back for error messages @@ -8516,7 +8517,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, const char // If it's still empty it was changed and restored, need to restore in // the complicated way. if (*p_cpo == NUL) { - set_option_value_give_err("cpo", 0L, save_cpo, 0); + set_option_value_give_err("cpo", CSTR_AS_OPTVAL(save_cpo), 0); } free_string_option(save_cpo); } |