Merge #41045 from justinmk/refactoroptions

This commit is contained in:
Justin M. Keyes 2026-07-29 09:57:19 -04:00 committed by GitHub
commit b9d732c249
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
40 changed files with 465 additions and 521 deletions

View File

@ -144,7 +144,9 @@ end
--- @param opt_type vim.option_type
--- @return string
local function opt_type_enum(opt_type)
return ('kOptValType%s'):format(lowercase_to_titlecase(opt_type))
return ('kObjectType%s'):format(
({ boolean = 'Boolean', number = 'Integer', string = 'String' })[opt_type]
)
end
--- @param scope vim.option_scope
@ -213,7 +215,10 @@ local function get_opt_val(v)
end
end
return ('{ .type = %s, .data.%s = %s }'):format(opt_type_enum(v_type), v_type, v)
-- def_val is stored as an API Object.
local obj_type = ({ boolean = 'Boolean', number = 'Integer', string = 'String' })[v_type]
local obj_field = ({ boolean = 'boolean', number = 'integer', string = 'string' })[v_type]
return ('{ .type = kObjectType%s, .data.%s = %s }'):format(obj_type, obj_field, v)
end
--- @param d vim.option_value|function
@ -281,11 +286,12 @@ local function dump_option(i, o, write)
end
if not o.defaults then
write(' .def_val=NIL_OPTVAL')
write(' .def_val={ .type = kObjectTypeNil }')
elseif o.defaults.condition then
write(('#if defined(%s)'):format(o.defaults.condition))
write(' .def_val=', get_defaults(o.defaults.if_true, o.full_name))
if o.defaults.if_false then
-- Check against nil: `if_false=false` is a valid default and must still emit the `#else`.
if o.defaults.if_false ~= nil then
write('#else')
write(' .def_val=', get_defaults(o.defaults.if_false, o.full_name))
end

View File

@ -743,21 +743,19 @@ static Object get_option_from(void *from, OptScope scope, String name, Error *er
return (Object)OBJECT_INIT;
});
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);
if (ERROR_SET(err)) {
return (Object)OBJECT_INIT;
}
}
VALIDATE_S(value.type != kOptValTypeNil, "option name", name.data, {
// Reject a scope the option doesn't support. This must be an explicit check: an unset value is
// itself Nil, so a Nil value can't distinguish "unsupported scope" from "unset value".
VALIDATE_S(option_has_scope(opt_idx, scope), "option name", name.data, {
return (Object)OBJECT_INIT;
});
return optval_as_object(value);
Object value = get_option_value_for(opt_idx, scope == kOptScopeGlobal ? OPT_GLOBAL : OPT_LOCAL,
scope, from, err);
if (ERROR_SET(err)) {
return (Object)OBJECT_INIT;
}
return value;
}
/// Sets the value of a global or local (buffer, window) option.
@ -779,16 +777,16 @@ static void set_option_to(uint64_t channel_id, void *to, OptScope scope, String
return;
});
bool error = false;
OptVal optval = object_as_optval(value, &error);
// Handle invalid option value type.
// Only scalar Objects (nil/boolean/number/string) are valid option values.
// Don't use `name` in the error message here, because `name` can be any String.
// No need to check if value type actually matches the types for the option, as set_option_value()
// already handles that.
VALIDATE_EXP(!error, "value", "valid option type", api_typename(value.type), {
const bool valid = value.type == kObjectTypeNil || value.type == kObjectTypeBoolean
|| value.type == kObjectTypeInteger || value.type == kObjectTypeString;
VALIDATE_EXP(valid, "value", "valid option type", api_typename(value.type), {
return;
});
Object optval = value;
// For global-win-local options -> setlocal
// For win-local options -> setglobal and setlocal (opt_flags == 0)

View File

@ -125,9 +125,8 @@ static int validate_option_value_args(Dict(option) *opts, char *name, bool allow
});
}
VALIDATE_CON(*operation == OP_NONE || option_has_type(*opt_idxp,
kOptValTypeString)
|| option_has_type(*opt_idxp, kOptValTypeNumber),
VALIDATE_CON(*operation == OP_NONE || option_has_type(*opt_idxp, kObjectTypeString)
|| option_has_type(*opt_idxp, kObjectTypeInteger),
opts->operation.data,
"boolean options", {
return FAIL;
@ -188,8 +187,8 @@ static buf_T *do_ft_buf(const char *filetype, CtxSwitch *aco, Error *err)
// Set curwin/curbuf to buf and save a few things.
ctx_switch(aco, NULL, NULL, ftbuf, 0);
set_option_direct(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL, SID_NONE);
set_option_direct(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL, SID_NONE);
set_option_direct(kOptBufhidden, STATIC_CSTR_AS_OBJ("hide"), OPT_LOCAL, SID_NONE);
set_option_direct(kOptBuftype, STATIC_CSTR_AS_OBJ("nofile"), OPT_LOCAL, SID_NONE);
assert(ftbuf->b_ml.ml_mfp->mf_fd < 0); // ml_open() should not have opened swapfile already
ftbuf->b_p_swf = false;
ftbuf->b_p_ml = false;
@ -289,7 +288,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);
Object value = get_option_value_for(opt_idx, opt_flags, scope, from, err);
// Restore curwin/curbuf and a few other things.
ctx_restore(&aco);
@ -298,17 +297,11 @@ Object nvim_get_option_value(String name, Dict(option) *opts, Error *err)
}
if (ERROR_SET(err)) {
goto err;
api_free_object(value);
return (Object)OBJECT_INIT;
}
VALIDATE_S(value.type != kOptValTypeNil, "option", name.data, {
goto err;
});
return optval_as_object(value);
err:
optval_free(value);
return (Object)OBJECT_INIT;
return value;
}
/// Sets the value of an option. The behavior of this function matches that of
@ -361,15 +354,15 @@ Object nvim_set_option_value(uint64_t channel_id, String name, Object value, Dic
}
}
// Convert the incoming value into an OptVal.
// Convert the incoming value into an Object.
bool error = false;
OptVal optval_right = object_as_optval_for(opt_idx, value, operation, &error);
Object optval_right = object_as_optval(opt_idx, value, operation, &error);
VALIDATE_EXP(!error, name.data, "a valid type", api_typename(value.type), {
return NIL;
});
OptVal merged_val = NIL_OPTVAL;
Object merged_val = NIL;
const char *errmsg = NULL;
vimoption_T *option = get_option(opt_idx);
@ -381,9 +374,10 @@ Object nvim_set_option_value(uint64_t channel_id, String name, Object value, Dic
char *argp = NULL;
switch (optval_right.type) {
case kOptValTypeNil:
case kObjectTypeUnset:
case kObjectTypeNil:
break;
case kOptValTypeString: {
case kObjectTypeString: {
char *optval_escaped = escape_option_str_cmdline(optval_right.data.string.data);
// We need a leading equal sign because get_option_newval is used for
// cmdline stuff and expects an =
@ -391,18 +385,20 @@ Object nvim_set_option_value(uint64_t channel_id, String name, Object value, Dic
XFREE_CLEAR(optval_escaped);
break;
}
case kOptValTypeNumber:
argp = arena_printf(arena, "=%" PRId64, optval_right.data.number).data;
case kObjectTypeInteger:
argp = arena_printf(arena, "=%" PRId64, optval_right.data.integer).data;
break;
case kOptValTypeBoolean:
case kObjectTypeBoolean:
merged_val = optval_right;
break;
default:
abort();
}
optval_free(optval_right);
if (optval_right.type == kOptValTypeNumber || optval_right.type == kOptValTypeString) {
OptVal oldval = optval_from_varp(opt_idx, varp);
if (optval_right.type == kObjectTypeInteger || optval_right.type == kObjectTypeString) {
Object oldval = opt_from_varp(opt_idx, varp);
merged_val = get_option_newval(opt_idx, opt_flags, PREFIX_NONE, &argp, 0, operation,
option->flags, varp, &oldval, NULL, 0, &errmsg);
VALIDATE(errmsg == NULL, "%s", errmsg, {

View File

@ -278,6 +278,7 @@ void object_to_vim_take_luaref(Object *obj, typval_T *tv, bool take_luaref, Erro
tv->v_lock = VAR_UNLOCKED;
switch (obj->type) {
case kObjectTypeUnset:
case kObjectTypeNil:
tv->v_type = VAR_SPECIAL;
tv->vval.v_special = kSpecialVarNull;

View File

@ -104,6 +104,9 @@ typedef enum {
kObjectTypeArray,
kObjectTypeDict,
kObjectTypeLuaRef,
/// Internal-only: for unset options (e.g. the local value of a global-local option).
/// Never crosses RPC/Lua boundary (becomes Nil).
kObjectTypeUnset,
// EXT types, cannot be split or reordered, see #EXT_OBJECT_TYPE_SHIFT
kObjectTypeBuffer,
kObjectTypeWindow,

View File

@ -540,6 +540,7 @@ Array arena_take_arraybuilder(Arena *arena, ArrayBuilder *arr)
void api_free_object(Object value)
{
switch (value.type) {
case kObjectTypeUnset:
case kObjectTypeNil:
case kObjectTypeBoolean:
case kObjectTypeInteger:
@ -659,6 +660,7 @@ Dict copy_dict(Dict dict, Arena *arena)
Object copy_object(Object obj, Arena *arena)
{
switch (obj.type) {
case kObjectTypeUnset:
case kObjectTypeBuffer:
case kObjectTypeTabpage:
case kObjectTypeWindow:
@ -740,6 +742,8 @@ int object_to_hl_id(Object obj, const char *what, Error *err)
char *api_typename(ObjectType t)
{
switch (t) {
case kObjectTypeUnset:
return "unset";
case kObjectTypeNil:
return "nil";
case kObjectTypeBoolean:

View File

@ -62,6 +62,7 @@
.data.luaref = r })
#define NIL ((Object)OBJECT_INIT)
#define UNSET ((Object) { .type = kObjectTypeUnset })
#define NULL_STRING ((String)STRING_INIT)
#define HAS_KEY(d, typ, key) (((d)->is_set__##typ##_ & (1ULL << KEYSET_OPTIDX_##typ##__##key)) != 0)

View File

@ -1068,9 +1068,9 @@ 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,
set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OBJ("hide"), OPT_LOCAL, 0,
kOptScopeBuf, buf);
set_option_direct_for(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL, 0,
set_option_direct_for(kOptBuftype, STATIC_CSTR_AS_OBJ("nofile"), OPT_LOCAL, 0,
kOptScopeBuf, buf);
assert(buf->b_ml.ml_mfp->mf_fd < 0); // ml_open() should not have opened swapfile already
buf->b_p_swf = false;

View File

@ -703,7 +703,7 @@ char *au_event_disable(char *what)
} else {
STRCPY(new_ei + p_ei_len, what);
}
set_option_direct(kOptEventignore, CSTR_AS_OPTVAL(new_ei), 0, SID_NONE);
set_option_direct(kOptEventignore, CSTR_AS_OBJ(new_ei), 0, SID_NONE);
xfree(new_ei);
return save_ei;
}
@ -711,7 +711,7 @@ char *au_event_disable(char *what)
void au_event_restore(char *old_ei)
{
if (old_ei != NULL) {
set_option_direct(kOptEventignore, CSTR_AS_OPTVAL(old_ei), 0, SID_NONE);
set_option_direct(kOptEventignore, CSTR_AS_OBJ(old_ei), 0, SID_NONE);
xfree(old_ei);
}
}
@ -1316,8 +1316,8 @@ static void deferred_optionset_modified(void **argv)
api_clear_error(&err);
if (buf) {
bool new_val = (bool)(uintptr_t)argv[1];
OptVal old = BOOLEAN_OPTVAL(!new_val);
OptVal new = BOOLEAN_OPTVAL(new_val);
Object old = BOOLEAN_OBJ(!new_val);
Object new = BOOLEAN_OBJ(new_val);
CtxSwitch aco = { 0 };
ctx_switch(&aco, NULL, NULL, buf, 0);
apply_optionset_autocmd_now(kOptModified, OPT_LOCAL, old, old, old, new, NULL);

View File

@ -131,8 +131,8 @@ void ctx_save(Context *ctx, const int flags)
void ctx_load(Context *ctx, const int flags)
FUNC_ATTR_NONNULL_ALL
{
OptVal op_shada = get_option_value(kOptShada, OPT_GLOBAL);
set_option_value(kOptShada, STATIC_CSTR_AS_OPTVAL("!,'100,%"), OPT_GLOBAL);
Object op_shada = get_option_value(kOptShada, OPT_GLOBAL);
set_option_value(kOptShada, STATIC_CSTR_AS_OBJ("!,'100,%"), OPT_GLOBAL);
if (flags & kCtxRegs) {
shada_read_string(ctx->regs, kShaDaWantInfo | kShaDaForceit);

View File

@ -1519,7 +1519,7 @@ static void set_diff_option(win_T *wp, bool value)
curwin = wp;
curbuf = curwin->w_buffer;
curbuf->b_ro_locked++;
set_option_value_give_err(kOptDiff, BOOLEAN_OPTVAL(value), OPT_LOCAL);
set_option_value_give_err(kOptDiff, BOOLEAN_OBJ(value), OPT_LOCAL);
curbuf->b_ro_locked--;
curwin = old_curwin;
curbuf = curwin->w_buffer;
@ -1561,7 +1561,7 @@ void diff_win_options(win_T *wp, bool addbuf)
}
wp->w_p_fdm_save = xstrdup(wp->w_p_fdm);
}
set_option_direct_for(kOptFoldmethod, STATIC_CSTR_AS_OPTVAL("diff"), OPT_LOCAL, 0,
set_option_direct_for(kOptFoldmethod, STATIC_CSTR_AS_OBJ("diff"), OPT_LOCAL, 0,
kOptScopeWin, wp);
if (!wp->w_p_diff) {

View File

@ -3405,10 +3405,10 @@ int eval_option(const char **const arg, typval_T *const rettv, const bool evalua
ret = FAIL;
} else if (rettv != NULL) {
OptVal value = is_tty_opt ? get_tty_option(*arg) : get_option_value(opt_idx, opt_flags);
assert(value.type != kOptValTypeNil);
Object value = is_tty_opt ? get_tty_option(*arg) : get_option_value(opt_idx, opt_flags);
assert(value.type != kObjectTypeNil);
*rettv = optval_as_tv(value, true);
*rettv = opt_to_tv(value, true);
} else if (working && !is_tty_opt && is_option_hidden(opt_idx)) {
ret = FAIL;
}
@ -6459,7 +6459,7 @@ char *do_string_sub(char *str, size_t len, char *pat, char *sub, typval_T *expr,
// If it's still empty it was changed and restored, need to restore in
// the complicated way.
if (*p_cpo == NUL) {
set_option_value_give_err(kOptCpoptions, CSTR_AS_OPTVAL(save_cpo), 0);
set_option_value_give_err(kOptCpoptions, CSTR_AS_OBJ(save_cpo), 0);
}
free_string_option(save_cpo);
}

View File

@ -6202,7 +6202,7 @@ int do_searchpair(const char *spat, const char *mpat, const char *epat, int dir,
// If it's still empty it was changed and restored, need to restore in
// the complicated way.
if (*p_cpo == NUL) {
set_option_value_give_err(kOptCpoptions, CSTR_AS_OPTVAL(save_cpo), 0);
set_option_value_give_err(kOptCpoptions, CSTR_AS_OBJ(save_cpo), 0);
}
free_string_option(save_cpo);
}

View File

@ -1371,35 +1371,35 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const,
bool is_tty_opt = is_tty_option(arg);
bool hidden = is_option_hidden(opt_idx);
OptVal curval = is_tty_opt ? get_tty_option(arg) : get_option_value(opt_idx, opt_flags);
OptVal newval = NIL_OPTVAL;
Object curval = is_tty_opt ? get_tty_option(arg) : get_option_value(opt_idx, opt_flags);
Object newval = NIL;
if (curval.type == kOptValTypeNil) {
if (curval.type == kObjectTypeNil) {
semsg(_(e_unknown_option2), arg);
goto theend;
}
if (op != NULL && *op != '='
&& ((curval.type != kOptValTypeString && *op == '.')
|| (curval.type == kOptValTypeString && *op != '.'))) {
&& ((curval.type != kObjectTypeString && *op == '.')
|| (curval.type == kObjectTypeString && *op != '.'))) {
semsg(_(e_letwrong), op);
goto theend;
}
bool error;
newval = tv_to_optval(tv, opt_idx, arg, &error);
newval = opt_from_tv(tv, opt_idx, arg, &error);
if (error) {
goto theend;
}
// Current value and new value must have the same type.
assert(curval.type == newval.type);
const bool is_num = curval.type == kOptValTypeNumber || curval.type == kOptValTypeBoolean;
const bool is_string = curval.type == kOptValTypeString;
const bool is_num = curval.type == kObjectTypeInteger || curval.type == kObjectTypeBoolean;
const bool is_string = curval.type == kObjectTypeString;
if (op != NULL && *op != '=') {
if (!hidden && is_num) { // number or bool
OptInt cur_n = curval.type == kOptValTypeNumber ? curval.data.number : curval.data.boolean;
OptInt new_n = newval.type == kOptValTypeNumber ? newval.data.number : newval.data.boolean;
OptInt cur_n = curval.type == kObjectTypeInteger ? curval.data.integer : curval.data.boolean;
OptInt new_n = newval.type == kObjectTypeInteger ? newval.data.integer : newval.data.boolean;
switch (*op) {
case '+':
@ -1414,18 +1414,18 @@ static char *ex_let_option(char *arg, typval_T *const tv, const bool is_const,
new_n = num_modulus(cur_n, new_n); break;
}
if (curval.type == kOptValTypeNumber) {
newval = NUMBER_OPTVAL(new_n);
if (curval.type == kObjectTypeInteger) {
newval = INTEGER_OBJ(new_n);
} else {
newval = BOOLEAN_OPTVAL(TRISTATE_FROM_INT(new_n));
newval = opt_from_tristate(TRISTATE_FROM_INT(new_n));
}
} else if (!hidden && is_string) { // string
const char *curval_data = curval.data.string.data;
const char *newval_data = newval.data.string.data;
if (curval_data != NULL && newval_data != NULL) {
OptVal newval_old = newval;
newval = CSTR_AS_OPTVAL(concat_str(curval_data, newval_data));
Object newval_old = newval;
newval = CSTR_AS_OBJ(concat_str(curval_data, newval_data));
optval_free(newval_old);
}
}
@ -3186,24 +3186,23 @@ static void getwinvar(typval_T *argvars, typval_T *rettv, int off)
get_var_from(varname, rettv, &argvars[off + 2], 'w', tp, win, NULL);
}
/// Convert typval to option value for a particular option.
/// Converts a typval to a structured option value.
///
/// @param[in] tv typval to convert.
/// @param[in] option Option name.
/// @param[in] flags Option flags.
/// @param[out] error Whether an error occurred.
///
/// @return Typval converted to OptVal. Must be freed by caller.
/// Returns NIL_OPTVAL for invalid option name.
static OptVal tv_to_optval(typval_T *tv, OptIndex opt_idx, const char *option, bool *error)
/// @return Structured option, or NIL if invalid option name. Must be freed by caller.
static Object opt_from_tv(typval_T *tv, OptIndex opt_idx, const char *option, bool *error)
{
OptVal value = NIL_OPTVAL;
Object value = NIL;
char nbuf[NUMBUFLEN];
bool err = false;
const bool is_tty_opt = is_tty_option(option);
const bool option_has_bool = !is_tty_opt && option_has_type(opt_idx, kOptValTypeBoolean);
const bool option_has_num = !is_tty_opt && option_has_type(opt_idx, kOptValTypeNumber);
const bool option_has_str = is_tty_opt || option_has_type(opt_idx, kOptValTypeString);
const bool option_has_bool = !is_tty_opt && option_has_type(opt_idx, kObjectTypeBoolean);
const bool option_has_num = !is_tty_opt && option_has_type(opt_idx, kObjectTypeInteger);
const bool option_has_str = is_tty_opt || option_has_type(opt_idx, kObjectTypeString);
if (!is_tty_opt && (get_option(opt_idx)->flags & kOptFlagFunc) && tv_is_func(*tv)) {
// If the option can be set to a function reference or a lambda
@ -3211,7 +3210,7 @@ static OptVal tv_to_optval(typval_T *tv, OptIndex opt_idx, const char *option, b
// the name (string) of the function reference.
char *strval = encode_tv2string(tv, NULL);
err = strval == NULL;
value = CSTR_AS_OPTVAL(strval);
value = CSTR_AS_OBJ(strval);
} else if (option_has_bool || option_has_num) {
varnumber_T n = option_has_num ? tv_get_number_chk(tv, &err) : tv_get_bool_chk(tv, &err);
// This could be either "0" or a string that's not a number.
@ -3227,13 +3226,13 @@ static OptVal tv_to_optval(typval_T *tv, OptIndex opt_idx, const char *option, b
tv->vval.v_string == NULL ? "" : tv->vval.v_string);
}
}
value = option_has_num ? NUMBER_OPTVAL((OptInt)n) : BOOLEAN_OPTVAL(TRISTATE_FROM_INT(n));
value = option_has_num ? INTEGER_OBJ((OptInt)n) : opt_from_tristate(TRISTATE_FROM_INT(n));
} else if (option_has_str) {
// Avoid setting string option to a boolean or a special value.
if (tv->v_type != VAR_BOOL && tv->v_type != VAR_SPECIAL) {
const char *strval = tv_get_string_buf_chk(tv, nbuf);
err = strval == NULL;
value = CSTR_TO_OPTVAL(strval);
value = CSTR_TO_OBJ(strval);
} else if (!is_tty_opt) {
err = true;
emsg(_(e_string_required));
@ -3248,37 +3247,47 @@ static OptVal tv_to_optval(typval_T *tv, OptIndex opt_idx, const char *option, b
return value;
}
/// Convert an option value to typval.
/// Converts an option value to typval.
///
/// @param[in] value Option value to convert.
/// @param numbool Whether to convert boolean values to number.
/// Used for backwards compatibility.
///
/// @return OptVal converted to typval.
typval_T optval_as_tv(OptVal value, bool numbool)
/// @return Object converted to typval.
typval_T opt_to_tv(Object value, bool numbool)
{
typval_T rettv = { .v_type = VAR_SPECIAL, .vval = { .v_special = kSpecialVarNull } };
switch (value.type) {
case kOptValTypeNil:
case kObjectTypeUnset:
// Legacy numbool callers (e.g. `&l:autoread` unset global-local boolean)
// expect the kNone; otherwise an unset value is v:null.
if (numbool) {
rettv.v_type = VAR_NUMBER;
rettv.vval.v_number = kNone;
}
break;
case kOptValTypeBoolean:
case kObjectTypeNil:
break; // Return v:null.
case kObjectTypeBoolean:
if (numbool) {
rettv.v_type = VAR_NUMBER;
rettv.vval.v_number = value.data.boolean;
} else if (value.data.boolean != kNone) {
} else {
rettv.v_type = VAR_BOOL;
rettv.vval.v_bool = value.data.boolean == kTrue;
rettv.vval.v_bool = value.data.boolean ? kBoolVarTrue : kBoolVarFalse;
}
break; // return v:null for None boolean value.
case kOptValTypeNumber:
rettv.v_type = VAR_NUMBER;
rettv.vval.v_number = value.data.number;
break;
case kOptValTypeString:
case kObjectTypeInteger:
rettv.v_type = VAR_NUMBER;
rettv.vval.v_number = value.data.integer;
break;
case kObjectTypeString:
rettv.v_type = VAR_STRING;
rettv.vval.v_string = value.data.string.data;
break;
default:
abort(); // Should never happen.
}
return rettv;
@ -3294,7 +3303,7 @@ static void set_option_from_tv(const char *varname, typval_T *varp)
}
bool error = false;
OptVal value = tv_to_optval(varp, opt_idx, varname, &error);
Object value = opt_from_tv(varp, opt_idx, varname, &error);
if (!error) {
const char *errmsg = set_option_value_handle_tty(varname, opt_idx, value, OPT_LOCAL);

View File

@ -4512,7 +4512,7 @@ skip:
// Show 'inccommand' preview if there are matched lines.
if (cmdpreview_ns > 0 && !aborting()) {
if (got_quit || profile_passed_limit(tm)) { // Too slow, disable.
set_option_direct(kOptInccommand, STATIC_CSTR_AS_OPTVAL(""), 0, SID_NONE);
set_option_direct(kOptInccommand, STATIC_CSTR_AS_OBJ(""), 0, SID_NONE);
} else if (*p_icm != NUL && pat.data != NULL) {
if (pre_hl_id == 0) {
pre_hl_id = syn_check_group(S_LEN("Substitute"));
@ -4811,7 +4811,7 @@ bool prepare_tagpreview(bool undo_sync, bool use_previewpopup)
RESET_BINDING(curwin); // don't take over 'scrollbind' and 'cursorbind'
curwin->w_p_diff = false; // no 'diff'
set_option_direct(kOptFoldcolumn, STATIC_CSTR_AS_OPTVAL("0"), 0, SID_NONE); // no 'foldcolumn'
set_option_direct(kOptFoldcolumn, STATIC_CSTR_AS_OBJ("0"), 0, SID_NONE); // no 'foldcolumn'
return true;
}
@ -4830,7 +4830,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i
buf_T *cmdpreview_buf = NULL;
// disable file info message
set_option_direct(kOptShortmess, STATIC_CSTR_AS_OPTVAL("F"), 0, SID_NONE);
set_option_direct(kOptShortmess, STATIC_CSTR_AS_OBJ("F"), 0, SID_NONE);
// Place cursor on nearest matching line, to undo do_sub() cursor placement.
for (size_t i = 0; i < lines.subresults.size; i++) {
@ -4931,7 +4931,7 @@ static int show_sub(exarg_T *eap, pos_T old_cusr, PreviewLines *preview_lines, i
xfree(str);
set_option_direct(kOptShortmess, CSTR_AS_OPTVAL(save_shm_p), 0, SID_NONE);
set_option_direct(kOptShortmess, CSTR_AS_OBJ(save_shm_p), 0, SID_NONE);
xfree(save_shm_p);
return preview ? 2 : 1;

View File

@ -2749,7 +2749,7 @@ void apply_cmdmod(cmdmod_T *cmod)
// Set 'eventignore' to "all".
// First save the existing option value for restoring it later.
cmod->cmod_save_ei = xstrdup(p_ei);
set_option_direct(kOptEventignore, STATIC_CSTR_AS_OPTVAL("all"), 0, SID_NONE);
set_option_direct(kOptEventignore, STATIC_CSTR_AS_OBJ("all"), 0, SID_NONE);
}
}
@ -2769,7 +2769,7 @@ void undo_cmdmod(cmdmod_T *cmod)
if (cmod->cmod_save_ei != NULL) {
// Restore 'eventignore' to the value before ":noautocmd".
set_option_direct(kOptEventignore, CSTR_AS_OPTVAL(cmod->cmod_save_ei), 0, SID_NONE);
set_option_direct(kOptEventignore, CSTR_AS_OBJ(cmod->cmod_save_ei), 0, SID_NONE);
free_string_option(cmod->cmod_save_ei);
cmod->cmod_save_ei = NULL;
}
@ -8007,7 +8007,7 @@ static void ex_setfiletype(exarg_T *eap)
arg += 9;
}
set_option_value_give_err(kOptFiletype, CSTR_AS_OPTVAL(arg), OPT_LOCAL);
set_option_value_give_err(kOptFiletype, CSTR_AS_OBJ(arg), OPT_LOCAL);
if (arg != eap->arg) {
curbuf->b_did_filetype = false;
}

View File

@ -982,7 +982,7 @@ static uint8_t *command_line_enter(int firstc, int count, int indent, bool clear
need_wait_return = false;
}
set_option_direct(kOptInccommand, CSTR_AS_OPTVAL(s->save_p_icm), 0, SID_NONE);
set_option_direct(kOptInccommand, CSTR_AS_OBJ(s->save_p_icm), 0, SID_NONE);
State = s->save_State;
if (cmdpreview != save_cmdpreview) {
cmdpreview = save_cmdpreview; // restore preview state
@ -2712,7 +2712,7 @@ static bool cmdpreview_may_show(CommandLineState *s)
// Open preview buffer if inccommand=split.
if (icm_split && (cmdpreview_buf = cmdpreview_open_buf()) == NULL) {
// Failed to create preview buffer, so disable preview.
set_option_direct(kOptInccommand, STATIC_CSTR_AS_OPTVAL("nosplit"), 0, SID_NONE);
set_option_direct(kOptInccommand, STATIC_CSTR_AS_OBJ("nosplit"), 0, SID_NONE);
icm_split = false;
}
// Setup preview namespace if it's not already set.

View File

@ -1681,7 +1681,7 @@ failed:
save_file_ff(curbuf);
// If editing a new file: set 'fenc' for the current buffer.
// Also for ":read ++edit file".
set_option_direct(kOptFileencoding, CSTR_AS_OPTVAL(fenc), OPT_LOCAL, 0);
set_option_direct(kOptFileencoding, CSTR_AS_OBJ(fenc), OPT_LOCAL, 0);
}
if (fenc_alloced) {
xfree(fenc);
@ -2023,7 +2023,7 @@ void set_forced_fenc(exarg_T *eap)
}
char *fenc = enc_canonize(eap->cmd + eap->force_enc);
set_option_direct(kOptFileencoding, CSTR_AS_OPTVAL(fenc), OPT_LOCAL, 0);
set_option_direct(kOptFileencoding, CSTR_AS_OBJ(fenc), OPT_LOCAL, 0);
xfree(fenc);
}

View File

@ -423,7 +423,7 @@ void cleanup_help_tags(int num_file, char **file)
void prepare_help_buffer(void)
{
curbuf->b_help = true;
set_option_direct(kOptBuftype, STATIC_CSTR_AS_OPTVAL("help"), OPT_LOCAL, 0);
set_option_direct(kOptBuftype, STATIC_CSTR_AS_OBJ("help"), OPT_LOCAL, 0);
// Always set these options after jumping to a help tag, because the
// user may have an autocommand that gets in the way.
@ -432,13 +432,13 @@ void prepare_help_buffer(void)
// Only set it when needed, buf_init_chartab() is some work.
char *p = "!-~,^*,^|,^\",192-255";
if (strcmp(curbuf->b_p_isk, p) != 0) {
set_option_direct(kOptIskeyword, CSTR_AS_OPTVAL(p), OPT_LOCAL, 0);
set_option_direct(kOptIskeyword, CSTR_AS_OBJ(p), OPT_LOCAL, 0);
check_buf_options(curbuf);
buf_init_chartab(curbuf, false);
}
// Don't use the global foldmethod.
set_option_direct(kOptFoldmethod, STATIC_CSTR_AS_OPTVAL("manual"), OPT_LOCAL, 0);
set_option_direct(kOptFoldmethod, STATIC_CSTR_AS_OBJ("manual"), OPT_LOCAL, 0);
curbuf->b_p_ts = 8; // 'tabstop' is 8.
curwin->w_p_list = false; // No list mode.

View File

@ -1448,7 +1448,7 @@ void do_highlight(const char *line, const bool forceit, const bool init)
&& dark != (*p_bg == 'd')
&& !option_was_set(kOptBackground)) {
set_option_value_give_err(kOptBackground,
CSTR_AS_OPTVAL(dark ? "dark" : "light"), 0);
CSTR_AS_OBJ(dark ? "dark" : "light"), 0);
reset_option_was_set(kOptBackground);
}
}

View File

@ -1600,7 +1600,7 @@ void ex_retab(exarg_T *eap)
colnr_T *old_vts_ary = curbuf->b_p_vts_array;
if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_vts_array) > 1) {
set_option_direct(kOptVartabstop, CSTR_AS_OPTVAL(new_ts_str), OPT_LOCAL, 0);
set_option_direct(kOptVartabstop, CSTR_AS_OBJ(new_ts_str), OPT_LOCAL, 0);
curbuf->b_p_vts_array = new_vts_array;
xfree(old_vts_ary);
} else {

View File

@ -3036,9 +3036,9 @@ const char *did_set_completefunc(optset_T *args)
int retval;
if (args->os_flags & OPT_LOCAL) {
retval = option_set_callback_func(args->os_newval.string.data, &buf->b_cfu_cb);
retval = option_set_callback_func(args->os_newval.data.string.data, &buf->b_cfu_cb);
} else {
retval = option_set_callback_func(args->os_newval.string.data, &cfu_cb);
retval = option_set_callback_func(args->os_newval.data.string.data, &cfu_cb);
if (retval == OK && !(args->os_flags & OPT_GLOBAL)) {
set_buflocal_cfu_callback(buf);
}
@ -3064,9 +3064,9 @@ const char *did_set_omnifunc(optset_T *args)
int retval;
if (args->os_flags & OPT_LOCAL) {
retval = option_set_callback_func(args->os_newval.string.data, &buf->b_ofu_cb);
retval = option_set_callback_func(args->os_newval.data.string.data, &buf->b_ofu_cb);
} else {
retval = option_set_callback_func(args->os_newval.string.data, &ofu_cb);
retval = option_set_callback_func(args->os_newval.data.string.data, &ofu_cb);
if (retval == OK && !(args->os_flags & OPT_GLOBAL)) {
set_buflocal_ofu_callback(buf);
}

View File

@ -741,6 +741,7 @@ void nlua_push_Object(lua_State *lstate, Object *obj, int flags)
FUNC_ATTR_NONNULL_ALL
{
switch (obj->type) {
case kObjectTypeUnset:
case kObjectTypeNil:
if (flags & kNluaPushSpecial) {
lua_pushnil(lstate);

View File

@ -1189,7 +1189,7 @@ static void command_line_scan(mparm_T *parmp)
} else if (STRNICMP(argv[0] + argv_idx, "clean", 5) == 0) {
parmp->use_vimrc = "NONE";
parmp->clean = true;
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OPTVAL("NONE"), 0);
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OBJ("NONE"), 0);
} else if (STRNICMP(argv[0] + argv_idx, "luamod-dev", 9) == 0) {
nlua_disable_preload = true;
} else {
@ -1203,7 +1203,7 @@ static void command_line_scan(mparm_T *parmp)
}
break;
case 'A': // "-A" start in Arabic mode.
set_option_value_give_err(kOptArabic, BOOLEAN_OPTVAL(true), 0);
set_option_value_give_err(kOptArabic, BOOLEAN_OBJ(true), 0);
break;
case 'b': // "-b" binary mode.
// Needs to be effective before expanding file names, because
@ -1233,8 +1233,8 @@ static void command_line_scan(mparm_T *parmp)
usage();
os_exit(0);
case 'H': // "-H" start in Hebrew mode: rl + keymap=hebrew set.
set_option_value_give_err(kOptKeymap, STATIC_CSTR_AS_OPTVAL("hebrew"), 0);
set_option_value_give_err(kOptRightleft, BOOLEAN_OPTVAL(true), 0);
set_option_value_give_err(kOptKeymap, STATIC_CSTR_AS_OBJ("hebrew"), 0);
set_option_value_give_err(kOptRightleft, BOOLEAN_OBJ(true), 0);
break;
case 'M': // "-M" no changes or writing of files
reset_modifiable();
@ -1293,7 +1293,7 @@ static void command_line_scan(mparm_T *parmp)
exmode_active = true;
parmp->no_swap_file = true;
if (p_shadafile == NULL || *p_shadafile == NUL) {
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OPTVAL("NONE"), 0);
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OBJ("NONE"), 0);
}
} else { // "-s {scriptin}" read from script file
want_argument = true;
@ -1318,7 +1318,7 @@ static void command_line_scan(mparm_T *parmp)
// default is 10: a little bit verbose
p_verbose = get_number_arg(argv[0], &argv_idx, 10);
if (argv[0][argv_idx] != NUL) {
set_option_value_give_err(kOptVerbosefile, CSTR_AS_OPTVAL(argv[0] + argv_idx), 0);
set_option_value_give_err(kOptVerbosefile, CSTR_AS_OBJ(argv[0] + argv_idx), 0);
argv_idx = (int)strlen(argv[0]);
}
break;
@ -1326,7 +1326,7 @@ static void command_line_scan(mparm_T *parmp)
// "-w {scriptout}" write to script
if (ascii_isdigit((argv[0])[argv_idx])) {
n = get_number_arg(argv[0], &argv_idx, 10);
set_option_value_give_err(kOptWindow, NUMBER_OPTVAL((OptInt)n), 0);
set_option_value_give_err(kOptWindow, INTEGER_OBJ((OptInt)n), 0);
break;
}
want_argument = true;
@ -1424,7 +1424,7 @@ static void command_line_scan(mparm_T *parmp)
break;
case 'i': // "-i {shada}" use for shada
set_option_value_give_err(kOptShadafile, CSTR_AS_OPTVAL(argv[0]), 0);
set_option_value_give_err(kOptShadafile, CSTR_AS_OBJ(argv[0]), 0);
break;
case 'l': // "-l" Lua script: args after "-l".
@ -1434,7 +1434,7 @@ static void command_line_scan(mparm_T *parmp)
parmp->no_swap_file = true;
parmp->use_vimrc = parmp->use_vimrc ? parmp->use_vimrc : "NONE";
if (p_shadafile == NULL || *p_shadafile == NUL) {
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OPTVAL("NONE"), 0);
set_option_value_give_err(kOptShadafile, STATIC_CSTR_AS_OBJ("NONE"), 0);
}
parmp->luaf = argv[0];
argc--;
@ -1471,7 +1471,7 @@ scripterror:
if (ascii_isdigit(*(argv[0]))) {
argv_idx = 0;
n = get_number_arg(argv[0], &argv_idx, 10);
set_option_value_give_err(kOptWindow, NUMBER_OPTVAL((OptInt)n), 0);
set_option_value_give_err(kOptWindow, INTEGER_OBJ((OptInt)n), 0);
argv_idx = -1;
break;
}
@ -1658,7 +1658,7 @@ static void handle_quickfix(mparm_T *paramp)
{
if (paramp->edit_type == EDIT_QF) {
if (paramp->use_ef != NULL) {
set_option_direct(kOptErrorfile, CSTR_AS_OPTVAL(paramp->use_ef), 0, SID_CARG);
set_option_direct(kOptErrorfile, CSTR_AS_OBJ(paramp->use_ef), 0, SID_CARG);
}
vim_snprintf(IObuff, IOSIZE, "cfile %s", p_ef);
if (qf_init(NULL, p_ef, p_efm, true, IObuff, p_menc) < 0) {
@ -1906,7 +1906,7 @@ static void edit_buffers(mparm_T *parmp)
p_shm_save = xstrdup(p_shm);
snprintf(buf, sizeof(buf), "F%s", p_shm);
set_option_value_give_err(kOptShortmess, CSTR_AS_OPTVAL(buf), 0);
set_option_value_give_err(kOptShortmess, CSTR_AS_OBJ(buf), 0);
}
} else {
if (curwin->w_next == NULL) { // just checking
@ -1951,7 +1951,7 @@ static void edit_buffers(mparm_T *parmp)
}
if (p_shm_save != NULL) {
set_option_value_give_err(kOptShortmess, CSTR_AS_OPTVAL(p_shm_save), 0);
set_option_value_give_err(kOptShortmess, CSTR_AS_OBJ(p_shm_save), 0);
xfree(p_shm_save);
}

View File

@ -981,7 +981,7 @@ void ml_recover(bool checkext)
set_fileformat(b0_ff - 1, OPT_LOCAL);
}
if (b0_fenc != NULL) {
set_option_value_give_err(kOptFileencoding, CSTR_AS_OPTVAL(b0_fenc), OPT_LOCAL);
set_option_value_give_err(kOptFileencoding, CSTR_AS_OBJ(b0_fenc), OPT_LOCAL);
xfree(b0_fenc);
}
unchanged(curbuf, true, true);

View File

@ -213,6 +213,7 @@ void mpack_object_inner(Object *current, Object *container, size_t container_idx
api_free_luaref(current->data.luaref);
current->data.luaref = LUA_NOREF;
FALLTHROUGH;
case kObjectTypeUnset:
case kObjectTypeNil:
mpack_nil(&packer->ptr);
break;

File diff suppressed because it is too large Load Diff

View File

@ -40,31 +40,19 @@ typedef enum {
PREFIX_INV, ///< "inv" prefix
} set_prefix_T;
/// Get name of OptValType as a string.
static inline const char *optval_type_get_name(const OptValType type)
/// Gets the option-domain name of an option's type.
static inline const char *optval_type_name(const ObjectType type)
{
switch (type) {
case kOptValTypeNil:
return "nil";
case kOptValTypeBoolean:
case kObjectTypeBoolean:
return "boolean";
case kOptValTypeNumber:
case kObjectTypeInteger:
return "number";
case kOptValTypeString:
case kObjectTypeString:
return "string";
default:
abort();
}
UNREACHABLE;
}
// OptVal helper macros.
#define NIL_OPTVAL ((OptVal) { .type = kOptValTypeNil })
#define BOOLEAN_OPTVAL(b) ((OptVal) { .type = kOptValTypeBoolean, .data.boolean = b })
#define NUMBER_OPTVAL(n) ((OptVal) { .type = kOptValTypeNumber, .data.number = n })
#define STRING_OPTVAL(s) ((OptVal) { .type = kOptValTypeString, .data.string = s })
#define CSTR_AS_OPTVAL(s) STRING_OPTVAL(cstr_as_string(s))
#define CSTR_TO_OPTVAL(s) STRING_OPTVAL(cstr_to_string(s))
#define STATIC_CSTR_AS_OPTVAL(s) STRING_OPTVAL(STATIC_CSTR_AS_STRING(s))
#define STATIC_CSTR_TO_OPTVAL(s) STRING_OPTVAL(STATIC_CSTR_TO_STRING(s))
#include "option.h.generated.h"

View File

@ -42,16 +42,6 @@ typedef enum {
kOptFlagColon = 1 << 25, ///< Values use colons to create sublists.
} OptFlags;
/// Option value type.
/// These types are also used as type flags by using the type value as an index for the type_flags
/// bit field (@see option_has_type()).
typedef enum {
kOptValTypeNil = -1, // Make sure Nil can't be bitshifted and used as an option type flag.
kOptValTypeBoolean,
kOptValTypeNumber,
kOptValTypeString,
} OptValType;
/// Scopes that an option can support.
typedef enum {
kOptScopeGlobal = 0, ///< Request global option value
@ -63,19 +53,6 @@ typedef enum {
#define kOptScopeSize (kOptScopeTab + 1)
typedef uint8_t OptScopeFlags;
typedef union {
// boolean options are actually tri-states because they have a third "None" value.
TriState boolean;
OptInt number;
String string;
} OptValData;
/// Option value
typedef struct {
OptValType type;
OptValData data;
} OptVal;
/// Value kind of one key in a dict option (see "schema" in options.lua).
typedef enum {
kOptSchemaFlag, ///< bare flag, e.g. 'diffopt' "filler"
@ -118,9 +95,9 @@ typedef struct {
int os_flags;
/// Old value of the option.
OptValData os_oldval;
Object os_oldval;
/// New value of the option.
OptValData os_newval;
Object os_newval;
/// Option value was checked to be safe, no need to set kOptFlagInsecure
/// Used for the 'keymap', 'filetype' and 'syntax' options.
@ -192,7 +169,7 @@ typedef struct {
char *fullname; ///< full option name
char *shortname; ///< permissible abbreviation
uint32_t flags; ///< see above
OptValType type; ///< option type
ObjectType type; ///< option type
OptScopeFlags scope_flags; ///< option scope flags, see OptScope
void *var; ///< global option: pointer to variable;
///< window-local option: NULL;
@ -215,6 +192,6 @@ typedef struct {
/// cmdline. Only useful for string options.
opt_expand_cb_T opt_expand_cb;
OptVal def_val; ///< default value
Object def_val; ///< default value
sctx_T script_ctx; ///< script in which the option was last set
} vimoption_T;

View File

@ -574,7 +574,7 @@ const char *did_set_background(optset_T *args)
return errmsg;
}
if (args->os_oldval.string.data[0] == *p_bg) {
if (args->os_oldval.data.string.data[0] == *p_bg) {
// Value was not changed
return NULL;
}
@ -621,7 +621,7 @@ const char *did_set_backspace(optset_T *args FUNC_ATTR_UNUSED)
const char *did_set_backupcopy(optset_T *args)
{
buf_T *buf = (buf_T *)args->os_buf;
const char *oldval = args->os_oldval.string.data;
const char *oldval = args->os_oldval.data.string.data;
int opt_flags = args->os_flags;
char *bkc = p_bkc;
unsigned *flags = &bkc_flags;
@ -725,7 +725,7 @@ const char *did_set_buftype(optset_T *args)
// buftype=prompt:
if (buf->b_p_bt[0] == 'p') {
// Set default value for 'comments'
set_option_direct(kOptComments, STATIC_CSTR_AS_OPTVAL(""), OPT_LOCAL, SID_NONE);
set_option_direct(kOptComments, STATIC_CSTR_AS_OBJ(""), OPT_LOCAL, SID_NONE);
// set the prompt start position to lastline.
pos_T next_prompt = { .lnum = buf->b_ml.ml_line_count, .col = buf->b_prompt_start.mark.col,
.coladd = 0 };
@ -1202,7 +1202,7 @@ int expand_set_eventignore(optexpand_T *args, int *numMatches, char ***matches)
const char *did_set_fileformat(optset_T *args)
{
buf_T *buf = (buf_T *)args->os_buf;
const char *oldval = args->os_oldval.string.data;
const char *oldval = args->os_oldval.data.string.data;
int opt_flags = args->os_flags;
if (!MODIFIABLE(buf) && !(opt_flags & OPT_GLOBAL)) {
return e_modifiable;
@ -1244,7 +1244,7 @@ const char *did_set_filetype_or_syntax(optset_T *args)
return e_invarg;
}
args->os_value_changed = strcmp(args->os_oldval.string.data, *varp) != 0;
args->os_value_changed = strcmp(args->os_oldval.data.string.data, *varp) != 0;
// Since we check the value, there is no need to set kOptFlagInsecure,
// even when the value comes from a modeline.
@ -1615,7 +1615,7 @@ const char *did_set_sessionoptions(optset_T *args)
}
if ((ssop_flags & kOptSsopFlagCurdir) && (ssop_flags & kOptSsopFlagSesdir)) {
// Don't allow both "sesdir" and "curdir".
const char *oldval = args->os_oldval.string.data;
const char *oldval = args->os_oldval.data.string.data;
opt_strings_flags(oldval, opt_ssop_values, &ssop_flags, true, NULL, 0);
return e_invarg;
}
@ -1676,7 +1676,7 @@ const char *did_set_shellpipe_redir(optset_T *args)
{
bool seen = false;
for (char *p = args->os_newval.string.data; *p != NUL; p++) {
for (char *p = args->os_newval.data.string.data; *p != NUL; p++) {
if (*p != '%') {
continue;
}
@ -1745,7 +1745,7 @@ const char *did_set_signcolumn(optset_T *args)
{
win_T *win = (win_T *)args->os_win;
char **varp = (char **)args->os_varp;
const char *oldval = args->os_oldval.string.data;
const char *oldval = args->os_oldval.data.string.data;
if (check_signcolumn(*varp, varp == &win->w_p_scl ? win : NULL) != OK) {
return e_invarg;
}
@ -1796,7 +1796,7 @@ const char *did_set_spelloptions(optset_T *args)
{
win_T *win = (win_T *)args->os_win;
int opt_flags = args->os_flags;
const char *val = args->os_newval.string.data;
const char *val = args->os_newval.data.string.data;
if (!(opt_flags & OPT_LOCAL)) {
const char *errmsg = opt_strings_flags(val, opt_spo_values, &spo_flags, true, args->os_errbuf,
@ -2056,7 +2056,7 @@ const char *did_set_virtualedit(optset_T *args)
args->os_errbuflen);
if (errmsg != NULL) {
return errmsg;
} else if (strcmp(ve, args->os_oldval.string.data) != 0) {
} else if (strcmp(ve, args->os_oldval.data.string.data) != 0) {
// Recompute cursor position in case the new 've' setting
// changes something.
validate_virtcol(win);

View File

@ -1193,11 +1193,11 @@ static bool pum_set_selected(int n, int repeat)
if (res == OK) {
// Edit a new, empty buffer. Set options for a "wipeout"
// buffer.
set_option_value_give_err(kOptSwapfile, BOOLEAN_OPTVAL(false), OPT_LOCAL);
set_option_value_give_err(kOptBuflisted, BOOLEAN_OPTVAL(false), OPT_LOCAL);
set_option_value_give_err(kOptBuftype, STATIC_CSTR_AS_OPTVAL("nofile"), OPT_LOCAL);
set_option_value_give_err(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("wipe"), OPT_LOCAL);
set_option_value_give_err(kOptDiff, BOOLEAN_OPTVAL(false), OPT_LOCAL);
set_option_value_give_err(kOptSwapfile, BOOLEAN_OBJ(false), OPT_LOCAL);
set_option_value_give_err(kOptBuflisted, BOOLEAN_OBJ(false), OPT_LOCAL);
set_option_value_give_err(kOptBuftype, STATIC_CSTR_AS_OBJ("nofile"), OPT_LOCAL);
set_option_value_give_err(kOptBufhidden, STATIC_CSTR_AS_OBJ("wipe"), OPT_LOCAL);
set_option_value_give_err(kOptDiff, BOOLEAN_OBJ(false), OPT_LOCAL);
}
}

View File

@ -3896,12 +3896,12 @@ static int qf_goto_cwindow(const qf_info_T *qi, bool resize, int sz, bool vertsp
static void qf_set_cwindow_options(void)
{
// switch off 'swapfile'
set_option_value_give_err(kOptSwapfile, BOOLEAN_OPTVAL(false), OPT_LOCAL);
set_option_value_give_err(kOptBuftype, STATIC_CSTR_AS_OPTVAL("quickfix"), OPT_LOCAL);
set_option_value_give_err(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("hide"), OPT_LOCAL);
set_option_value_give_err(kOptSwapfile, BOOLEAN_OBJ(false), OPT_LOCAL);
set_option_value_give_err(kOptBuftype, STATIC_CSTR_AS_OBJ("quickfix"), OPT_LOCAL);
set_option_value_give_err(kOptBufhidden, STATIC_CSTR_AS_OBJ("hide"), OPT_LOCAL);
RESET_BINDING(curwin);
curwin->w_p_diff = false;
set_option_value_give_err(kOptFoldmethod, STATIC_CSTR_AS_OPTVAL("manual"), OPT_LOCAL);
set_option_value_give_err(kOptFoldmethod, STATIC_CSTR_AS_OBJ("manual"), OPT_LOCAL);
}
// Open a new quickfix or location list window, load the quickfix buffer and
@ -4495,7 +4495,7 @@ static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last, int q
// resembles reading a file into a buffer, it's more logical when using
// autocommands.
curbuf->b_ro_locked++;
set_option_value_give_err(kOptFiletype, STATIC_CSTR_AS_OPTVAL("qf"), OPT_LOCAL);
set_option_value_give_err(kOptFiletype, STATIC_CSTR_AS_OBJ("qf"), OPT_LOCAL);
curbuf->b_p_ma = false;
curbuf->b_keep_filetype = true; // don't detect 'filetype'
@ -5376,7 +5376,7 @@ void ex_cfile(exarg_T *eap)
}
}
if (*eap->arg != NUL) {
set_option_direct(kOptErrorfile, CSTR_AS_OPTVAL(eap->arg), 0, 0);
set_option_direct(kOptErrorfile, CSTR_AS_OBJ(eap->arg), 0, 0);
}
char *enc = (*curbuf->b_p_menc != NUL) ? curbuf->b_p_menc : p_menc;
@ -7656,7 +7656,7 @@ void ex_helpgrep(exarg_T *eap)
// Darn, some plugin changed the value. If it's still empty it was
// changed and restored, need to restore in the complicated way.
if (*p_cpo == NUL) {
set_option_value_give_err(kOptCpoptions, CSTR_AS_OPTVAL(save_cpo), 0);
set_option_value_give_err(kOptCpoptions, CSTR_AS_OBJ(save_cpo), 0);
}
free_string_option(save_cpo);
}

View File

@ -1183,7 +1183,7 @@ static int add_pack_dir_to_rtp(char *fname, bool is_pack)
}
bool was_valid = runtime_search_path_valid;
set_option_value_give_err(kOptRuntimepath, STRING_OPTVAL(new_rtp), 0);
set_option_value_give_err(kOptRuntimepath, STRING_OBJ(new_rtp), 0);
assert(!runtime_search_path_valid);
// If this is the result of "packadd opt_pack", rebuilding runtime_search_pat

View File

@ -3220,13 +3220,13 @@ void ex_spelldump(exarg_T *eap)
if (no_spell_checking(curwin)) {
return;
}
OptVal spl = get_option_value(kOptSpelllang, OPT_LOCAL);
Object spl = get_option_value(kOptSpelllang, OPT_LOCAL);
// Create a new empty buffer in a new window.
do_cmdline_cmd("new");
// enable spelling locally in the new window
set_option_value_give_err(kOptSpell, BOOLEAN_OPTVAL(true), OPT_LOCAL);
set_option_value_give_err(kOptSpell, BOOLEAN_OBJ(true), OPT_LOCAL);
set_option_value_give_err(kOptSpelllang, spl, OPT_LOCAL);
optval_free(spl);

View File

@ -5686,7 +5686,7 @@ static void init_spellfile(void)
(fname != NULL && strstr(path_tail(fname), ".ascii.") != NULL) ? "ascii" : spell_enc();
vim_snprintf(buf + strlen(buf), buf_len - strlen(buf), ".%s.add", enc_suffix);
set_option_value_give_err(kOptSpellfile, CSTR_AS_OPTVAL(buf), OPT_LOCAL);
set_option_value_give_err(kOptSpellfile, CSTR_AS_OBJ(buf), OPT_LOCAL);
xfree(buf);
}

View File

@ -239,9 +239,9 @@ const char *did_set_tagfunc(optset_T *args)
int retval;
if (args->os_flags & OPT_LOCAL) {
retval = option_set_callback_func(args->os_newval.string.data, &buf->b_tfu_cb);
retval = option_set_callback_func(args->os_newval.data.string.data, &buf->b_tfu_cb);
} else {
retval = option_set_callback_func(args->os_newval.string.data, &tfu_cb);
retval = option_set_callback_func(args->os_newval.data.string.data, &tfu_cb);
if (retval == OK && !(args->os_flags & OPT_GLOBAL)) {
set_buflocal_tfu_callback(buf);
}

View File

@ -600,7 +600,7 @@ void terminal_open(Terminal **termpp, buf_T *buf)
}
refresh_screen(term, buf);
buf->b_locked++;
set_option_value(kOptBuftype, STATIC_CSTR_AS_OPTVAL("terminal"), OPT_LOCAL);
set_option_value(kOptBuftype, STATIC_CSTR_AS_OBJ("terminal"), OPT_LOCAL);
buf->b_locked--;
if (buf->b_ffname != NULL) {

View File

@ -220,7 +220,7 @@ void ui_refresh(void)
// Reset 'cmdheight' for all tabpages when ext_messages toggles.
if (had_message != ui_ext[kUIMessages]) {
if (ui_refresh_cmdheight) {
set_option_value(kOptCmdheight, NUMBER_OPTVAL(had_message), 0);
set_option_value(kOptCmdheight, INTEGER_OBJ(had_message), 0);
FOR_ALL_TABS(tp) {
tp->tp_ch_used = had_message;
}

View File

@ -3791,7 +3791,7 @@ void frame_new_height(frame_T *topfrp, int height, bool topfirst, bool wfh, bool
OptInt new_ch = MAX(min_set_ch, p_ch + topfrp->fr_height - height);
if (new_ch != p_ch) {
const OptInt save_ch = min_set_ch;
set_option_value(kOptCmdheight, NUMBER_OPTVAL(new_ch), 0);
set_option_value(kOptCmdheight, INTEGER_OBJ(new_ch), 0);
min_set_ch = save_ch;
}
height = (int)MIN(ROWS_AVAIL, height);
@ -4777,7 +4777,7 @@ static void enter_tabpage(tabpage_T *tp, buf_T *old_curbuf, bool trigger_enter_a
OptInt new_ch = p_ch;
p_ch = prev_p_ch;
command_frame_height = false;
set_option_value(kOptCmdheight, NUMBER_OPTVAL(new_ch), 0);
set_option_value(kOptCmdheight, INTEGER_OBJ(new_ch), 0);
command_frame_height = true;
} else if (old_curtab != curtab) {
tabpage_check_windows(old_curtab);

View File

@ -476,7 +476,7 @@ win_T *win_float_special(bool enter, bool new_buf, WinKind kind)
return win_float_special_fail(wp, &err);
}
buf->b_p_bl = false; // unlist
set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OPTVAL("wipe"), OPT_LOCAL, 0,
set_option_direct_for(kOptBufhidden, STATIC_CSTR_AS_OBJ("wipe"), OPT_LOCAL, 0,
kOptScopeBuf, buf);
win_set_buf(wp, buf, &err);
if (ERROR_SET(&err)) {