diff options
author | Famiu Haque <famiuhaque@proton.me> | 2024-11-08 11:57:59 +0600 |
---|---|---|
committer | Famiu Haque <famiuhaque@proton.me> | 2024-12-26 20:55:13 +0600 |
commit | 6257270040bc5c61a489f7fb9d4102223c36cf89 (patch) | |
tree | a0db9a3bf31b56dedd9a240b54c5d47b02ce43ff /src/nvim/api/deprecated.c | |
parent | 98763ce4e93752f22d379e3f735f4c78ae49afad (diff) | |
download | rneovim-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/deprecated.c')
-rw-r--r-- | src/nvim/api/deprecated.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/nvim/api/deprecated.c b/src/nvim/api/deprecated.c index d5eddb74de..47a49436ab 100644 --- a/src/nvim/api/deprecated.c +++ b/src/nvim/api/deprecated.c @@ -649,8 +649,8 @@ static Object get_option_from(void *from, OptScope scope, String name, Error *er OptVal value = NIL_OPTVAL; if (option_has_scope(opt_idx, scope)) { - value = get_option_value_for(opt_idx, scope == kOptScopeGlobal ? OPT_GLOBAL : OPT_LOCAL, - scope, from, err); + value = get_option_value_from(opt_idx, option_ctx_from(scope, from), + scope == kOptScopeGlobal ? OPT_GLOBAL : OPT_LOCAL); if (ERROR_SET(err)) { return (Object)OBJECT_INIT; } @@ -701,7 +701,11 @@ static void set_option_to(uint64_t channel_id, void *to, OptScope scope, String : ((scope == kOptScopeGlobal) ? OPT_GLOBAL : OPT_LOCAL); 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); + } }); } |