]> granicus.if.org Git - vim/commitdiff
patch 8.2.4186: cannot use an import in 'patchexpr' v8.2.4186
authorBram Moolenaar <Bram@vim.org>
Sat, 22 Jan 2022 20:55:30 +0000 (20:55 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 22 Jan 2022 20:55:30 +0000 (20:55 +0000)
Problem:    Cannot use an import in 'patchexpr'.
Solution:   Set the script context when evaluating 'patchexpr'.  Do not
            require 'patchexpr' to return a bool, it was ignored anyway.

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

index 9dbdc75c0c99a241d8b4116c94f33d7a91a8130f..7578378b3bdc2788b21d54897d356147302ace03 100644 (file)
@@ -443,15 +443,26 @@ eval_patch(
     char_u     *difffile,
     char_u     *outfile)
 {
-    int                err;
+    sctx_T     saved_sctx = current_sctx;
+    sctx_T     *ctx;
+    typval_T   *tv;
 
     set_vim_var_string(VV_FNAME_IN, origfile, -1);
     set_vim_var_string(VV_FNAME_DIFF, difffile, -1);
     set_vim_var_string(VV_FNAME_OUT, outfile, -1);
-    (void)eval_to_bool(p_pex, &err, NULL, FALSE);
+
+    ctx = get_option_sctx("patchexpr");
+    if (ctx != NULL)
+       current_sctx = *ctx;
+
+    // errors are ignored
+    tv = eval_expr(p_pex, NULL);
+    free_tv(tv);
+
     set_vim_var_string(VV_FNAME_IN, NULL, -1);
     set_vim_var_string(VV_FNAME_DIFF, NULL, -1);
     set_vim_var_string(VV_FNAME_OUT, NULL, -1);
+    current_sctx = saved_sctx;
 }
 # endif
 
index 52a0c821da9e21a87f04a3f439ba8f80beb6bd57..19379a01aa31c6c0849b156a337f9ad1068960aa 100644 (file)
@@ -759,6 +759,36 @@ def Run_Test_import_in_diffexpr()
   bwipe!
 enddef
 
+def Test_import_in_patchexpr()
+  var lines =<< trim END
+    vim9script
+    export def TPatch()
+      call writefile(['output file'], v:fname_out)
+    enddef
+  END
+  writefile(lines, 'Xpatchexpr')
+
+  lines =<< trim END
+      vim9script
+      import './Xpatchexpr' as patch
+      set patchexpr=patch.TPatch()
+  END
+  CheckScriptSuccess(lines)
+
+  call writefile(['input file'], 'Xinput')
+  call writefile(['diff file'], 'Xdiff')
+  :%bwipe!
+  edit Xinput
+  diffpatch Xdiff
+  call assert_equal('output file', getline(1))
+
+  call delete('Xinput')
+  call delete('Xdiff')
+  call delete('Xpatchexpr')
+  set patchexpr&
+  :%bwipe!
+enddef
+
 def Test_import_in_formatexpr()
   var lines =<< trim END
       vim9script
index 9571473c96261a0b5c2b0391dbc9d4ce05dab3d4..8e659e0286d2b59b49c36167e0bf077ea0ea61b1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4186,
 /**/
     4185,
 /**/