mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
api: {get,set}_option should {get,set} global value of local options (#6405)
- nvim_get_option should return the global default of a local option. - nvim_set_option should set the global default of a local option.
This commit is contained in:
parent
66b336d89b
commit
eb0e94f71b
@ -289,7 +289,7 @@ void set_option_to(void *to, int type, String name, Object value, Error *err)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int opt_flags = (type ? OPT_LOCAL : OPT_GLOBAL);
|
int opt_flags = (type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
|
||||||
|
|
||||||
if (flags & SOPT_BOOL) {
|
if (flags & SOPT_BOOL) {
|
||||||
if (value.type != kObjectTypeBoolean) {
|
if (value.type != kObjectTypeBoolean) {
|
||||||
|
@ -440,7 +440,7 @@ Object nvim_get_vvar(String name, Error *err)
|
|||||||
///
|
///
|
||||||
/// @param name Option name
|
/// @param name Option name
|
||||||
/// @param[out] err Error details, if any
|
/// @param[out] err Error details, if any
|
||||||
/// @return Option value
|
/// @return Option value (global)
|
||||||
Object nvim_get_option(String name, Error *err)
|
Object nvim_get_option(String name, Error *err)
|
||||||
FUNC_API_SINCE(1)
|
FUNC_API_SINCE(1)
|
||||||
{
|
{
|
||||||
|
@ -4619,14 +4619,13 @@ int get_option_value_strict(char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char_u *varp = NULL;
|
char_u *varp = NULL;
|
||||||
vimoption_T *p;
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
int opt_idx = findoption(name);
|
int opt_idx = findoption(name);
|
||||||
if (opt_idx < 0) {
|
if (opt_idx < 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = &(options[opt_idx]);
|
vimoption_T *p = &options[opt_idx];
|
||||||
|
|
||||||
// Hidden option
|
// Hidden option
|
||||||
if (p->var == NULL) {
|
if (p->var == NULL) {
|
||||||
@ -4642,26 +4641,25 @@ int get_option_value_strict(char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (p->indir == PV_NONE) {
|
if (p->indir == PV_NONE) {
|
||||||
if (opt_type == SREQ_GLOBAL)
|
if (opt_type == SREQ_GLOBAL) {
|
||||||
rv |= SOPT_GLOBAL;
|
rv |= SOPT_GLOBAL;
|
||||||
else
|
} else {
|
||||||
return 0; // Did not request global-only option
|
return 0; // Did not request global-only option
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (p->indir & PV_BOTH) {
|
if (p->indir & PV_BOTH) {
|
||||||
rv |= SOPT_GLOBAL;
|
rv |= SOPT_GLOBAL;
|
||||||
} else if (opt_type == SREQ_GLOBAL) {
|
|
||||||
return 0; // Requested global option
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p->indir & PV_WIN) {
|
if (p->indir & PV_WIN) {
|
||||||
if (opt_type == SREQ_BUF) {
|
if (opt_type == SREQ_BUF) {
|
||||||
return 0; // Did not request window-local option
|
return 0; // Requested buffer-local, not window-local option
|
||||||
} else {
|
} else {
|
||||||
rv |= SOPT_WIN;
|
rv |= SOPT_WIN;
|
||||||
}
|
}
|
||||||
} else if (p->indir & PV_BUF) {
|
} else if (p->indir & PV_BUF) {
|
||||||
if (opt_type == SREQ_WIN) {
|
if (opt_type == SREQ_WIN) {
|
||||||
return 0; // Did not request buffer-local option
|
return 0; // Requested window-local, not buffer-local option
|
||||||
} else {
|
} else {
|
||||||
rv |= SOPT_BUF;
|
rv |= SOPT_BUF;
|
||||||
}
|
}
|
||||||
@ -4673,7 +4671,11 @@ int get_option_value_strict(char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (opt_type == SREQ_GLOBAL) {
|
if (opt_type == SREQ_GLOBAL) {
|
||||||
|
if (p->var == VAR_WIN) {
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
varp = p->var;
|
varp = p->var;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (opt_type == SREQ_BUF) {
|
if (opt_type == SREQ_BUF) {
|
||||||
// Special case: 'modified' is b_changed, but we also want to
|
// Special case: 'modified' is b_changed, but we also want to
|
||||||
@ -4720,7 +4722,7 @@ int get_option_value_strict(char *name,
|
|||||||
/// @param[in] name Option name.
|
/// @param[in] name Option name.
|
||||||
/// @param[in] number New value for the number or boolean option.
|
/// @param[in] number New value for the number or boolean option.
|
||||||
/// @param[in] string New value for string option.
|
/// @param[in] string New value for string option.
|
||||||
/// @param[in] opt_flags Flags: OPT_LOCAL or 0 (both).
|
/// @param[in] opt_flags Flags: OPT_LOCAL, OPT_GLOBAL, or 0 (both).
|
||||||
///
|
///
|
||||||
/// @return NULL on success, error message on error.
|
/// @return NULL on success, error message on error.
|
||||||
char *set_option_value(const char *const name, const long number,
|
char *set_option_value(const char *const name, const long number,
|
||||||
|
@ -16,9 +16,9 @@
|
|||||||
#define SOPT_UNSET 0x40 // Option does not have local value set
|
#define SOPT_UNSET 0x40 // Option does not have local value set
|
||||||
|
|
||||||
// Option types for various functions in option.c
|
// Option types for various functions in option.c
|
||||||
#define SREQ_GLOBAL 0 // Request global option
|
#define SREQ_GLOBAL 0 // Request global option value
|
||||||
#define SREQ_WIN 1 // Request window-local option
|
#define SREQ_WIN 1 // Request window-local option value
|
||||||
#define SREQ_BUF 2 // Request buffer-local option
|
#define SREQ_BUF 2 // Request buffer-local option value
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Default values for 'errorformat'.
|
* Default values for 'errorformat'.
|
||||||
|
@ -153,6 +153,28 @@ describe('api', function()
|
|||||||
nvim('set_option', 'equalalways', false)
|
nvim('set_option', 'equalalways', false)
|
||||||
ok(not nvim('get_option', 'equalalways'))
|
ok(not nvim('get_option', 'equalalways'))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('works to get global value of local options', function()
|
||||||
|
eq(false, nvim('get_option', 'lisp'))
|
||||||
|
eq(8, nvim('get_option', 'shiftwidth'))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('works to set global value of local options', function()
|
||||||
|
nvim('set_option', 'lisp', true)
|
||||||
|
eq(true, nvim('get_option', 'lisp'))
|
||||||
|
eq(false, helpers.curbuf('get_option', 'lisp'))
|
||||||
|
eq(nil, nvim('command_output', 'setglobal lisp?'):match('nolisp'))
|
||||||
|
eq('nolisp', nvim('command_output', 'setlocal lisp?'):match('nolisp'))
|
||||||
|
nvim('set_option', 'shiftwidth', 20)
|
||||||
|
eq('20', nvim('command_output', 'setglobal shiftwidth?'):match('%d+'))
|
||||||
|
eq('8', nvim('command_output', 'setlocal shiftwidth?'):match('%d+'))
|
||||||
|
end)
|
||||||
|
|
||||||
|
it('most window-local options have no global value', function()
|
||||||
|
local status, err = pcall(nvim, 'get_option', 'foldcolumn')
|
||||||
|
eq(false, status)
|
||||||
|
ok(err:match('Invalid option name') ~= nil)
|
||||||
|
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