From 92a3d20682d46359bb50a452b4f831659e799155 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 31 Aug 2022 16:40:17 +0100 Subject: [PATCH] patch 9.0.0341: mapset() does not restore mapping properly Problem: mapset() does not restore mapping properly. Solution: Use an empty string for . (closes #11022) --- src/map.c | 5 ++++- src/testdir/test_map_functions.vim | 33 ++++++++++++++++++++++++------ src/version.c | 2 ++ 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/src/map.c b/src/map.c index f870b96831..140cbc84f8 100644 --- a/src/map.c +++ b/src/map.c @@ -2658,7 +2658,10 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED) return; } orig_rhs = rhs; - rhs = replace_termcodes(rhs, &arg_buf, + if (STRICMP(rhs, "") == 0) // "" means nothing + rhs = (char_u *)""; + else + rhs = replace_termcodes(rhs, &arg_buf, REPTERM_DO_LT | REPTERM_SPECIAL, NULL); noremap = dict_get_number(d, "noremap") ? REMAP_NONE: 0; diff --git a/src/testdir/test_map_functions.vim b/src/testdir/test_map_functions.vim index 79321a02f4..5caf668c21 100644 --- a/src/testdir/test_map_functions.vim +++ b/src/testdir/test_map_functions.vim @@ -183,11 +183,11 @@ func Test_range_map() call assert_equal("abcd", getline(1)) endfunc -func One_mapset_test(keys) - exe 'nnoremap ' .. a:keys .. ' original' +func One_mapset_test(keys, rhs) + exe 'nnoremap ' .. a:keys .. ' ' .. a:rhs let orig = maparg(a:keys, 'n', 0, 1) call assert_equal(a:keys, orig.lhs) - call assert_equal('original', orig.rhs) + call assert_equal(a:rhs, orig.rhs) call assert_equal('n', orig.mode) exe 'nunmap ' .. a:keys @@ -197,15 +197,16 @@ func One_mapset_test(keys) call mapset('n', 0, orig) let d = maparg(a:keys, 'n', 0, 1) call assert_equal(a:keys, d.lhs) - call assert_equal('original', d.rhs) + call assert_equal(a:rhs, d.rhs) call assert_equal('n', d.mode) exe 'nunmap ' .. a:keys endfunc func Test_mapset() - call One_mapset_test('K') - call One_mapset_test('') + call One_mapset_test('K', 'original') + call One_mapset_test('', 'original') + call One_mapset_test('', 'Nop>') " Check <> key conversion new @@ -228,6 +229,26 @@ func Test_mapset() iunmap K + " Test that is restored properly + inoremap K + call feedkeys("SK\", 'xt') + call assert_equal('', getline(1)) + + let orig = maparg('K', 'i', 0, 1) + call assert_equal('K', orig.lhs) + call assert_equal('', orig.rhs) + call assert_equal('i', orig.mode) + + inoremap K foo + call feedkeys("SK\", 'xt') + call assert_equal('foo', getline(1)) + + call mapset('i', 0, orig) + call feedkeys("SK\", 'xt') + call assert_equal('', getline(1)) + + iunmap K + " Test literal using a backslash let cpo_save = &cpo set cpo-=B diff --git a/src/version.c b/src/version.c index d88688277e..2db1aa65cb 100644 --- a/src/version.c +++ b/src/version.c @@ -707,6 +707,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 341, /**/ 340, /**/