]> granicus.if.org Git - vim/commitdiff
patch 8.2.4192: cannot use an import in 'printexpr' v8.2.4192
authorBram Moolenaar <Bram@vim.org>
Sun, 23 Jan 2022 13:44:35 +0000 (13:44 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 23 Jan 2022 13:44:35 +0000 (13:44 +0000)
Problem:    Cannot use an import in 'printexpr'.
Solution:   Set the script context when evaluating 'printexpr'.

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

index 7578378b3bdc2788b21d54897d356147302ace03..196d4d42297a4ec790b0fb4489b72687f4a2af96 100644 (file)
@@ -391,13 +391,21 @@ eval_charconvert(
 eval_printexpr(char_u *fname, char_u *args)
 {
     int                err = FALSE;
+    sctx_T     saved_sctx = current_sctx;
+    sctx_T     *ctx;
 
     set_vim_var_string(VV_FNAME_IN, fname, -1);
     set_vim_var_string(VV_CMDARG, args, -1);
+    ctx = get_option_sctx("printexpr");
+    if (ctx != NULL)
+       current_sctx = *ctx;
+
     if (eval_to_bool(p_pexpr, &err, NULL, FALSE))
        err = TRUE;
+
     set_vim_var_string(VV_FNAME_IN, NULL, -1);
     set_vim_var_string(VV_CMDARG, NULL, -1);
+    current_sctx = saved_sctx;
 
     if (err)
     {
index 19379a01aa31c6c0849b156a337f9ad1068960aa..482e759d11c39b12d2435900e56a8be00f578089 100644 (file)
@@ -874,6 +874,37 @@ def Test_import_in_indentexpr()
   delete('Xindenter')
 enddef
 
+func Test_import_in_printexpr()
+  CheckFeature postscript
+  call Run_Test_import_in_printexpr()
+endfunc
+
+def Run_Test_import_in_printexpr()
+  var lines =<< trim END
+      vim9script
+      export def PrintFile(): bool
+        g:printed = 'yes'
+        delete('v:fname_in')
+        return false
+      enddef
+  END
+  writefile(lines, 'Xprint.vim')
+
+  lines =<< trim END
+      vim9script
+      import './Xprint.vim'
+      set printexpr=Xprint.PrintFile()
+  END
+  CheckScriptSuccess(lines)
+
+  help
+  hardcopy dummy args
+  assert_equal('yes', g:printed)
+
+  delete('Xprint.vim')
+  set printexpr=
+enddef
+
 def Test_export_fails()
   CheckScriptFailure(['export var some = 123'], 'E1042:')
   CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
index f385750da397f68022a7dea4357911c5df09c938..824522f469b0f32e4cb97959c2a7681d37399984 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4192,
 /**/
     4191,
 /**/