diff options
Diffstat (limited to 'neovim/.config/nvim/lua/config/autocmds.lua')
| -rw-r--r-- | neovim/.config/nvim/lua/config/autocmds.lua | 43 |
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. | ||
| 22 | local sourced_project_configs = {} | ||
| 23 | |||
| 24 | local 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 | ||
| 53 | end | ||
| 54 | |||
| 55 | vim.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". |
