aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/vars.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2023-10-08 22:13:15 +0600
committerFamiu Haque <famiuhaque@proton.me>2023-10-17 00:08:47 +0600
commit5df4fdf253f9c9cc35f9f5f16c6d0ba9d87b4c71 (patch)
tree526161313a7690d2c944c7449e183e3a26f2d1c5 /src/nvim/eval/vars.c
parent93b9c889465ee6a55e71c1fd681c1c6b1d5ed060 (diff)
downloadrneovim-5df4fdf253f9c9cc35f9f5f16c6d0ba9d87b4c71.tar.gz
rneovim-5df4fdf253f9c9cc35f9f5f16c6d0ba9d87b4c71.tar.bz2
rneovim-5df4fdf253f9c9cc35f9f5f16c6d0ba9d87b4c71.zip
refactor(options)!: make OptionSet `v:` values use typval
BREAKING CHANGE: This breaks the OptionSet autocommand, as the `v:` values associated with it (`v:option_new`, `v:option_old`, `v:option_oldlocal` and `v:option_oldglobal`) are now the same type as the option, instead of all option values being converted to strings.
Diffstat (limited to 'src/nvim/eval/vars.c')
-rw-r--r--src/nvim/eval/vars.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/nvim/eval/vars.c b/src/nvim/eval/vars.c
index 4b314ca338..ed400b2ee9 100644
--- a/src/nvim/eval/vars.c
+++ b/src/nvim/eval/vars.c
@@ -20,6 +20,7 @@
#include "nvim/eval/encode.h"
#include "nvim/eval/funcs.h"
#include "nvim/eval/typval.h"
+#include "nvim/eval/typval_defs.h"
#include "nvim/eval/userfunc.h"
#include "nvim/eval/vars.h"
#include "nvim/eval/window.h"
@@ -1896,6 +1897,45 @@ static OptVal tv_to_optval(typval_T *tv, const char *option, uint32_t flags, boo
return value;
}
+/// Convert an option value to typval.
+///
+/// @param[in] value Option value to convert.
+///
+/// @return OptVal converted to typval.
+typval_T optval_as_tv(OptVal value)
+{
+ typval_T rettv = { .v_type = VAR_SPECIAL, .vval = { .v_special = kSpecialVarNull } };
+
+ switch (value.type) {
+ case kOptValTypeNil:
+ break;
+ case kOptValTypeBoolean:
+ switch (value.data.boolean) {
+ case kTrue:
+ rettv.v_type = VAR_BOOL;
+ rettv.vval.v_bool = kBoolVarTrue;
+ break;
+ case kFalse:
+ rettv.v_type = VAR_BOOL;
+ rettv.vval.v_bool = kBoolVarFalse;
+ break;
+ case kNone:
+ break; // return v:null for None boolean value
+ }
+ break;
+ case kOptValTypeNumber:
+ rettv.v_type = VAR_NUMBER;
+ rettv.vval.v_number = value.data.number;
+ break;
+ case kOptValTypeString:
+ rettv.v_type = VAR_STRING;
+ rettv.vval.v_string = value.data.string.data;
+ break;
+ }
+
+ return rettv;
+}
+
/// 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)
{