Skip to content

Commit c94c146

Browse files
committed
patch 8.2.0812: mapset() does not properly handle <> notation
Problem: mapset() does not properly handle <> notation. Solution: Convert <> codes. (closes #6116)
1 parent 9cdcd1d commit c94c146

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

src/map.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2269,6 +2269,8 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
22692269
dict_T *d;
22702270
char_u *lhs;
22712271
char_u *rhs;
2272+
char_u *orig_rhs;
2273+
char_u *arg_buf = NULL;
22722274
int noremap;
22732275
int expr;
22742276
int silent;
@@ -2304,6 +2306,9 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
23042306
emsg(_("E99: rhs entry missing in mapset() dict argument"));
23052307
return;
23062308
}
2309+
orig_rhs = rhs;
2310+
rhs = replace_termcodes(rhs, &arg_buf,
2311+
REPTERM_DO_LT | REPTERM_SPECIAL, NULL);
23072312

23082313
noremap = dict_get_number(d, (char_u *)"noremap") ? REMAP_NONE: 0;
23092314
if (dict_get_number(d, (char_u *)"script") != 0)
@@ -2330,9 +2335,10 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
23302335

23312336
keys = replace_termcodes(lhs, &keys_buf,
23322337
REPTERM_FROM_PART | REPTERM_DO_LT, NULL);
2333-
(void)map_add(map_table, abbr_table, keys, rhs, rhs, noremap,
2338+
(void)map_add(map_table, abbr_table, keys, rhs, orig_rhs, noremap,
23342339
nowait, silent, mode, is_abbr, expr, sid, lnum, simplified);
23352340
vim_free(keys_buf);
2341+
vim_free(arg_buf);
23362342
}
23372343
#endif
23382344

src/testdir/test_maparg.vim

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ func s:SID()
66
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
77
endfunc
88

9-
funct Test_maparg()
9+
func Test_maparg()
1010
new
1111
set cpo-=<
1212
set encoding=utf8
@@ -156,6 +156,73 @@ endfunc
156156
func Test_mapset()
157157
call One_mapset_test('K')
158158
call One_mapset_test('<F3>')
159+
160+
" Check <> key conversion
161+
new
162+
inoremap K one<Left>x
163+
call feedkeys("iK\<Esc>", 'xt')
164+
call assert_equal('onxe', getline(1))
165+
166+
let orig = maparg('K', 'i', 0, 1)
167+
call assert_equal('K', orig.lhs)
168+
call assert_equal('one<Left>x', orig.rhs)
169+
call assert_equal('i', orig.mode)
170+
171+
iunmap K
172+
let d = maparg('K', 'i', 0, 1)
173+
call assert_equal({}, d)
174+
175+
call mapset('i', 0, orig)
176+
call feedkeys("SK\<Esc>", 'xt')
177+
call assert_equal('onxe', getline(1))
178+
179+
iunmap K
180+
181+
" Test literal <CR> using a backslash
182+
let cpo_save = &cpo
183+
set cpo-=B
184+
inoremap K one\<CR>two
185+
call feedkeys("SK\<Esc>", 'xt')
186+
call assert_equal('one<CR>two', getline(1))
187+
188+
let orig = maparg('K', 'i', 0, 1)
189+
call assert_equal('K', orig.lhs)
190+
call assert_equal('one\<CR>two', orig.rhs)
191+
call assert_equal('i', orig.mode)
192+
193+
iunmap K
194+
let d = maparg('K', 'i', 0, 1)
195+
call assert_equal({}, d)
196+
197+
call mapset('i', 0, orig)
198+
call feedkeys("SK\<Esc>", 'xt')
199+
call assert_equal('one<CR>two', getline(1))
200+
201+
iunmap K
202+
let &cpo = cpo_save
203+
204+
" Test literal <CR> using CTRL-V
205+
inoremap K one<CR>two
206+
call feedkeys("SK\<Esc>", 'xt')
207+
call assert_equal('one<CR>two', getline(1))
208+
209+
let orig = maparg('K', 'i', 0, 1)
210+
call assert_equal('K', orig.lhs)
211+
call assert_equal("one\x16<CR>two", orig.rhs)
212+
call assert_equal('i', orig.mode)
213+
214+
iunmap K
215+
let d = maparg('K', 'i', 0, 1)
216+
call assert_equal({}, d)
217+
218+
call mapset('i', 0, orig)
219+
call feedkeys("SK\<Esc>", 'xt')
220+
call assert_equal('one<CR>two', getline(1))
221+
222+
iunmap K
223+
let &cpo = cpo_save
224+
225+
bwipe!
159226
endfunc
160227

161228
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ static char *(features[]) =
746746

747747
static int included_patches[] =
748748
{ /* Add new patch number below this line */
749+
/**/
750+
812,
749751
/**/
750752
811,
751753
/**/

0 commit comments

Comments
 (0)