diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-07-22 21:47:03 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-07-22 22:38:05 +0800 |
commit | 232cdbb8807c79a5d933f28345011d2a32264f02 (patch) | |
tree | 7ef32b42b357bef5504a54d553328d04960e56bb | |
parent | 271739c8305ac7eb41a3467e508bdeb5c03f0427 (diff) | |
download | rneovim-232cdbb8807c79a5d933f28345011d2a32264f02.tar.gz rneovim-232cdbb8807c79a5d933f28345011d2a32264f02.tar.bz2 rneovim-232cdbb8807c79a5d933f28345011d2a32264f02.zip |
vim-patch:8.2.1489: Vim9: error when setting an option with setbufvar()
Problem: Vim9: error when setting an option with setbufvar().
Solution: Do not get a number from a string value. (closes vim/vim#6740)
https://github.com/vim/vim/commit/191929b182ba38abe6bc431fb9d8d9507f408903
Vim9 is N/A, so this just refactors the code without changing behavior.
-rw-r--r-- | src/nvim/eval/vars.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c index 01fd10dcda..e56ccef02b 100644 --- a/src/nvim/eval/vars.c +++ b/src/nvim/eval/vars.c @@ -1544,6 +1544,18 @@ static void getwinvar(typval_T *argvars, typval_T *rettv, int off) } } +/// Set option "varname" to the value of "varp" for the current buffer/window. +static void set_option_from_tv(const char *varname, typval_T *varp) +{ + bool error = false; + char nbuf[NUMBUFLEN]; + const long numval = (long)tv_get_number_chk(varp, &error); + const char *const strval = tv_get_string_buf_chk(varp, nbuf); + if (!error && strval != NULL) { + set_option_value(varname, numval, strval, OPT_LOCAL); + } +} + /// "setwinvar()" and "settabwinvar()" functions static void setwinvar(typval_T *argvars, typval_T *rettv, int off) { @@ -1566,16 +1578,7 @@ static void setwinvar(typval_T *argvars, typval_T *rettv, int off) switchwin_T switchwin; if (!need_switch_win || switch_win(&switchwin, win, tp, true) == OK) { if (*varname == '&') { - long numval; - bool error = false; - - varname++; - numval = tv_get_number_chk(varp, &error); - char nbuf[NUMBUFLEN]; - const char *const strval = tv_get_string_buf_chk(varp, nbuf); - if (!error && strval != NULL) { - set_option_value(varname, numval, strval, OPT_LOCAL); - } + set_option_from_tv(varname + 1, varp); } else { const size_t varname_len = strlen(varname); char *const winvarname = xmalloc(varname_len + 3); @@ -1789,20 +1792,12 @@ void f_setbufvar(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (buf != NULL && varname != NULL) { if (*varname == '&') { - long numval; - bool error = false; aco_save_T aco; // set curbuf to be our buf, temporarily aucmd_prepbuf(&aco, buf); - varname++; - numval = tv_get_number_chk(varp, &error); - char nbuf[NUMBUFLEN]; - const char *const strval = tv_get_string_buf_chk(varp, nbuf); - if (!error && strval != NULL) { - set_option_value(varname, numval, strval, OPT_LOCAL); - } + set_option_from_tv(varname + 1, varp); // reset notion of buffer aucmd_restbuf(&aco); |