aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-11-26 21:08:16 +0100
committerGitHub <noreply@github.com>2019-11-26 21:08:16 +0100
commita40ae96a38f0e99947421f81511ad2f7c2d3fc2c (patch)
treefc9f79c5396894110fccd1606286a8613f914bc9
parentf53822d89f727fc16a9b5578d4f5c82015f4d7aa (diff)
parenta76a669ac24ec91144153b65e0a0dc5598802653 (diff)
downloadrneovim-a40ae96a38f0e99947421f81511ad2f7c2d3fc2c.tar.gz
rneovim-a40ae96a38f0e99947421f81511ad2f7c2d3fc2c.tar.bz2
rneovim-a40ae96a38f0e99947421f81511ad2f7c2d3fc2c.zip
Merge pull request #11466 from bfredl/luaopt
lua: make vim.wo and vim.bo used nested indexing for specified handle
-rw-r--r--src/nvim/lua/vim.lua32
-rw-r--r--test/functional/lua/vim_spec.lua16
2 files changed, 29 insertions, 19 deletions
diff --git a/src/nvim/lua/vim.lua b/src/nvim/lua/vim.lua
index 8019511317..e13b44a8ed 100644
--- a/src/nvim/lua/vim.lua
+++ b/src/nvim/lua/vim.lua
@@ -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
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index ebe394f164..720a33d430 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -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)