changeset 27311:b3ef31c6a922 v8.2.4184

patch 8.2.4184: cannot use an import in 'includeexpr' Commit: https://github.com/vim/vim/commit/47bcc5f4c83c158f43ac2ea7abfe99dbf5c2e098 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jan 22 20:19:22 2022 +0000 patch 8.2.4184: cannot use an import in 'includeexpr' Problem: Cannot use an import in 'includeexpr'. Solution: Set the script context when evaluating 'includeexpr'
author Bram Moolenaar <Bram@vim.org>
date Sat, 22 Jan 2022 21:30:02 +0100
parents 1644ebf86471
children 50468d3041ae
files src/findfile.c src/testdir/test_vim9_import.vim src/version.c
diffstat 3 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/findfile.c
+++ b/src/findfile.c
@@ -2094,11 +2094,16 @@ file_name_in_line(
 eval_includeexpr(char_u *ptr, int len)
 {
     char_u	*res;
+    sctx_T	save_sctx = current_sctx;
 
     set_vim_var_string(VV_FNAME, ptr, len);
+    current_sctx = curbuf->b_p_script_ctx[BV_INEX];
+
     res = eval_to_string_safe(curbuf->b_p_inex,
-		was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), FALSE);
+		 was_set_insecurely((char_u *)"includeexpr", OPT_LOCAL), TRUE);
+
     set_vim_var_string(VV_FNAME, NULL, 0);
+    current_sctx = save_sctx;
     return res;
 }
 # endif
--- a/src/testdir/test_vim9_import.vim
+++ b/src/testdir/test_vim9_import.vim
@@ -787,6 +787,36 @@ def Test_import_in_formatexpr()
   set formatexpr=
 enddef
 
+def Test_import_in_includeexpr()
+  writefile(['found it'], 'Xthisfile')
+  new
+
+  var lines =<< trim END
+      vim9script
+      export def DoSub(): string
+        return substitute(v:fname, 'that', 'this', '')
+      enddef
+  END
+  writefile(lines, 'Xinclude.vim')
+
+  lines =<< trim END
+    vim9script
+    import './Xinclude.vim'
+    set includeexpr=Xinclude.DoSub()
+  END
+  CheckScriptSuccess(lines)
+
+  setline(1, ['Xthatfile'])
+  exe "normal \<C-W>f"
+  assert_equal('Xthisfile', expand('%'))
+
+  bwipe!
+  bwipe!
+  set includeexpr=
+  delete('Xinclude')
+  delete('Xthisfile')
+enddef
+
 def Test_export_fails()
   CheckScriptFailure(['export var some = 123'], 'E1042:')
   CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    4184,
+/**/
     4183,
 /**/
     4182,