aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-09-02 04:38:50 +0200
committerJustin M. Keyes <justinkz@gmail.com>2019-09-01 19:38:50 -0700
commitfb19aeeb33f76cd3b2fec9f62a22e01c212fb076 (patch)
tree84d9f5fa59467b71c9a236469cb4c96912138c1c
parentb10d703213da5699a176c7791a51a322f248dbd2 (diff)
downloadrneovim-fb19aeeb33f76cd3b2fec9f62a22e01c212fb076.tar.gz
rneovim-fb19aeeb33f76cd3b2fec9f62a22e01c212fb076.tar.bz2
rneovim-fb19aeeb33f76cd3b2fec9f62a22e01c212fb076.zip
API: make nvim_win_set_option() set window-global, not buffer-local #9110
NB: the `!(flags & SOPT_GLOBAL)` exception is for 'statusline'. Because `:set statusline=...` sets the global value for _all_ windows, `:setlocal` is the best we can do there. This is a one-of-a-kind option that doesn't work like any other option.
-rw-r--r--src/nvim/api/private/helpers.c4
-rw-r--r--test/functional/api/window_spec.lua8
-rw-r--r--test/functional/eval/buf_functions_spec.lua4
3 files changed, 13 insertions, 3 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c
index 2e4874d7c6..26f388ae7e 100644
--- a/src/nvim/api/private/helpers.c
+++ b/src/nvim/api/private/helpers.c
@@ -394,7 +394,9 @@ void set_option_to(uint64_t channel_id, void *to, int type,
current_SID = channel_id == LUA_INTERNAL_CALL ? SID_LUA : SID_API_CLIENT;
current_channel_id = channel_id;
- const int opt_flags = (type == SREQ_GLOBAL) ? OPT_GLOBAL : OPT_LOCAL;
+ const int opt_flags = (type == SREQ_WIN && !(flags & SOPT_GLOBAL))
+ ? 0 : (type == SREQ_GLOBAL)
+ ? OPT_GLOBAL : OPT_LOCAL;
set_option_value_for(name.data, numval, stringval,
opt_flags, type, to, err);
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 9af1bdb93b..3bc53cfc83 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -212,10 +212,18 @@ describe('API/win', function()
it('works', function()
curwin('set_option', 'colorcolumn', '4,3')
eq('4,3', curwin('get_option', 'colorcolumn'))
+ command("set modified hidden")
+ command("enew") -- edit new buffer, window option is preserved
+ eq('4,3', curwin('get_option', 'colorcolumn'))
+
-- global-local option
curwin('set_option', 'statusline', 'window-status')
eq('window-status', curwin('get_option', 'statusline'))
eq('', nvim('get_option', 'statusline'))
+ command("set modified")
+ command("enew") -- global-local: not preserved in new buffer
+ eq({false, "Failed to get value for option 'statusline'"}, meth_pcall(curwin, 'get_option', 'statusline'))
+ eq('', eval('&l:statusline')) -- confirm local value was not copied
end)
end)
diff --git a/test/functional/eval/buf_functions_spec.lua b/test/functional/eval/buf_functions_spec.lua
index c0e264d4c9..380ccfb5d5 100644
--- a/test/functional/eval/buf_functions_spec.lua
+++ b/test/functional/eval/buf_functions_spec.lua
@@ -228,9 +228,9 @@ describe('getbufvar() function', function()
eq(0, funcs.getbufvar(1, '&g:number'))
command('new')
-- But with window-local options it probably does not what you expect
- curwinmeths.set_option('number', true)
+ command("setl number")
-- (note that current window’s buffer is 2, but getbufvar() receives 1)
- eq(2, bufmeths.get_number(curwinmeths.get_buf()))
+ eq({id=2}, curwinmeths.get_buf())
eq(1, funcs.getbufvar(1, '&number'))
eq(1, funcs.getbufvar(1, '&l:number'))
-- You can get global value though, if you find this useful.