diff options
Diffstat (limited to 'src/nvim/eval/vars.c')
-rw-r--r-- | src/nvim/eval/vars.c | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index a8358aab51..c64477741d 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -40,7 +40,6 @@ #include "nvim/ops.h" #include "nvim/option.h" #include "nvim/option_defs.h" -#include "nvim/option_vars.h" #include "nvim/os/os.h" #include "nvim/search.h" #include "nvim/strings.h" @@ -811,9 +810,9 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const, // Find the end of the name. char *arg_end = NULL; OptIndex opt_idx; - int scope; + int opt_flags; - char *const p = (char *)find_option_var_end((const char **)&arg, &opt_idx, &scope); + char *const p = (char *)find_option_var_end((const char **)&arg, &opt_idx, &opt_flags); if (p == NULL || (endchars != NULL && vim_strchr(endchars, (uint8_t)(*skipwhite(p))) == NULL)) { emsg(_(e_letunexp)); @@ -825,7 +824,7 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const, bool is_tty_opt = is_tty_option(arg); bool hidden = is_option_hidden(opt_idx); - OptVal curval = is_tty_opt ? get_tty_option(arg) : get_option_value(opt_idx, scope); + OptVal curval = is_tty_opt ? get_tty_option(arg) : get_option_value(opt_idx, opt_flags); OptVal newval = NIL_OPTVAL; if (curval.type == kOptValTypeNil) { @@ -845,11 +844,10 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const, goto theend; } - // Don't assume current and new values are of the same type in order to future-proof the code for - // when an option can have multiple types. - const bool is_num = ((curval.type == kOptValTypeNumber || curval.type == kOptValTypeBoolean) - && (newval.type == kOptValTypeNumber || newval.type == kOptValTypeBoolean)); - const bool is_string = curval.type == kOptValTypeString && newval.type == kOptValTypeString; + // Current value and new value must have the same type. + assert(curval.type == newval.type); + const bool is_num = curval.type == kOptValTypeNumber || curval.type == kOptValTypeBoolean; + const bool is_string = curval.type == kOptValTypeString; if (op != NULL && *op != '=') { if (!hidden && is_num) { // number or bool @@ -874,15 +872,19 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const, } else { newval = BOOLEAN_OPTVAL(TRISTATE_FROM_INT(new_n)); } - } else if (!hidden && is_string - && curval.data.string.data != NULL && newval.data.string.data != NULL) { // string - OptVal newval_old = newval; - newval = CSTR_AS_OPTVAL(concat_str(curval.data.string.data, newval.data.string.data)); - optval_free(newval_old); + } else if (!hidden && is_string) { // string + const char *curval_data = curval.data.string.data; + const char *newval_data = newval.data.string.data; + + if (curval_data != NULL && newval_data != NULL) { + OptVal newval_old = newval; + newval = CSTR_AS_OPTVAL(concat_str(curval_data, newval_data)); + optval_free(newval_old); + } } } - const char *err = set_option_value_handle_tty(arg, opt_idx, newval, scope); + const char *err = set_option_value_handle_tty(arg, opt_idx, newval, opt_flags); arg_end = p; if (err != NULL) { emsg(_(err)); @@ -1409,6 +1411,7 @@ static void list_one_var(dictitem_T *v, const char *prefix, int *first) static void list_one_var_a(const char *prefix, const char *name, const ptrdiff_t name_len, const VarType type, const char *string, int *first) { + msg_ext_set_kind("list_cmd"); // don't use msg() to avoid overwriting "v:statusmsg" msg_start(); msg_puts(prefix); @@ -1902,8 +1905,6 @@ static void getwinvar(typval_T *argvars, typval_T *rettv, int off) /// /// @return Typval converted to OptVal. Must be freed by caller. /// Returns NIL_OPTVAL for invalid option name. -/// -/// TODO(famiu): Refactor this to support multitype options. static OptVal tv_to_optval(typval_T *tv, OptIndex opt_idx, const char *option, bool *error) { OptVal value = NIL_OPTVAL; |