From f7c939fa7af9744bcb6d79100a7e126f7e9c8f5c Mon Sep 17 00:00:00 2001 From: Yochem van Rosmalen Date: Sun, 29 Jun 2025 17:19:10 +0200 Subject: [PATCH] fix(exrc): exrc knows its own location (#34638) fix(exrc): lua exrc files know their location Problem: 'exrc' files are inherently bound to their location / workspace and therefore require to "know" their location on the filesystem. However, currently using `debug.getinfo(1, 'S')` returns `""`. Solution: Include the filepath as chunkname in `loadstring()` and `nlua_exec()`. --- runtime/doc/options.txt | 2 ++ runtime/doc/vimfn.txt | 3 ++- runtime/lua/vim/_defaults.lua | 2 +- runtime/lua/vim/_meta/options.lua | 2 ++ runtime/lua/vim/_meta/vimfn.lua | 3 ++- src/nvim/api/deprecated.c | 2 +- src/nvim/api/vim.c | 2 +- src/nvim/eval.lua | 3 ++- src/nvim/lua/executor.c | 7 +++++-- src/nvim/lua/executor.h | 2 +- src/nvim/main.c | 5 +++-- src/nvim/options.lua | 2 ++ 12 files changed, 24 insertions(+), 11 deletions(-) diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 5281c03282..89bd974476 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -2527,6 +2527,8 @@ A jump table for the options with a short description can be found at |Q_op|. Unset 'exrc' to stop further searching of 'exrc' files in parent directories, similar to |editorconfig.root|. + To get its own location, Lua exrc files can use |debug.getinfo()|. + Compare 'exrc' to |editorconfig|: - 'exrc' can execute any code; editorconfig only specifies settings. - 'exrc' is Nvim-specific; editorconfig works in other editors. diff --git a/runtime/doc/vimfn.txt b/runtime/doc/vimfn.txt index 3643fb6fcc..87fb95063e 100644 --- a/runtime/doc/vimfn.txt +++ b/runtime/doc/vimfn.txt @@ -2114,7 +2114,8 @@ expand({string} [, {nosuf} [, {list}]]) *expand()* "123_" where "123" is the current script ID ||