mirror of
https://github.com/neovim/neovim.git
synced 2025-09-29 14:38:32 +00:00
lua: make vim.wo and vim.bo used nested indexing for specified handle
Also missing option should be an error. Options are functionality, not arbitrary variable names (as for vim.g)
This commit is contained in:
@@ -314,7 +314,7 @@ do
|
||||
end
|
||||
vim.g = make_meta_accessor(nil_wrap(a.nvim_get_var), a.nvim_set_var, a.nvim_del_var)
|
||||
vim.v = make_meta_accessor(nil_wrap(a.nvim_get_vvar), a.nvim_set_vvar)
|
||||
vim.o = make_meta_accessor(nil_wrap(a.nvim_get_option), a.nvim_set_option)
|
||||
vim.o = make_meta_accessor(a.nvim_get_option, a.nvim_set_option)
|
||||
vim.env = make_meta_accessor(vim.fn.getenv, vim.fn.setenv)
|
||||
-- TODO(ashkan) if/when these are available from an API, generate them
|
||||
-- instead of hardcoding.
|
||||
@@ -344,29 +344,31 @@ do
|
||||
if window_options[k] then
|
||||
return a.nvim_err_writeln(k.." is a window option, not a buffer option")
|
||||
end
|
||||
return a.nvim_buf_get_option(bufnr, k)
|
||||
if bufnr == nil and type(k) == "number" then
|
||||
return new_buf_opt_accessor(k)
|
||||
end
|
||||
return a.nvim_buf_get_option(bufnr or 0, k)
|
||||
end
|
||||
local function set(k, v)
|
||||
if window_options[k] then
|
||||
return a.nvim_err_writeln(k.." is a window option, not a buffer option")
|
||||
end
|
||||
return a.nvim_buf_set_option(bufnr, k, v)
|
||||
return a.nvim_buf_set_option(bufnr or 0, k, v)
|
||||
end
|
||||
return make_meta_accessor(nil_wrap(get), set)
|
||||
end
|
||||
vim.bo = new_buf_opt_accessor(0)
|
||||
getmetatable(vim.bo).__call = function(_, bufnr)
|
||||
return new_buf_opt_accessor(bufnr)
|
||||
return make_meta_accessor(get, set)
|
||||
end
|
||||
vim.bo = new_buf_opt_accessor(nil)
|
||||
local function new_win_opt_accessor(winnr)
|
||||
local function get(k) return a.nvim_win_get_option(winnr, k) end
|
||||
local function set(k, v) return a.nvim_win_set_option(winnr, k, v) end
|
||||
return make_meta_accessor(nil_wrap(get), set)
|
||||
end
|
||||
vim.wo = new_win_opt_accessor(0)
|
||||
getmetatable(vim.wo).__call = function(_, winnr)
|
||||
return new_win_opt_accessor(winnr)
|
||||
local function get(k)
|
||||
if winnr == nil and type(k) == "number" then
|
||||
return new_win_opt_accessor(k)
|
||||
end
|
||||
return a.nvim_win_get_option(winnr or nil, k)
|
||||
end
|
||||
local function set(k, v) return a.nvim_win_set_option(winnr or nil, k, v) end
|
||||
return make_meta_accessor(get, set)
|
||||
end
|
||||
vim.wo = new_win_opt_accessor(nil)
|
||||
end
|
||||
|
||||
return module
|
||||
|
@@ -587,13 +587,17 @@ describe('lua stdlib', function()
|
||||
]]
|
||||
eq(false, funcs.luaeval "vim.bo.modified")
|
||||
eq('markdown', funcs.luaeval "vim.bo.filetype")
|
||||
eq(false, funcs.luaeval "vim.bo(BUF).modifiable")
|
||||
eq(false, funcs.luaeval "vim.bo[BUF].modifiable")
|
||||
exec_lua [[
|
||||
vim.bo.filetype = ''
|
||||
vim.bo(BUF).modifiable = true
|
||||
vim.bo[BUF].modifiable = true
|
||||
]]
|
||||
eq('', funcs.luaeval "vim.bo.filetype")
|
||||
eq(true, funcs.luaeval "vim.bo(BUF).modifiable")
|
||||
eq(true, funcs.luaeval "vim.bo[BUF].modifiable")
|
||||
matches("^Error executing lua: .*: Invalid option name: 'nosuchopt'$",
|
||||
pcall_err(exec_lua, 'return vim.bo.nosuchopt'))
|
||||
matches("^Error executing lua: .*: Expected lua string$",
|
||||
pcall_err(exec_lua, 'return vim.bo[0][0].autoread'))
|
||||
end)
|
||||
|
||||
it('vim.wo', function()
|
||||
@@ -606,8 +610,12 @@ describe('lua stdlib', function()
|
||||
eq(2, funcs.luaeval "vim.wo.cole")
|
||||
exec_lua [[
|
||||
vim.wo.conceallevel = 0
|
||||
vim.bo(BUF).modifiable = true
|
||||
vim.bo[BUF].modifiable = true
|
||||
]]
|
||||
eq(0, funcs.luaeval "vim.wo.cole")
|
||||
matches("^Error executing lua: .*: Invalid option name: 'notanopt'$",
|
||||
pcall_err(exec_lua, 'return vim.wo.notanopt'))
|
||||
matches("^Error executing lua: .*: Expected lua string$",
|
||||
pcall_err(exec_lua, 'return vim.wo[0][0].list'))
|
||||
end)
|
||||
end)
|
||||
|
Reference in New Issue
Block a user