aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/options.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2024-11-25 15:07:56 +0600
committerGitHub <noreply@github.com>2024-11-25 17:07:56 +0800
commitbeec377e905baca73e772080c4f276c800ad2a40 (patch)
tree478d0eafce4ac8a7153fa66f39bfc70ba5d2adbc /src/nvim/api/options.c
parent9e7b0bcf51924716461f838a33a9508b718934b5 (diff)
downloadrneovim-beec377e905baca73e772080c4f276c800ad2a40.tar.gz
rneovim-beec377e905baca73e772080c4f276c800ad2a40.tar.bz2
rneovim-beec377e905baca73e772080c4f276c800ad2a40.zip
refactor(options): fix confusing naming of `scope` and `req_scope` (#31317)
Problem: The name `scope` is often used to refer to option flags because `OPT_LOCAL` and `OPT_GLOBAL` are often used to determine the option scope. This leads to the name `req_scope` being used for actual option scopes instead. Solution: Since the end-goal is to remove `OPT_LOCAL` and `OPT_GLOBAL` entirely and replace them with `OptScope`, rename `OptScope` variables to `scope` and the old scope flag variables to `opt_flags`.
Diffstat (limited to 'src/nvim/api/options.c')
-rw-r--r--src/nvim/api/options.c57
1 files changed, 29 insertions, 28 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 8fd9904f7a..bfd63ca489 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -23,15 +23,15 @@
#endif
static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *opt_idxp,
- int *scope, OptScope *req_scope, void **from, char **filetype,
+ int *opt_flags, OptScope *scope, void **from, char **filetype,
Error *err)
{
#define HAS_KEY_X(d, v) HAS_KEY(d, option, v)
if (HAS_KEY_X(opts, scope)) {
if (!strcmp(opts->scope.data, "local")) {
- *scope = OPT_LOCAL;
+ *opt_flags = OPT_LOCAL;
} else if (!strcmp(opts->scope.data, "global")) {
- *scope = OPT_GLOBAL;
+ *opt_flags = OPT_GLOBAL;
} else {
VALIDATE_EXP(false, "scope", "'local' or 'global'", NULL, {
return FAIL;
@@ -39,14 +39,14 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
}
}
- *req_scope = kOptScopeGlobal;
+ *scope = kOptScopeGlobal;
if (filetype != NULL && HAS_KEY_X(opts, filetype)) {
*filetype = opts->filetype.data;
}
if (HAS_KEY_X(opts, win)) {
- *req_scope = kOptScopeWin;
+ *scope = kOptScopeWin;
*from = find_window_by_handle(opts->win, err);
if (ERROR_SET(err)) {
return FAIL;
@@ -54,12 +54,12 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
}
if (HAS_KEY_X(opts, buf)) {
- VALIDATE(!(HAS_KEY_X(opts, scope) && *scope == OPT_GLOBAL), "%s",
+ VALIDATE(!(HAS_KEY_X(opts, scope) && *opt_flags == OPT_GLOBAL), "%s",
"cannot use both global 'scope' and 'buf'", {
return FAIL;
});
- *scope = OPT_LOCAL;
- *req_scope = kOptScopeBuf;
+ *opt_flags = OPT_LOCAL;
+ *scope = kOptScopeBuf;
*from = find_buffer_by_handle(opts->buf, err);
if (ERROR_SET(err)) {
return FAIL;
@@ -81,10 +81,10 @@ static int validate_option_value_args(Dict(option) *opts, char *name, OptIndex *
if (*opt_idxp == kOptInvalid) {
// unknown option
api_set_error(err, kErrorTypeValidation, "Unknown option '%s'", name);
- } else if (*req_scope == kOptScopeBuf || *req_scope == kOptScopeWin) {
+ } else if (*scope == kOptScopeBuf || *scope == kOptScopeWin) {
// if 'buf' or 'win' is passed, make sure the option supports it
- if (!option_has_scope(*opt_idxp, *req_scope)) {
- char *tgt = *req_scope == kOptScopeBuf ? "buf" : "win";
+ if (!option_has_scope(*opt_idxp, *scope)) {
+ char *tgt = *scope == kOptScopeBuf ? "buf" : "win";
char *global = option_has_scope(*opt_idxp, kOptScopeGlobal) ? "global " : "";
char *req = option_has_scope(*opt_idxp, kOptScopeBuf)
? "buffer-local "
@@ -151,13 +151,13 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
FUNC_API_SINCE(9) FUNC_API_RET_ALLOC
{
OptIndex opt_idx = 0;
- int scope = 0;
- OptScope req_scope = kOptScopeGlobal;
+ int opt_flags = 0;
+ OptScope scope = kOptScopeGlobal;
void *from = NULL;
char *filetype = NULL;
- if (!validate_option_value_args(opts, name.data, &opt_idx, &scope, &req_scope, &from, &filetype,
- err)) {
+ if (!validate_option_value_args(opts, name.data, &opt_idx, &opt_flags, &scope, &from,
+ &filetype, err)) {
return (Object)OBJECT_INIT;
}
@@ -181,7 +181,7 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
from = ftbuf;
}
- OptVal value = get_option_value_for(opt_idx, scope, req_scope, from, err);
+ OptVal value = get_option_value_for(opt_idx, opt_flags, scope, from, err);
if (ftbuf != NULL) {
// restore curwin/curbuf and a few other things
@@ -224,10 +224,11 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(
FUNC_API_SINCE(9)
{
OptIndex opt_idx = 0;
- int scope = 0;
- OptScope req_scope = kOptScopeGlobal;
+ int opt_flags = 0;
+ OptScope scope = kOptScopeGlobal;
void *to = NULL;
- if (!validate_option_value_args(opts, name.data, &opt_idx, &scope, &req_scope, &to, NULL, err)) {
+ if (!validate_option_value_args(opts, name.data, &opt_idx, &opt_flags, &scope, &to, NULL,
+ err)) {
return;
}
@@ -237,9 +238,9 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(
// - option is global or local to window (global-local)
//
// Then force scope to local since we don't want to change the global option
- if (req_scope == kOptScopeWin && scope == 0) {
+ if (scope == kOptScopeWin && opt_flags == 0) {
if (option_has_scope(opt_idx, kOptScopeGlobal)) {
- scope = OPT_LOCAL;
+ opt_flags = OPT_LOCAL;
}
}
@@ -255,7 +256,7 @@ void nvim_set_option_value(uint64_t channel_id, String name, Object value, Dict(
});
WITH_SCRIPT_CONTEXT(channel_id, {
- set_option_value_for(name.data, opt_idx, optval, scope, req_scope, to, err);
+ set_option_value_for(name.data, opt_idx, optval, opt_flags, scope, to, err);
});
}
@@ -310,16 +311,16 @@ Dict nvim_get_option_info2(String name, Dict(option) *opts, Arena *arena, Error
FUNC_API_SINCE(11)
{
OptIndex opt_idx = 0;
- int scope = 0;
- OptScope req_scope = kOptScopeGlobal;
+ int opt_flags = 0;
+ OptScope scope = kOptScopeGlobal;
void *from = NULL;
- if (!validate_option_value_args(opts, name.data, &opt_idx, &scope, &req_scope, &from, NULL,
+ if (!validate_option_value_args(opts, name.data, &opt_idx, &opt_flags, &scope, &from, NULL,
err)) {
return (Dict)ARRAY_DICT_INIT;
}
- buf_T *buf = (req_scope == kOptScopeBuf) ? (buf_T *)from : curbuf;
- win_T *win = (req_scope == kOptScopeWin) ? (win_T *)from : curwin;
+ buf_T *buf = (scope == kOptScopeBuf) ? (buf_T *)from : curbuf;
+ win_T *win = (scope == kOptScopeWin) ? (win_T *)from : curwin;
- return get_vimoption(name, scope, buf, win, arena, err);
+ return get_vimoption(name, opt_flags, buf, win, arena, err);
}