mirror of
https://github.com/neovim/neovim.git
synced 2026-11-02 09:49:02 -06:00
fix(exrc): ensure consistent 'exrc' loading sequence #35148
Problem: The execution of startup scripts in parent directories are too late compared to scripts in current direcctory. Solution: Execute all startup scripts with `lua/_core/exrc.lua`. closes: #35147
This commit is contained in:
1 parent
2f9f77cd72
commit
ed9abb1851
3 files changed
+28
-60
No files matched your search
@@ -0,0 +1,19 @@
|
|||||||
|
local files = vim.fs.find({ '.nvim.lua', '.nvimrc', '.exrc' }, {
|
||||||
|
type = 'file',
|
||||||
|
upward = true,
|
||||||
|
limit = math.huge,
|
||||||
|
})
|
||||||
|
for _, file in ipairs(files) do
|
||||||
|
local trusted = vim.secure.read(file) --[[@as string|nil]]
|
||||||
|
if trusted then
|
||||||
|
if vim.endswith(file, '.lua') then
|
||||||
|
assert(loadstring(trusted, '@' .. file))()
|
||||||
|
else
|
||||||
|
vim.api.nvim_exec2(trusted, {})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- If the user unset 'exrc' in the current exrc then stop searching
|
||||||
|
if not vim.o.exrc then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -952,37 +952,6 @@ do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd('VimEnter', {
|
|
||||||
group = vim.api.nvim_create_augroup('nvim.exrc', {}),
|
|
||||||
desc = 'Find exrc files in parent directories',
|
|
||||||
callback = function()
|
|
||||||
if not vim.o.exrc then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
local files = vim.fs.find({ '.nvim.lua', '.nvimrc', '.exrc' }, {
|
|
||||||
type = 'file',
|
|
||||||
upward = true,
|
|
||||||
limit = math.huge,
|
|
||||||
-- exrc in cwd already handled from C, thus start in parent directory.
|
|
||||||
path = vim.fs.dirname((vim.uv.cwd())),
|
|
||||||
})
|
|
||||||
for _, file in ipairs(files) do
|
|
||||||
local trusted = vim.secure.read(file) --[[@as string|nil]]
|
|
||||||
if trusted then
|
|
||||||
if vim.endswith(file, '.lua') then
|
|
||||||
assert(loadstring(trusted, '@' .. file))()
|
|
||||||
else
|
|
||||||
vim.api.nvim_exec2(trusted, {})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- If the user unset 'exrc' in the current exrc then stop searching
|
|
||||||
if not vim.o.exrc then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
if tty then
|
if tty then
|
||||||
-- Show progress bars in supporting terminals
|
-- Show progress bars in supporting terminals
|
||||||
vim.api.nvim_create_autocmd('Progress', {
|
vim.api.nvim_create_autocmd('Progress', {
|
||||||
|
|||||||
+9
-29
@@ -2101,38 +2101,18 @@ static bool do_user_initialization(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read initialization commands from ".nvim.lua", ".nvimrc", or ".exrc" in
|
// Read initialization commands from ".nvim.lua", ".nvimrc", or ".exrc" in
|
||||||
// current directory. This is only done if the 'exrc' option is set.
|
// current directory and all parent directories. This is only done if the 'exrc'
|
||||||
// Only do this if VIMRC_FILE is not the same as vimrc file sourced in
|
// option is set. Only do this if VIMRC_FILE is not the same as vimrc file
|
||||||
// do_user_initialization.
|
// sourced in do_user_initialization.
|
||||||
static void do_exrc_initialization(void)
|
static void do_exrc_initialization(void)
|
||||||
{
|
{
|
||||||
char *str;
|
lua_State *const L = get_global_lstate();
|
||||||
|
assert(L);
|
||||||
|
|
||||||
if (os_path_exists(VIMRC_LUA_FILE)) {
|
lua_getglobal(L, "require");
|
||||||
str = nlua_read_secure(VIMRC_LUA_FILE);
|
lua_pushstring(L, "vim._core.exrc");
|
||||||
if (str != NULL) {
|
if (nlua_pcall(L, 1, 0)) {
|
||||||
Error err = ERROR_INIT;
|
fprintf(stderr, "%s\n", lua_tostring(L, -1));
|
||||||
nlua_exec(cstr_as_string(str), "@"VIMRC_LUA_FILE, (Array)ARRAY_DICT_INIT, kRetNilBool, NULL,
|
|
||||||
&err);
|
|
||||||
xfree(str);
|
|
||||||
if (ERROR_SET(&err)) {
|
|
||||||
semsg("Error in %s:", VIMRC_LUA_FILE);
|
|
||||||
semsg_multiline("emsg", err.msg);
|
|
||||||
api_clear_error(&err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (os_path_exists(VIMRC_FILE)) {
|
|
||||||
str = nlua_read_secure(VIMRC_FILE);
|
|
||||||
if (str != NULL) {
|
|
||||||
do_source_str(str, VIMRC_FILE);
|
|
||||||
xfree(str);
|
|
||||||
}
|
|
||||||
} else if (os_path_exists(EXRC_FILE)) {
|
|
||||||
str = nlua_read_secure(EXRC_FILE);
|
|
||||||
if (str != NULL) {
|
|
||||||
do_source_str(str, EXRC_FILE);
|
|
||||||
xfree(str);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user