• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisiond9e3fdf26cb9625888b05f34910f6147469710a6 (tree)
Time2020-05-23 03:15:03
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.0812: mapset() does not properly handle <> notation

Commit: https://github.com/vim/vim/commit/c94c1467b9b86156a6b7c8d3e41ff01c13d2be07
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri May 22 20:01:06 2020 +0200

patch 8.2.0812: mapset() does not properly handle <> notation
Problem: mapset() does not properly handle <> notation.
Solution: Convert <> codes. (closes https://github.com/vim/vim/issues/6116)

Change Summary

Incremental Difference

diff -r 313bff7c3f01 -r d9e3fdf26cb9 src/map.c
--- a/src/map.c Fri May 22 14:45:04 2020 +0200
+++ b/src/map.c Fri May 22 20:15:03 2020 +0200
@@ -2269,6 +2269,8 @@
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 @@
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 @@
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
diff -r 313bff7c3f01 -r d9e3fdf26cb9 src/testdir/test_maparg.vim
--- a/src/testdir/test_maparg.vim Fri May 22 14:45:04 2020 +0200
+++ b/src/testdir/test_maparg.vim Fri May 22 20:15:03 2020 +0200
@@ -6,7 +6,7 @@
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 @@
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
diff -r 313bff7c3f01 -r d9e3fdf26cb9 src/version.c
--- a/src/version.c Fri May 22 14:45:04 2020 +0200
+++ b/src/version.c Fri May 22 20:15:03 2020 +0200
@@ -747,6 +747,8 @@
747747 static int included_patches[] =
748748 { /* Add new patch number below this line */
749749 /**/
750+ 812,
751+/**/
750752 811,
751753 /**/
752754 810,
Show on old repository browser