aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/options.c
diff options
context:
space:
mode:
authorFamiu Haque <famiuhaque@proton.me>2024-11-08 11:57:59 +0600
committerFamiu Haque <famiuhaque@proton.me>2024-12-26 20:55:13 +0600
commit6257270040bc5c61a489f7fb9d4102223c36cf89 (patch)
treea0db9a3bf31b56dedd9a240b54c5d47b02ce43ff /src/nvim/api/options.c
parent98763ce4e93752f22d379e3f735f4c78ae49afad (diff)
downloadrneovim-6257270040bc5c61a489f7fb9d4102223c36cf89.tar.gz
rneovim-6257270040bc5c61a489f7fb9d4102223c36cf89.tar.bz2
rneovim-6257270040bc5c61a489f7fb9d4102223c36cf89.zip
refactor(options): set option value for non-current context directly
Problem: Currently, we use `switch_option_context` to temporarily switch the current option context before setting an option for a different buffer / window. This is not ideal because we already support getting and setting option values for non-current contexts in the underlying implementation. Solution: Set option value for non-current context by passing the context directly to the lower level functions. Also introduce a new `OptCtx` struct to store option context information, this will scale much better if we add more option scopes and other context information in the future.
Diffstat (limited to 'src/nvim/api/options.c')
-rw-r--r--src/nvim/api/options.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/nvim/api/options.c b/src/nvim/api/options.c
index 64f8a35d54..2bbbdbbe8c 100644
--- a/src/nvim/api/options.c
+++ b/src/nvim/api/options.c
@@ -157,8 +157,8 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
void *from = NULL;
char *filetype = NULL;
- if (!validate_option_value_args(opts, name.data, &opt_idx, &opt_flags, &scope, &from,
- &filetype, err)) {
+ if (!validate_option_value_args(opts, name.data, &opt_idx, &opt_flags, &scope, &from, &filetype,
+ err)) {
return (Object)OBJECT_INIT;
}
@@ -182,7 +182,7 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
from = ftbuf;
}
- OptVal value = get_option_value_for(opt_idx, opt_flags, scope, from, err);
+ OptVal value = get_option_value_from(opt_idx, option_ctx_from(scope, from), opt_flags);
if (ftbuf != NULL) {
// restore curwin/curbuf and a few other things
@@ -257,7 +257,11 @@ 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, opt_flags, scope, to, err);
+ const char *errmsg
+ = set_option_value_for(opt_idx, optval, option_ctx_from(scope, to), opt_flags);
+ if (errmsg) {
+ api_set_error(err, kErrorTypeException, "%s", errmsg);
+ }
});
}