From a5e8bbeb9d79d905a193e95a39acd29bc37e6c66 Mon Sep 17 00:00:00 2001 From: Tom van der Lee Date: Wed, 16 Sep 2026 08:47:13 +0200 Subject: Updated dotfiles --- neovim/.config/nvim/lua/config/autocmds.lua | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'neovim/.config/nvim/lua/config/autocmds.lua') 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", { callback = strip_trailing_whitespace, }) +-- Project-local config: search upward from cwd for a .nvim.lua, the same +-- nearest-ancestor pattern LSP root-dir detection uses, so it's found +-- regardless of exactly which subdirectory Neovim's cwd is or how you got +-- there (:cd, opening a file, session restore, ...) - unlike core 'exrc' +-- (deliberately left off in options.lua), which only ever checks the +-- literal cwd once at startup. +local sourced_project_configs = {} + +local function source_project_config() + local found = vim.fs.find(".nvim.lua", { + upward = true, + path = vim.fn.getcwd(), + stop = vim.env.HOME, + })[1] + if not found or sourced_project_configs[found] then + return + end + + -- vim.secure.read is the same trust mechanism 'exrc' itself uses: prompts + -- on first encounter, honors ~/.local/state/nvim/trust, :trust still + -- manages the allowlist unchanged. Returns nil (no prompt shown again) + -- for a file previously denied. + local content = vim.secure.read(found) + if not content then + return + end + sourced_project_configs[found] = true + + local chunk, load_err = load(content, "@" .. found) + if not chunk then + vim.notify("Error loading " .. found .. ":\n" .. load_err, vim.log.levels.ERROR) + return + end + local ok, run_err = pcall(chunk) + if not ok then + vim.notify("Error running " .. found .. ":\n" .. run_err, vim.log.levels.ERROR) + end +end + +vim.api.nvim_create_autocmd({ "VimEnter", "DirChanged" }, { + callback = source_project_config, +}) + -- Note: the colorscheme (with its "desert" fallback) is applied from -- lua/plugins/colorscheme.lua's own `config` function, not here — under -- lazy.nvim that's the natural place to react to "the plugin is now loaded". -- cgit v1.3