diff options
author | Gregory Anders <greg@gpanders.com> | 2022-05-25 11:17:46 -0600 |
---|---|---|
committer | Gregory Anders <greg@gpanders.com> | 2022-06-20 09:16:21 -0600 |
commit | 87a68b6a3ab483c6b126fa8071066a112f9386a3 (patch) | |
tree | b472cb991e92731a0be588a101914942264cbff6 | |
parent | 58d028f64bb0ddc80b6201906880182d14ad9a3c (diff) | |
download | rneovim-87a68b6a3ab483c6b126fa8071066a112f9386a3.tar.gz rneovim-87a68b6a3ab483c6b126fa8071066a112f9386a3.tar.bz2 rneovim-87a68b6a3ab483c6b126fa8071066a112f9386a3.zip |
refactor: use nvim_{get,set}_option_value for vim.{b,w}o
`nvim_get_option_value` and `nvim_set_option_value` better handle
unsetting local options. For instance, this is currently not possible:
vim.bo.tagfunc = nil
This does not work because 'tagfunc' is marked as "local to buffer" and
does not have a fallback global option. However, using :setlocal *does*
work as expected
:setlocal tagfunc=
`nvim_set_option_value` behaves more like :set and :setlocal (by
design), so using these as the underlying API functions beneath vim.bo
and vim.wo makes those two tables act more like :setlocal. Note that
vim.o *already* uses `nvim_set_option_value` under the hood, so that
vim.o behaves like :set.
-rw-r--r-- | runtime/lua/vim/_meta.lua | 8 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 4 |
2 files changed, 6 insertions, 6 deletions
diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua index 59cf837a1d..715a7e5561 100644 --- a/runtime/lua/vim/_meta.lua +++ b/runtime/lua/vim/_meta.lua @@ -91,11 +91,11 @@ do -- buffer option accessor return new_buf_opt_accessor(k) end - return a.nvim_buf_get_option(bufnr or 0, k) + return a.nvim_get_option_value(k, { buf = bufnr or 0 }) end local function set(k, v) - return a.nvim_buf_set_option(bufnr or 0, k, v) + return a.nvim_set_option_value(k, v, { buf = bufnr or 0 }) end return make_meta_accessor(get, set, nil, function(k) @@ -121,11 +121,11 @@ do -- window option accessor if winnr == nil and type(k) == 'number' then return new_win_opt_accessor(k) end - return a.nvim_win_get_option(winnr or 0, k) + return a.nvim_get_option_value(k, { win = winnr or 0 }) end local function set(k, v) - return a.nvim_win_set_option(winnr or 0, k, v) + return a.nvim_set_option_value(k, v, { win = winnr or 0 }) end return make_meta_accessor(get, set, nil, function(k) diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 1af46b7c2f..44e65afc78 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -1396,7 +1396,7 @@ describe('lua stdlib', function() ]] eq('', funcs.luaeval "vim.bo.filetype") eq(true, funcs.luaeval "vim.bo[BUF].modifiable") - matches("Invalid option name: 'nosuchopt'$", + matches("unknown option 'nosuchopt'$", pcall_err(exec_lua, 'return vim.bo.nosuchopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.bo[0][0].autoread')) @@ -1415,7 +1415,7 @@ describe('lua stdlib', function() eq(0, funcs.luaeval "vim.wo.cole") eq(0, funcs.luaeval "vim.wo[0].cole") eq(0, funcs.luaeval "vim.wo[1001].cole") - matches("Invalid option name: 'notanopt'$", + matches("unknown option 'notanopt'$", pcall_err(exec_lua, 'return vim.wo.notanopt')) matches("Expected lua string$", pcall_err(exec_lua, 'return vim.wo[0][0].list')) |