mirror of
https://github.com/neovim/neovim.git
synced 2025-09-24 20:18:32 +00:00
Merge pull request #31112 from famiu/refactor/options/set_option_for
refactor(options): set option value for non-current context directly
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@@ -983,10 +983,10 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err)
|
||||
buf_copy_options(buf, BCO_ENTER | BCO_NOHELP);
|
||||
|
||||
if (scratch) {
|
||||
set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL, 0,
|
||||
kOptScopeBuf, buf);
|
||||
set_option_direct_for(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL, 0,
|
||||
kOptScopeBuf, buf);
|
||||
set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"),
|
||||
option_ctx_from(kOptScopeBuf, buf), OPT_LOCAL, 0);
|
||||
set_option_direct_for(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"),
|
||||
option_ctx_from(kOptScopeBuf, buf), OPT_LOCAL, 0);
|
||||
assert(buf->b_ml.ml_mfp->mf_fd < 0); // ml_open() should not have opened swapfile already
|
||||
buf->b_p_swf = false;
|
||||
buf->b_p_ml = false;
|
||||
|
Reference in New Issue
Block a user