mirror of
https://github.com/neovim/neovim
synced 2025-07-16 09:11:51 +00:00
feat(exrc): stop searching in parent directories by unsetting 'exrc'
Problem: No way for a user to limit 'exrc' search in parent directories (compare editorconfig.root). Solution: A configuration file can unset 'exrc', disabling the search for its parent directories.
This commit is contained in:
@ -930,25 +930,29 @@ do
|
||||
group = vim.api.nvim_create_augroup('nvim.find_exrc', {}),
|
||||
desc = 'Find exrc files in parent directories',
|
||||
callback = function()
|
||||
if vim.o.exrc then
|
||||
-- Start from parent directory, as exrc file in the current
|
||||
-- directory is already loaded in do_exrc_initalization().
|
||||
local files = vim.fs.find({ '.nvim.lua', '.nvimrc', '.exrc' }, {
|
||||
type = 'file',
|
||||
upward = true,
|
||||
limit = math.huge,
|
||||
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
|
||||
loadstring(trusted)()
|
||||
else
|
||||
vim.api.nvim_exec2(trusted, {})
|
||||
end
|
||||
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
|
||||
loadstring(trusted)()
|
||||
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,
|
||||
})
|
||||
|
Reference in New Issue
Block a user