mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 03:48:18 +00:00
feat(lua): allow passing handles to vim.b/w/t
vim.bo can target a specific buffer by indexing with a number, e.g: `vim.bo[2].filetype` can get/set the filetype for buffer 2. This change replicates that behaviour for the variable namespace.
This commit is contained in:
@@ -323,22 +323,25 @@ end
|
||||
do
|
||||
local validate = vim.validate
|
||||
|
||||
local function make_dict_accessor(scope)
|
||||
local function make_dict_accessor(scope, handle)
|
||||
validate {
|
||||
scope = {scope, 's'};
|
||||
}
|
||||
local mt = {}
|
||||
function mt:__newindex(k, v)
|
||||
return vim._setvar(scope, 0, k, v)
|
||||
return vim._setvar(scope, handle or 0, k, v)
|
||||
end
|
||||
function mt:__index(k)
|
||||
return vim._getvar(scope, 0, k)
|
||||
if handle == nil and type(k) == 'number' then
|
||||
return make_dict_accessor(scope, k)
|
||||
end
|
||||
return vim._getvar(scope, handle or 0, k)
|
||||
end
|
||||
return setmetatable({}, mt)
|
||||
end
|
||||
|
||||
vim.g = make_dict_accessor('g')
|
||||
vim.v = make_dict_accessor('v')
|
||||
vim.g = make_dict_accessor('g', false)
|
||||
vim.v = make_dict_accessor('v', false)
|
||||
vim.b = make_dict_accessor('b')
|
||||
vim.w = make_dict_accessor('w')
|
||||
vim.t = make_dict_accessor('t')
|
||||
|
Reference in New Issue
Block a user