aboutsummaryrefslogtreecommitdiffstats
path: root/neovim/.config/nvim/lua/config/autocmds.lua
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2026-09-16 08:47:13 +0200
committerGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2026-09-16 08:47:13 +0200
commita5e8bbeb9d79d905a193e95a39acd29bc37e6c66 (patch)
tree5b42d54e6b91d454bcbac89f7aac42b0863a869d /neovim/.config/nvim/lua/config/autocmds.lua
parent6906a9d55928c6250ff106d041b73fdd1ac8aae6 (diff)
downloaddotfiles-a5e8bbeb9d79d905a193e95a39acd29bc37e6c66.tar.gz
dotfiles-a5e8bbeb9d79d905a193e95a39acd29bc37e6c66.tar.bz2
dotfiles-a5e8bbeb9d79d905a193e95a39acd29bc37e6c66.zip
Updated dotfiles
Diffstat (limited to 'neovim/.config/nvim/lua/config/autocmds.lua')
-rw-r--r--neovim/.config/nvim/lua/config/autocmds.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/neovim/.config/nvim/lua/config/autocmds.lua b/neovim/.config/nvim/lua/config/autocmds.lua
index 7bc4f6b..e9ebe04 100644
--- a/neovim/.config/nvim/lua/config/autocmds.lua
+++ b/neovim/.config/nvim/lua/config/autocmds.lua
@@ -13,6 +13,49 @@ vim.api.nvim_create_autocmd("BufWritePre", {
13 callback = strip_trailing_whitespace, 13 callback = strip_trailing_whitespace,
14}) 14})
15 15
16-- Project-local config: search upward from cwd for a .nvim.lua, the same
17-- nearest-ancestor pattern LSP root-dir detection uses, so it's found
18-- regardless of exactly which subdirectory Neovim's cwd is or how you got
19-- there (:cd, opening a file, session restore, ...) - unlike core 'exrc'
20-- (deliberately left off in options.lua), which only ever checks the
21-- literal cwd once at startup.
22local sourced_project_configs = {}
23
24local function source_project_config()
25 local found = vim.fs.find(".nvim.lua", {
26 upward = true,
27 path = vim.fn.getcwd(),
28 stop = vim.env.HOME,
29 })[1]
30 if not found or sourced_project_configs[found] then
31 return
32 end
33
34 -- vim.secure.read is the same trust mechanism 'exrc' itself uses: prompts
35 -- on first encounter, honors ~/.local/state/nvim/trust, :trust still
36 -- manages the allowlist unchanged. Returns nil (no prompt shown again)
37 -- for a file previously denied.
38 local content = vim.secure.read(found)
39 if not content then
40 return
41 end
42 sourced_project_configs[found] = true
43
44 local chunk, load_err = load(content, "@" .. found)
45 if not chunk then
46 vim.notify("Error loading " .. found .. ":\n" .. load_err, vim.log.levels.ERROR)
47 return
48 end
49 local ok, run_err = pcall(chunk)
50 if not ok then
51 vim.notify("Error running " .. found .. ":\n" .. run_err, vim.log.levels.ERROR)
52 end
53end
54
55vim.api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, {
56 callback = source_project_config,
57})
58
16-- Note: the colorscheme (with its "desert" fallback) is applied from 59-- Note: the colorscheme (with its "desert" fallback) is applied from
17-- lua/plugins/colorscheme.lua's own `config` function, not here — under 60-- lua/plugins/colorscheme.lua's own `config` function, not here — under
18-- lazy.nvim that's the natural place to react to "the plugin is now loaded". 61-- lazy.nvim that's the natural place to react to "the plugin is now loaded".