Patch 8.2.0148
Problem: Mapping related function in wrong source file.
Solution: Move the function. Add a few more test cases. (Yegappan
Lakshmanan, closes #5528)
Files: src/map.c, src/proto/term.pro, src/term.c,
src/testdir/test_mapping.vim
*** ../vim-8.2.0147/src/map.c 2020-01-07 20:59:30.528926519 +0100
--- src/map.c 2020-01-24 20:07:40.101317558 +0100
***************
*** 1057,1062 ****
--- 1057,1137 ----
static int expand_buffer = FALSE;
/*
+ * Translate an internal mapping/abbreviation representation into the
+ * corresponding external one recognized by :map/:abbrev commands.
+ * Respects the current B/k/< settings of 'cpoption'.
+ *
+ * This function is called when expanding mappings/abbreviations on the
+ * command-line.
+ *
+ * It uses a growarray to build the translation string since the latter can be
+ * wider than the original description. The caller has to free the string
+ * afterwards.
+ *
+ * Returns NULL when there is a problem.
+ */
+ static char_u *
+ translate_mapping(char_u *str)
+ {
+ garray_T ga;
+ int c;
+ int modifiers;
+ int cpo_bslash;
+ int cpo_special;
+
+ ga_init(&ga);
+ ga.ga_itemsize = 1;
+ ga.ga_growsize = 40;
+
+ cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL);
+ cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL);
+
+ for (; *str; ++str)
+ {
+ c = *str;
+ if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
+ {
+ modifiers = 0;
+ if (str[1] == KS_MODIFIER)
+ {
+ str++;
+ modifiers = *++str;
+ c = *++str;
+ }
+ if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
+ {
+ if (cpo_special)
+ {
+ ga_clear(&ga);
+ return NULL;
+ }
+ c = TO_SPECIAL(str[1], str[2]);
+ if (c == K_ZERO) // display <Nul> as ^@
+ c = NUL;
+ str += 2;
+ }
+ if (IS_SPECIAL(c) || modifiers) // special key
+ {
+ if (cpo_special)
+ {
+ ga_clear(&ga);
+ return NULL;
+ }
+ ga_concat(&ga, get_special_key_name(c, modifiers));
+ continue; // for (str)
+ }
+ }
+ if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V
+ || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash))
+ ga_append(&ga, cpo_bslash ? Ctrl_V : '\\');
+ if (c)
+ ga_append(&ga, c);
+ }
+ ga_append(&ga, NUL);
+ return (char_u *)(ga.ga_data);
+ }
+
+ /*
* Work out what to complete when doing command line completion of mapping
* or abbreviation names.
*/
*** ../vim-8.2.0147/src/proto/term.pro 2019-12-12 12:55:34.000000000 +0100
--- src/proto/term.pro 2020-01-24 20:07:40.101317558 +0100
***************
*** 72,78 ****
char_u *replace_termcodes(char_u *from, char_u **bufp, int flags, int
*did_simplify);
void show_termcodes(void);
int show_one_termcode(char_u *name, char_u *code, int printit);
- char_u *translate_mapping(char_u *str);
void update_tcap(int attr);
void swap_tcap(void);
guicolor_T gui_get_color_cmn(char_u *name);
--- 72,77 ----
*** ../vim-8.2.0147/src/term.c 2019-12-29 23:04:20.294639884 +0100
--- src/term.c 2020-01-24 20:07:40.105317534 +0100
***************
*** 5936,6016 ****
}
#endif
- /*
- * Translate an internal mapping/abbreviation representation into the
- * corresponding external one recognized by :map/:abbrev commands.
- * Respects the current B/k/< settings of 'cpoption'.
- *
- * This function is called when expanding mappings/abbreviations on the
- * command-line.
- *
- * It uses a growarray to build the translation string since the latter can be
- * wider than the original description. The caller has to free the string
- * afterwards.
- *
- * Returns NULL when there is a problem.
- */
- char_u *
- translate_mapping(char_u *str)
- {
- garray_T ga;
- int c;
- int modifiers;
- int cpo_bslash;
- int cpo_special;
-
- ga_init(&ga);
- ga.ga_itemsize = 1;
- ga.ga_growsize = 40;
-
- cpo_bslash = (vim_strchr(p_cpo, CPO_BSLASH) != NULL);
- cpo_special = (vim_strchr(p_cpo, CPO_SPECI) != NULL);
-
- for (; *str; ++str)
- {
- c = *str;
- if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
- {
- modifiers = 0;
- if (str[1] == KS_MODIFIER)
- {
- str++;
- modifiers = *++str;
- c = *++str;
- }
- if (c == K_SPECIAL && str[1] != NUL && str[2] != NUL)
- {
- if (cpo_special)
- {
- ga_clear(&ga);
- return NULL;
- }
- c = TO_SPECIAL(str[1], str[2]);
- if (c == K_ZERO) // display <Nul> as ^@
- c = NUL;
- str += 2;
- }
- if (IS_SPECIAL(c) || modifiers) // special key
- {
- if (cpo_special)
- {
- ga_clear(&ga);
- return NULL;
- }
- ga_concat(&ga, get_special_key_name(c, modifiers));
- continue; // for (str)
- }
- }
- if (c == ' ' || c == '\t' || c == Ctrl_J || c == Ctrl_V
- || (c == '<' && !cpo_special) || (c == '\\' && !cpo_bslash))
- ga_append(&ga, cpo_bslash ? Ctrl_V : '\\');
- if (c)
- ga_append(&ga, c);
- }
- ga_append(&ga, NUL);
- return (char_u *)(ga.ga_data);
- }
-
#if (defined(MSWIN) && (!defined(FEAT_GUI) || defined(VIMDLL))) ||
defined(PROTO)
static char ksme_str[20];
static char ksmr_str[20];
--- 5936,5941 ----
*** ../vim-8.2.0147/src/testdir/test_mapping.vim 2020-01-23
16:19:51.414652572 +0100
--- src/testdir/test_mapping.vim 2020-01-24 20:07:40.105317534 +0100
***************
*** 476,481 ****
--- 476,490 ----
call assert_equal(['n ,n <Nop>'],
\ execute('nmap ,n')->trim()->split("\n"))
+ " verbose map
+ call assert_match("\tLast set from .*/test_mapping.vim line \\d\\+$",
+ \ execute('verbose map ,n')->trim()->split("\n")[1])
+
+ " map to CTRL-V
+ exe "nmap ,k \<C-V>"
+ call assert_equal(['n ,k <Nop>'],
+ \ execute('nmap ,k')->trim()->split("\n"))
+
nmapclear
endfunc
***************
*** 812,815 ****
--- 821,856 ----
call assert_equal({}, maparg('foo', 'i', 1, 1))
endfunc
+ " Trigger an abbreviation using a special key
+ func Test_abbr_trigger_special()
+ new
+ iabbr teh the
+ call feedkeys("iteh\<F2>\<Esc>", 'xt')
+ call assert_equal('the<F2>', getline(1))
+ iunab teh
+ close!
+ endfunc
+
+ " Test for '<' in 'cpoptions'
+ func Test_map_cpo_special_keycode()
+ set cpo-=<
+ imap x<Bslash>k Test
+ let d = maparg('x<Bslash>k', 'i', 0, 1)
+ call assert_equal(['x\k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
+ call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
+ call assert_equal('"imap x\k', @:)
+ iunmap x<Bslash>k
+ set cpo+=<
+ imap x<Bslash>k Test
+ let d = maparg('x<Bslash>k', 'i', 0, 1)
+ call assert_equal(['x<Bslash>k', 'Test', 'i'], [d.lhs, d.rhs, d.mode])
+ call feedkeys(":imap x\<C-A>\<C-B>\"\<CR>", 'tx')
+ call assert_equal('"imap x<Bslash>k', @:)
+ iunmap x<Bslash>k
+ set cpo-=<
+ " Modifying 'cpo' above adds some default mappings, remove them
+ mapclear
+ mapclear!
+ endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0147/src/version.c 2020-01-23 20:58:05.519775046 +0100
--- src/version.c 2020-01-24 20:09:09.408818637 +0100
***************
*** 744,745 ****
--- 744,747 ----
{ /* Add new patch number below this line */
+ /**/
+ 148,
/**/
--
An easy way to determine if you have enough teamwork to be doomed is simply to
measure how long it takes from the time you decide to go to lunch together
until the time you actually eat.
(Scott Adams - The Dilbert principle)
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202001241921.00OJLltr016257%40masaka.moolenaar.net.