diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/api/keysets.lua | 2 | ||||
-rw-r--r-- | src/nvim/api/private/helpers.c | 6 | ||||
-rw-r--r-- | src/nvim/api/vim.c | 39 |
3 files changed, 40 insertions, 7 deletions
diff --git a/src/nvim/api/keysets.lua b/src/nvim/api/keysets.lua index 6924e2ef8f..d4882abffe 100644 --- a/src/nvim/api/keysets.lua +++ b/src/nvim/api/keysets.lua @@ -85,6 +85,8 @@ return { }; option = { "scope"; + "win"; + "buf"; }; highlight = { "bold"; diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index adabb1471e..c251a4a25c 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -1040,8 +1040,8 @@ Object copy_object(Object obj) } } -static void set_option_value_for(char *key, int numval, char *stringval, int opt_flags, - int opt_type, void *from, Error *err) +void set_option_value_for(char *key, long numval, char *stringval, int opt_flags, + int opt_type, void *from, Error *err) { switchwin_T switchwin; aco_save_T aco; @@ -1081,7 +1081,7 @@ static void set_option_value_for(char *key, int numval, char *stringval, int opt } -static void set_option_value_err(char *key, int numval, char *stringval, int opt_flags, Error *err) +static void set_option_value_err(char *key, long numval, char *stringval, int opt_flags, Error *err) { char *errmsg; 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. |