aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/deprecated.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2023-06-07 06:05:16 +0600
committerGitHub <noreply@github.com>2023-06-07 08:05:16 +0800
commitb3d5138fd0066fda26ef7724a542ae45eb42fc84 (patch)
treef9893af238d838408c81c6d4e36655865fe465b0 /src/nvim/api/deprecated.c
parent0370e4def0c0328f8cd09f02c1ca82ed491ecb9a (diff)
downloadrneovim-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/api/deprecated.c')
-rw-r--r--src/nvim/api/deprecated.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c
index a7e5b32d49..83c33db5d3 100644
--- a/src/nvim/api/deprecated.c
+++ b/src/nvim/api/deprecated.c
@@ -709,14 +709,13 @@ static void set_option_to(uint64_t channel_id, void *to, int type, String name,
}
}
- long numval = 0;
- char *stringval = NULL;
+ OptVal optval = NIL_OPTVAL;
if (flags & SOPT_BOOL) {
VALIDATE(value.type == kObjectTypeBoolean, "Option '%s' value must be Boolean", name.data, {
return;
});
- numval = value.data.boolean;
+ optval = BOOLEAN_OPTVAL(value.data.boolean);
} else if (flags & SOPT_NUM) {
VALIDATE(value.type == kObjectTypeInteger, "Option '%s' value must be Integer", name.data, {
return;
@@ -725,12 +724,12 @@ static void set_option_to(uint64_t channel_id, void *to, int type, String name,
"Option '%s' value is out of range", name.data, {
return;
});
- numval = (int)value.data.integer;
+ optval = NUMBER_OPTVAL(value.data.integer);
} else {
VALIDATE(value.type == kObjectTypeString, "Option '%s' value must be String", name.data, {
return;
});
- stringval = value.data.string.data;
+ optval = STRING_OPTVAL(value.data.string);
}
// For global-win-local options -> setlocal
@@ -739,6 +738,6 @@ static void set_option_to(uint64_t channel_id, void *to, int type, String name,
(type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
WITH_SCRIPT_CONTEXT(channel_id, {
- access_option_value_for(name.data, &numval, &stringval, opt_flags, type, to, false, err);
+ set_option_value_for(name.data, optval, opt_flags, type, to, err);
});
}