patch 8.2.4184: cannot use an import in 'includeexpr' v8.2.4184
authorBram Moolenaar <Bram@vim.org>
Sat, 22 Jan 2022 20:19:22 +0000 (20:19 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 22 Jan 2022 20:19:22 +0000 (20:19 +0000)
Problem:    Cannot use an import in 'includeexpr'.
Solution:   Set the script context when evaluating 'includeexpr'

src/findfile.c
src/testdir/test_vim9_import.vim
src/version.c

index 3a6484574ed35ed401d314f3bce1d0603b7ee4a9..e8b3fa656dc11a365171ca8659e52d2518459cb5 100644 (file)
@@ -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
index 1cf1eb069981c07362f31049f56670c5dc76bdb9..423ee0dfd22df154a7123c8a5f499310fabf3bc9 100644 (file)
@@ -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:')
index bdf7a3a51a23092dd0a21fbb7298bce18fa916ce..c4a690c072a42ec49c9b43d9aa44019b650f57d5 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4184,
 /**/
     4183,
 /**/