mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Merge pull request #18528 from lewis6991/setwinopt
feat(api): add `win` and `buf` to `nvim_set_option_value`
This commit is contained in:
commit
24352cba01
@ -1674,12 +1674,18 @@ nvim_set_option_value({name}, {value}, {*opts})
|
|||||||
global and local value are set unless otherwise specified with
|
global and local value are set unless otherwise specified with
|
||||||
{scope}.
|
{scope}.
|
||||||
|
|
||||||
|
Note the options {win} and {buf} cannot be used together.
|
||||||
|
|
||||||
Parameters: ~
|
Parameters: ~
|
||||||
{name} Option name
|
{name} Option name
|
||||||
{value} New option value
|
{value} New option value
|
||||||
{opts} Optional parameters
|
{opts} Optional parameters
|
||||||
• scope: One of 'global' or 'local'. Analogous to
|
• scope: One of 'global' or 'local'. Analogous to
|
||||||
|:setglobal| and |:setlocal|, respectively.
|
|:setglobal| and |:setlocal|, respectively.
|
||||||
|
• win: |window-ID|. Used for setting window local
|
||||||
|
option.
|
||||||
|
• buf: Buffer number. Used for setting buffer
|
||||||
|
local option.
|
||||||
|
|
||||||
nvim_set_var({name}, {value}) *nvim_set_var()*
|
nvim_set_var({name}, {value}) *nvim_set_var()*
|
||||||
Sets a global (g:) variable.
|
Sets a global (g:) variable.
|
||||||
|
@ -85,6 +85,8 @@ return {
|
|||||||
};
|
};
|
||||||
option = {
|
option = {
|
||||||
"scope";
|
"scope";
|
||||||
|
"win";
|
||||||
|
"buf";
|
||||||
};
|
};
|
||||||
highlight = {
|
highlight = {
|
||||||
"bold";
|
"bold";
|
||||||
|
@ -1040,8 +1040,8 @@ Object copy_object(Object obj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_option_value_for(char *key, int numval, char *stringval, int opt_flags,
|
void set_option_value_for(char *key, long numval, char *stringval, int opt_flags,
|
||||||
int opt_type, void *from, Error *err)
|
int opt_type, void *from, Error *err)
|
||||||
{
|
{
|
||||||
switchwin_T switchwin;
|
switchwin_T switchwin;
|
||||||
aco_save_T aco;
|
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;
|
char *errmsg;
|
||||||
|
|
||||||
|
@ -775,11 +775,15 @@ end:
|
|||||||
/// |:set|: for global-local options, both the global and local value are set
|
/// |:set|: for global-local options, both the global and local value are set
|
||||||
/// unless otherwise specified with {scope}.
|
/// unless otherwise specified with {scope}.
|
||||||
///
|
///
|
||||||
|
/// Note the options {win} and {buf} cannot be used together.
|
||||||
|
///
|
||||||
/// @param name Option name
|
/// @param name Option name
|
||||||
/// @param value New option value
|
/// @param value New option value
|
||||||
/// @param opts Optional parameters
|
/// @param opts Optional parameters
|
||||||
/// - scope: One of 'global' or 'local'. Analogous to
|
/// - scope: One of 'global' or 'local'. Analogous to
|
||||||
/// |:setglobal| and |:setlocal|, respectively.
|
/// |: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
|
/// @param[out] err Error details, if any
|
||||||
void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err)
|
void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error *err)
|
||||||
FUNC_API_SINCE(9)
|
FUNC_API_SINCE(9)
|
||||||
@ -799,6 +803,36 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error
|
|||||||
return;
|
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;
|
long numval = 0;
|
||||||
char *stringval = NULL;
|
char *stringval = NULL;
|
||||||
|
|
||||||
@ -820,10 +854,7 @@ void nvim_set_option_value(String name, Object value, Dict(option) *opts, Error
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *e = set_option_value(name.data, numval, stringval, scope);
|
set_option_value_for(name.data, numval, stringval, scope, opt_type, to, err);
|
||||||
if (e) {
|
|
||||||
api_set_error(err, kErrorTypeException, "%s", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the option information for all options.
|
/// Gets the option information for all options.
|
||||||
|
@ -1439,6 +1439,24 @@ describe('API', function()
|
|||||||
nvim('set_option_value', 'autoread', NIL, {scope = 'local'})
|
nvim('set_option_value', 'autoread', NIL, {scope = 'local'})
|
||||||
eq(NIL, nvim('get_option_value', 'autoread', {scope = 'local'}))
|
eq(NIL, nvim('get_option_value', 'autoread', {scope = 'local'}))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('set window options', function()
|
||||||
|
-- Same as to nvim_win_set_option
|
||||||
|
nvim('set_option_value', 'colorcolumn', '4,3', {win=0})
|
||||||
|
eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'}))
|
||||||
|
command("set modified hidden")
|
||||||
|
command("enew") -- edit new buffer, window option is preserved
|
||||||
|
eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'}))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('set local window options', function()
|
||||||
|
-- Different to nvim_win_set_option
|
||||||
|
nvim('set_option_value', 'colorcolumn', '4,3', {win=0, scope='local'})
|
||||||
|
eq('4,3', nvim('get_option_value', 'colorcolumn', {scope = 'local'}))
|
||||||
|
command("set modified hidden")
|
||||||
|
command("enew") -- edit new buffer, window option is reset
|
||||||
|
eq('', nvim('get_option_value', 'colorcolumn', {scope = 'local'}))
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('nvim_{get,set}_current_buf, nvim_list_bufs', function()
|
describe('nvim_{get,set}_current_buf, nvim_list_bufs', function()
|
||||||
|
Loading…
Reference in New Issue
Block a user