From 6b8d2262d3e94d5f4fdbe29ea621946f2718fe53 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Sun, 10 May 2026 16:41:35 +0000 Subject: [PATCH] patch 9.2.0463: Not able to use legacy expression evaluation in a vim9script maps 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 Signed-off-by: Christian Brabandt --- src/map.c | 9 ++++++--- src/testdir/test_vim9_cmd.vim | 11 +++++++++++ src/version.c | 2 ++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/map.c b/src/map.c index 5f07ef4a81..1c0d0ac7fd 100644 --- 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); diff --git a/src/testdir/test_vim9_cmd.vim b/src/testdir/test_vim9_cmd.vim index ce05898061..f90d719715 100644 --- a/src/testdir/test_vim9_cmd.vim +++ b/src/testdir/test_vim9_cmd.vim @@ -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 'hello' . 'world' + new + feedkeys("a\", 'xt') + assert_equal(['helloworld'], getline(1, '$')) + bw! + END + v9.CheckDefAndScriptSuccess(lines) +enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker diff --git a/src/version.c b/src/version.c index fd79c4354c..1e9a692ea1 100644 --- a/src/version.c +++ b/src/version.c @@ -729,6 +729,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 463, /**/ 462, /**/