commit 2a28149efc705ca5f2e53a8f3ed08912afa885eb
parent 96a514ed464d5583bebd2d3631cbcb8cd71b45e3
Author: Jan Edmund Lazo <jan.lazo@mail.utoronto.ca>
Date: Mon, 20 Oct 2025 21:20:08 -0400
vim-patch:9.1.0359: MS-Windows: relative import in a script sourced from a buffer doesn't work
Problem: MS-Windows: Relative import in a script sourced from a buffer
doesn't work (Ernie Rael)
Solution: Set a filename, so that we are not trying to use
script-relative filename (Yegappan Lakshmanan)
When a script is sourced from a buffer, the file name is set to ":source
buffer=". In MS-Windows, the ":" is a path separator character (used
after a drive letter). This results in the code trying to use the ":"
prefix to import the script on MS-Windows. To fix this, when importing a
script from a script sourced from a buffer with nofile, don't use
a script relative path name.
fixes vim/vim#14588
closes: vim/vim#14603
https://github.com/vim/vim/commit/f135fa28e481b2eba73baf52b08d24add5c4fe8b
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat:
2 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c
@@ -1993,14 +1993,19 @@ static char *do_source_buffer_init(source_cookie_T *sp, const exarg_T *eap, bool
return NULL;
}
- if (ex_lua) {
- // Use ":{range}lua buffer=<num>" as the script name
- snprintf(IObuff, IOSIZE, ":{range}lua buffer=%d", curbuf->b_fnum);
+ char *fname;
+ if (curbuf->b_ffname != NULL) {
+ fname = xstrdup(curbuf->b_ffname);
} else {
- // Use ":source buffer=<num>" as the script name
- snprintf(IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum);
+ if (ex_lua) {
+ // Use ":{range}lua buffer=<num>" as the script name
+ snprintf(IObuff, IOSIZE, ":{range}lua buffer=%d", curbuf->b_fnum);
+ } else {
+ // Use ":source buffer=<num>" as the script name
+ snprintf(IObuff, IOSIZE, ":source buffer=%d", curbuf->b_fnum);
+ }
+ fname = xstrdup(IObuff);
}
- char *fname = xstrdup(IObuff);
ga_init(&sp->buflines, sizeof(char *), 100);
// Copy the lines from the buffer into a grow array
diff --git a/test/functional/ex_cmds/source_spec.lua b/test/functional/ex_cmds/source_spec.lua
@@ -247,12 +247,15 @@ describe(':source', function()
feed('dd')
feed_command(':source')
-
+ local filepath = fn.expand('%:p')
+ if filepath == '' then
+ filepath = ':source buffer=1'
+ end
eq(12, eval('g:c'))
eq(' \\ 1\n "\\ 2', exec_lua('return _G.a'))
- eq(':source buffer=1', api.nvim_get_var('sfile_value'))
- eq(':source buffer=1', api.nvim_get_var('stack_value'))
- eq(':source buffer=1', api.nvim_get_var('script_value'))
+ eq(filepath, api.nvim_get_var('sfile_value'))
+ eq(filepath, api.nvim_get_var('stack_value'))
+ eq(filepath, api.nvim_get_var('script_value'))
end)
end