mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user