]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0463: Not able to use legacy expression evaluation in a vim9script maps v9.2.0463
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sun, 10 May 2026 16:41:35 +0000 (16:41 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 10 May 2026 16:41:35 +0000 (16:41 +0000)
Problem:  Not able to use legacy expression evaluation in a vim9script
          maps
Solution: Explicitly set script version to 1 when the :legacy modifier has been
          used (Yegappan Lakshmanan).

fixe:   #20176
closes: #20177

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/map.c
src/testdir/test_vim9_cmd.vim
src/version.c

index 5f07ef4a81433154d56729768fc7206a3b559765..1c0d0ac7fd43f7763fb60e1a8723240fda3a94ee 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -277,6 +277,8 @@ map_add(
     else
     {
        mp->m_script_ctx = current_sctx;
+       if (cmdmod.cmod_flags & CMOD_LEGACY)
+           mp->m_script_ctx.sc_version = 1;
        mp->m_script_ctx.sc_lnum += SOURCING_LNUM;
     }
 #endif
@@ -871,6 +873,8 @@ do_map(
 #ifdef FEAT_EVAL
                                    mp->m_expr = expr;
                                    mp->m_script_ctx = current_sctx;
+                                   if (cmdmod.cmod_flags & CMOD_LEGACY)
+                                       mp->m_script_ctx.sc_version = 1;
                                    mp->m_script_ctx.sc_lnum += SOURCING_LNUM;
 #endif
                                    mp_result[keyround - 1] = mp;
@@ -1822,11 +1826,10 @@ eval_map_expr(
     save_cursor = curwin->w_cursor;
     save_msg_col = msg_col;
     save_msg_row = msg_row;
+
+    current_sctx.sc_version = mp->m_script_ctx.sc_version;
     if (mp->m_script_ctx.sc_version == SCRIPT_VERSION_VIM9)
-    {
        current_sctx.sc_sid = mp->m_script_ctx.sc_sid;
-       current_sctx.sc_version = SCRIPT_VERSION_VIM9;
-    }
 
     // Note: the evaluation may make "mp" invalid.
     p = eval_to_string(expr, FALSE, FALSE);
index ce05898061c6a9428eca5be7a21e082fc2551d03..f90d7197158ed9c089508e3c6b6cb09da1ef3f82 100644 (file)
@@ -2145,5 +2145,16 @@ def Test_syntax_enable_clear()
   syntax clear
 enddef
 
+" Test for using legacy expression evaluation in a vim9script map
+def Test_map_legacy_expr()
+  var lines =<< trim END
+    legacy inoremap <expr> <F2> 'hello' . 'world'
+    new
+    feedkeys("a\<F2>", 'xt')
+    assert_equal(['helloworld'], getline(1, '$'))
+    bw!
+  END
+  v9.CheckDefAndScriptSuccess(lines)
+enddef
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index fd79c4354ce9d60364da166730cc5bb82121b6bf..1e9a692ea10954625d3aab417fb509a584021c94 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    463,
 /**/
     462,
 /**/