]> granicus.if.org Git - vim/commitdiff
patch 8.2.4181: Vim9: cannot use an import in 'diffexpr' v8.2.4181
authorBram Moolenaar <Bram@vim.org>
Sat, 22 Jan 2022 17:58:13 +0000 (17:58 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 22 Jan 2022 17:58:13 +0000 (17:58 +0000)
Problem:    Vim9: cannot use an import in 'diffexpr'.
Solution:   Set the script context when evaluating 'diffexpr'.  Do not require
            'diffexpr' to return a bool, it was ignored anyway.

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

index d86d6eb518ddc50911a6c205a3a97a616f3a6f77..a1d2b9b49b39f6e64ff5a3b630e8b74582757b33 100644 (file)
@@ -415,15 +415,26 @@ eval_diff(
     char_u     *newfile,
     char_u     *outfile)
 {
-    int                err = FALSE;
+    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_NEW, newfile, -1);
     set_vim_var_string(VV_FNAME_OUT, outfile, -1);
-    (void)eval_to_bool(p_dex, &err, NULL, FALSE);
+
+    ctx = get_option_sctx("diffexpr");
+    if (ctx != NULL)
+       current_sctx = *ctx;
+
+    // errors are ignored
+    tv = eval_expr(p_dex, NULL);
+    clear_tv(tv);
+
     set_vim_var_string(VV_FNAME_IN, NULL, -1);
     set_vim_var_string(VV_FNAME_NEW, NULL, -1);
     set_vim_var_string(VV_FNAME_OUT, NULL, -1);
+    current_sctx = saved_sctx;
 }
 
     void
index 3608802b1902bdd4a6541f0acb554e0f266bc992..e6d97289609ff028dbac567e6172824f27295277 100644 (file)
@@ -716,6 +716,49 @@ def Test_use_autoload_import_in_fold_expression()
   &rtp = save_rtp
 enddef
 
+func Test_import_in_diffexpr()
+  CheckExecutable diff
+
+  call Run_Test_import_in_diffexpr()
+endfunc
+
+def Run_Test_import_in_diffexpr()
+  var lines =<< trim END
+      vim9script
+
+      export def DiffExpr()
+        # Prepend some text to check diff type detection
+        writefile(['warning', '  message'], v:fname_out)
+        silent exe '!diff ' .. v:fname_in .. ' '
+                            .. v:fname_new .. '>>' .. v:fname_out
+      enddef
+  END
+  writefile(lines, 'Xdiffexpr')
+
+  lines =<< trim END
+      vim9script
+      import './Xdiffexpr' as diff
+
+      set diffexpr=diff.DiffExpr()
+      set diffopt=foldcolumn:0
+  END
+  CheckScriptSuccess(lines)
+
+  enew!
+  call setline(1, ['one', 'two', 'three'])
+  diffthis
+
+  botright vert new
+  call setline(1, ['one', 'two', 'three.'])
+  diffthis
+  # we only check if this does not cause errors
+  redraw
+
+  diffoff!
+  bwipe!
+  bwipe!
+enddef
+
 def Test_export_fails()
   CheckScriptFailure(['export var some = 123'], 'E1042:')
   CheckScriptFailure(['vim9script', 'export var g:some'], 'E1022:')
index 88d32ffa8bcab85827ef15a385a4ab8fe271e6b6..cc5c10167dd8ce97ef9bea1e5cf53159881af4d2 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4181,
 /**/
     4180,
 /**/