# HG changeset patch # User Bram Moolenaar # Date 1680902104 -7200 # Node ID 44ba07fe943e370e9df3c24ce8e376a17ced8732 # Parent 622cba61715993276cfb73775bea97fe218ef6c1 patch 9.0.1442: mapset() does not restore non-script context Commit: https://github.com/vim/vim/commit/bfc7cbd1d44e53e844a079d8ad16ae990dad664d Author: zeertzjq Date: Fri Apr 7 22:09:46 2023 +0100 patch 9.0.1442: mapset() does not restore non-script context Problem: mapset() does not restore non-script context. Solution: Also accept negative sid. (closes https://github.com/vim/vim/issues/12132) diff --git a/src/map.c b/src/map.c --- a/src/map.c +++ b/src/map.c @@ -227,7 +227,7 @@ map_add( int is_abbr, #ifdef FEAT_EVAL int expr, - scid_T sid, // -1 to use current_sctx + scid_T sid, // 0 to use current_sctx int scriptversion, linenr_T lnum, #endif @@ -266,7 +266,7 @@ map_add( mp->m_simplified = simplified; #ifdef FEAT_EVAL mp->m_expr = expr; - if (sid > 0) + if (sid != 0) { mp->m_script_ctx.sc_sid = sid; mp->m_script_ctx.sc_lnum = lnum; @@ -924,7 +924,7 @@ do_map( if (map_add(map_table, abbr_table, keys, rhs, orig_rhs, noremap, nowait, silent, mode, abbrev, #ifdef FEAT_EVAL - expr, /* sid */ -1, /* scriptversion */ 0, /* lnum */ 0, + expr, /* sid */ 0, /* scriptversion */ 0, /* lnum */ 0, #endif keyround1_simplified) == FAIL) { diff --git a/src/testdir/test_map_functions.vim b/src/testdir/test_map_functions.vim --- a/src/testdir/test_map_functions.vim +++ b/src/testdir/test_map_functions.vim @@ -1,6 +1,8 @@ " Tests for maparg(), mapcheck(), mapset(), maplist() " Also test utf8 map with a 0x80 byte. +source shared.vim + func s:SID() return str2nr(matchstr(expand(''), '\zs\d\+\ze_SID$')) endfunc @@ -490,7 +492,28 @@ func Test_map_restore() call Check_ctrlb_map(dsimp, 0) nunmap +endfunc +" Test restoring the script context of a mapping +func Test_map_restore_sid() + let after =<< trim [CODE] + call assert_equal("\tLast set from --cmd argument", + \ execute('verbose nmap ,n')->trim()->split("\n")[-1]) + let d = maparg(',n', 'n', 0, 1) + nunmap ,n + call assert_equal('No mapping found', + \ execute('verbose nmap ,n')->trim()->split("\n")[-1]) + call mapset('n', 0, d) + call assert_equal("\tLast set from --cmd argument", + \ execute('verbose nmap ,n')->trim()->split("\n")[-1]) + call writefile(v:errors, 'Xresult') + qall! + [CODE] + + if RunVim([], after, '--clean --cmd "nmap ,n "') + call assert_equal([], readfile('Xresult')) + endif + call delete('Xresult') endfunc def Test_maplist() diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1442, +/**/ 1441, /**/ 1440,