Skip to content

Commit

Permalink
refactor(options)!: unify set_option and set_string_option
Browse files Browse the repository at this point in the history
While the interfaces for setting number and boolean options are now unified by #25394, there is still a separate `set_string_option` function that is used for setting a string option. This PR removes that function and merges it with set_option.

BREAKING CHANGE: `v:option_old` is now the old global value for all global-local options, instead of just string global-local options. Local value for a global-local number/boolean option is now unset when the option is set (e.g. using `:set` or `nvim_set_option_value`) without a scope, which means they now behave the same way as string options.

Ref: #25672
  • Loading branch information
famiu committed Oct 30, 2023
1 parent 8405649 commit e19cc9c
Show file tree
Hide file tree
Showing 10 changed files with 438 additions and 631 deletions.
9 changes: 4 additions & 5 deletions runtime/doc/autocmd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,10 @@ OptionSet After setting an option (except during
This does not set |<abuf>|, you could use
|bufnr()|.

Note that when setting a |global-local| string
option with |:set|, then |v:option_old| is the
old global value. However, for all other kinds
of options (local string options, global-local
number options, ...) it is the old local
Note that when setting a |global-local| option
with |:set|, then |v:option_old| is the old
global value. However, for all options that
are not global-local it is the old local
value.

OptionSet is not triggered on startup and for
Expand Down
7 changes: 6 additions & 1 deletion runtime/doc/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ The following changes may require adaptations in user config or plugins.

|OptionSet| autocommand args |v:option_new|, |v:option_old|,
|v:option_oldlocal|, |v:option_oldglobal| now have the type of the option
instead of always being strings.
instead of always being strings. |v:option_old| is now the old global value
for all global-local options, instead of just string global-local options.

• Local value for a global-local number/boolean option is now unset when
the option is set (e.g. using |:set| or |nvim_set_option_value()|) without a
scope, which means they now behave the same way as string options.

==============================================================================
NEW FEATURES *news-features*
Expand Down
7 changes: 6 additions & 1 deletion runtime/doc/vim_diff.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ Normal commands:
|Q| replays the last recorded macro instead of switching to Ex mode (|gQ|).

Options:
Local values for global-local number/boolean options are unset when the
option is set without a scope (e.g. by using |:set|), similarly to how
global-local string options work.

'autoread' works in the terminal (if it supports "focus" events)
'cpoptions' flags: |cpo-_|
'diffopt' "linematch" feature
Expand Down Expand Up @@ -381,7 +385,8 @@ Variables:
|v:windowid| is always available (for use by external UIs)
|OptionSet| autocommand args |v:option_new|, |v:option_old|,
|v:option_oldlocal|, |v:option_oldglobal| have the type of the option
instead of always being strings.
instead of always being strings. |v:option_old| is now the old global value
for all global-local options, instead of just string global-local options.

Vimscript:
|:redir| nested in |execute()| works.
Expand Down
15 changes: 0 additions & 15 deletions src/nvim/api/deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,21 +681,6 @@ static void set_option_to(uint64_t channel_id, void *to, OptReqScope req_scope,
return;
});

if (value.type == kObjectTypeNil) {
if (req_scope == kOptReqGlobal) {
api_set_error(err, kErrorTypeException, "Cannot unset option '%s'", name.data);
return;
} else if (!(flags & SOPT_GLOBAL)) {
api_set_error(err, kErrorTypeException,
"Cannot unset option '%s' because it doesn't have a global value",
name.data);
return;
} else {
unset_global_local_option(name.data, to);
return;
}
}

bool error = false;
OptVal optval = object_as_optval(value, &error);

Expand Down
5 changes: 2 additions & 3 deletions src/nvim/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -7229,12 +7229,11 @@ void set_vim_var_dict(const VimVarIndex idx, dict_T *const val)
/// Set v:variable to tv.
///
/// @param[in] idx Index of variable to set.
/// @param[in,out] val Value to set to. Reference count will be incremented.
/// Also keys of the dictionary will be made read-only.
/// @param[in] val Value to set to. Will be copied.
void set_vim_var_tv(const VimVarIndex idx, typval_T *const tv)
{
tv_clear(&vimvars[idx].vv_di.di_tv);
vimvars[idx].vv_di.di_tv = *tv;
tv_copy(tv, &vimvars[idx].vv_di.di_tv);
}

/// Set the v:argv list.
Expand Down

0 comments on commit e19cc9c

Please sign in to comment.