]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.1442: mapset() does not restore non-script context v9.0.1442
authorzeertzjq <zeertzjq@outlook.com>
Fri, 7 Apr 2023 21:09:46 +0000 (22:09 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 7 Apr 2023 21:09:46 +0000 (22:09 +0100)
Problem:    mapset() does not restore non-script context.
Solution:   Also accept negative sid. (closes #12132)

src/map.c
src/testdir/test_map_functions.vim
src/version.c

index 7c952865edffc95cef5dc8ed263fc66510769905..d56895b811435a813b70448b53647b5436b126fc 100644 (file)
--- 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)
        {
index a750cd79cd82cd464c6aa811b2c1cc8505594410..d76c79cb858d607edc749292f31a18f142522030 100644 (file)
@@ -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('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
 endfunc
@@ -490,7 +492,28 @@ func Test_map_restore()
   call Check_ctrlb_map(dsimp, 0)
 
   nunmap <C-B>
+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 <Nop>"')
+    call assert_equal([], readfile('Xresult'))
+  endif
+  call delete('Xresult')
 endfunc
 
 def Test_maplist()
index 856eb4666197bb08b36f025b4803c4e8ff2afd9a..192d58278757fcbcff41577b88377d92fde2b6c8 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1442,
 /**/
     1441,
 /**/