Merge pull request #25202 from zeertzjq/backport

Backport to release-0.9
This commit is contained in:
zeertzjq 2023-09-17 07:12:42 +08:00 committed by GitHub
commit 7fd12dabcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 9 deletions

View File

@ -968,6 +968,6 @@ function vim._init_defaults()
vim._init_default_autocmds()
end
require('vim._meta')
require('vim._options')
return vim

View File

@ -526,7 +526,10 @@ local function create_option_accessor(scope)
return setmetatable({}, {
__index = function(_, k)
return make_option(k, api.nvim_get_option_value(k, {}))
-- vim.opt_global must get global value only
-- vim.opt_local may fall back to global value like vim.opt
local opts = { scope = scope == 'global' and 'global' or nil }
return make_option(k, api.nvim_get_option_value(k, opts))
end,
__newindex = function(_, k, v)

View File

@ -271,7 +271,7 @@ set(LUA_LOADER_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/loader.lua)
set(LUA_INSPECT_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/inspect.lua)
set(LUA_FS_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/fs.lua)
set(LUA_F_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/F.lua)
set(LUA_META_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_meta.lua)
set(LUA_OPTIONS_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_options.lua)
set(LUA_FILETYPE_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/filetype.lua)
set(LUA_INIT_PACKAGES_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/_init_packages.lua)
set(LUA_KEYMAP_MODULE_SOURCE ${PROJECT_SOURCE_DIR}/runtime/lua/vim/keymap.lua)
@ -511,7 +511,7 @@ add_custom_command(
${LUA_SHARED_MODULE_SOURCE} "vim.shared"
${LUA_LOADER_MODULE_SOURCE} "vim.loader"
${LUA_F_MODULE_SOURCE} "vim.F"
${LUA_META_MODULE_SOURCE} "vim._meta"
${LUA_OPTIONS_MODULE_SOURCE} "vim._options"
${LUA_FILETYPE_MODULE_SOURCE} "vim.filetype"
${LUA_KEYMAP_MODULE_SOURCE} "vim.keymap"
DEPENDS
@ -522,7 +522,7 @@ add_custom_command(
${LUA_LOADER_MODULE_SOURCE}
${LUA_INSPECT_MODULE_SOURCE}
${LUA_F_MODULE_SOURCE}
${LUA_META_MODULE_SOURCE}
${LUA_OPTIONS_MODULE_SOURCE}
${LUA_FILETYPE_MODULE_SOURCE}
${LUA_LOAD_PACKAGE_MODULE_SOURCE}
${LUA_KEYMAP_MODULE_SOURCE}

View File

@ -2026,9 +2026,9 @@ void nlua_set_sctx(sctx_T *current)
lua_Debug *info = (lua_Debug *)xmalloc(sizeof(lua_Debug));
// Files where internal wrappers are defined so we can ignore them
// like vim.o/opt etc are defined in _meta.lua
// like vim.o/opt etc are defined in _options.lua
char *ignorelist[] = {
"vim/_meta.lua",
"vim/_options.lua",
"vim/keymap.lua",
};
int ignorelist_size = sizeof(ignorelist) / sizeof(ignorelist[0]);

View File

@ -2222,8 +2222,8 @@ describe('lua stdlib', function()
end)
end) -- vim.opt
describe('opt_local', function()
it('should be able to append to an array list type option', function()
describe('vim.opt_local', function()
it('appends into global value when changing local option value', function()
eq({ "foo,bar,baz,qux" }, exec_lua [[
local result = {}
@ -2238,6 +2238,19 @@ describe('lua stdlib', function()
end)
end)
describe('vim.opt_global', function()
it('gets current global option value', function()
eq({ "yes" }, exec_lua [[
local result = {}
vim.cmd "setglobal signcolumn=yes"
table.insert(result, vim.opt_global.signcolumn:get())
return result
]])
end)
end)
it('vim.cmd', function()
exec_lua [[
vim.cmd "autocmd BufNew * ++once lua BUF = vim.fn.expand('<abuf>')"