mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
Merge pull request #18528 from lewis6991/setwinopt
feat(api): add `win` and `buf` to `nvim_set_option_value`
This commit is contained in:
@@ -775,11 +775,15 @@ end:
|
||||
/// |:set|: for global-local options, both the global and local value are set
|
||||
/// unless otherwise specified with {scope}.
|
||||
///
|
||||
/// Note the options {win} and {buf} cannot be used together.
|
||||
///
|
||||
/// @param name Option name
|
||||
/// @param value New option value
|
||||
/// @param opts Optional parameters
|
||||
/// - scope: One of 'global' or 'local'. Analogous to
|
||||
/// |:setglobal| and |:setlocal|, respectively.
|
||||
/// - win: |window-ID|. Used for setting window local option.
|
||||
/// - buf: Buffer number. Used for setting buffer local option.
|
||||
/// @param[out] err Error details, if any
|
||||
void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err)
|
||||
FUNC_API_SINCE(9)
|
||||
@@ -799,6 +803,36 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error
|
||||
return;
|
||||
}
|
||||
|
||||
int opt_type = SREQ_GLOBAL;
|
||||
void *to = NULL;
|
||||
|
||||
if (opts->win.type == kObjectTypeInteger) {
|
||||
opt_type = SREQ_WIN;
|
||||
to = find_window_by_handle((int)opts->win.data.integer, err);
|
||||
} else if (HAS_KEY(opts->win)) {
|
||||
api_set_error(err, kErrorTypeValidation, "invalid value for key: win");
|
||||
return;
|
||||
}
|
||||
|
||||
if (opts->buf.type == kObjectTypeInteger) {
|
||||
scope = OPT_LOCAL;
|
||||
opt_type = SREQ_BUF;
|
||||
to = find_buffer_by_handle((int)opts->buf.data.integer, err);
|
||||
} else if (HAS_KEY(opts->buf)) {
|
||||
api_set_error(err, kErrorTypeValidation, "invalid value for key: buf");
|
||||
return;
|
||||
}
|
||||
|
||||
if (HAS_KEY(opts->scope) && HAS_KEY(opts->buf)) {
|
||||
api_set_error(err, kErrorTypeValidation, "scope and buf cannot be used together");
|
||||
return;
|
||||
}
|
||||
|
||||
if (HAS_KEY(opts->win) && HAS_KEY(opts->buf)) {
|
||||
api_set_error(err, kErrorTypeValidation, "buf and win cannot be used together");
|
||||
return;
|
||||
}
|
||||
|
||||
long numval = 0;
|
||||
char *stringval = NULL;
|
||||
|
||||
@@ -820,10 +854,7 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error
|
||||
return;
|
||||
}
|
||||
|
||||
char *e = set_option_value(name.data, numval, stringval, scope);
|
||||
if (e) {
|
||||
api_set_error(err, kErrorTypeException, "%s", e);
|
||||
}
|
||||
set_option_value_for(name.data, numval, stringval, scope, opt_type, to, err);
|
||||
}
|
||||
|
||||
/// Gets the option information for all options.
|
||||
|
Reference in New Issue
Block a user