aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2022-05-25 17:05:28 +0200
committerGitHub <noreply@github.com>2022-05-25 17:05:28 +0200
commit24352cba01395aeb1c29b651b6d06f472e0911d3 (patch)
tree7db56adbee1bfbde6b71cf367de5d42eb6acf127 /src/nvim/api/vim.c
parent802a23926d237139822dda0ab712de3e1a98e5f9 (diff)
parent6219331c4d333e5a76129746021f972c21a040db (diff)
downloadrneovim-24352cba01395aeb1c29b651b6d06f472e0911d3.tar.gz
rneovim-24352cba01395aeb1c29b651b6d06f472e0911d3.tar.bz2
rneovim-24352cba01395aeb1c29b651b6d06f472e0911d3.zip
Merge pull request #18528 from lewis6991/setwinopt
feat(api): add `win` and `buf` to `nvim_set_option_value`
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c39
1 files changed, 35 insertions, 4 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 15992a98be..8e216c2031 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -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.