summaryrefslogtreecommitdiffstatshomepage
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorYochem van Rosmalen <git@yochem.nl>2025-05-19 16:18:03 +0200
committerYochem van Rosmalen <git@yochem.nl>2025-05-20 00:03:14 +0200
commit8d397fa458a9f89c8e48fcaa281d2efcd0ef8e69 (patch)
treeec7ea8d87c90845506e0fe9c5a7975a54f711034 /runtime/lua/vim
parentdc6fc11b8753111a80f537dc762152d9adad2518 (diff)
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.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/_defaults.lua38
-rw-r--r--runtime/lua/vim/_meta/options.lua3
2 files changed, 24 insertions, 17 deletions
diff --git a/runtime/lua/vim/_defaults.lua b/runtime/lua/vim/_defaults.lua
index 9ae2412350..52fdfd0aef 100644
--- a/runtime/lua/vim/_defaults.lua
+++ b/runtime/lua/vim/_defaults.lua
@@ -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,
})
diff --git a/runtime/lua/vim/_meta/options.lua b/runtime/lua/vim/_meta/options.lua
index b77b135f92..90118cb4a1 100644
--- a/runtime/lua/vim/_meta/options.lua
+++ b/runtime/lua/vim/_meta/options.lua
@@ -2080,6 +2080,9 @@ vim.bo.et = vim.bo.expandtab
--- directories (ordered upwards), if the files are in the `trust` list.
--- Use `:trust` to manage trusted files. See also `vim.secure.read()`.
---
+--- Unset 'exrc' to stop further searching of 'exrc' files in parent
+--- directories, similar to `editorconfig.root`.
+---
--- Compare 'exrc' to `editorconfig`:
--- - 'exrc' can execute any code; editorconfig only specifies settings.
--- - 'exrc' is Nvim-specific; editorconfig works in other editors.