mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 8.2.0867: using \{xxx} for encoding a modifier is not nice
Problem: Using \{xxx} for encoding a modifier is not nice. Solution: Use \<*xxx> instead, since it's the same as \<xxx> but producing a different code.
This commit is contained in:
@@ -1353,8 +1353,8 @@ A string constant accepts these special characters:
|
|||||||
To use the double quote character it must be escaped: "<M-\">".
|
To use the double quote character it must be escaped: "<M-\">".
|
||||||
Don't use <Char-xxxx> to get a utf-8 character, use \uxxxx as
|
Don't use <Char-xxxx> to get a utf-8 character, use \uxxxx as
|
||||||
mentioned above.
|
mentioned above.
|
||||||
\{xxx} like \<xxx> but prepends a modifier instead of including it in the
|
\<*xxx> Like \<xxx> but prepends a modifier instead of including it in the
|
||||||
character. E.g. "\<C-w>" is one character 0x17 while "\{C-w}" is four
|
character. E.g. "\<C-w>" is one character 0x17 while "\<*C-w>" is four
|
||||||
bytes: 3 for the CTRL modifier and then character "W".
|
bytes: 3 for the CTRL modifier and then character "W".
|
||||||
|
|
||||||
Note that "\xff" is stored as the byte 255, which may be invalid in some
|
Note that "\xff" is stored as the byte 255, which may be invalid in some
|
||||||
|
15
src/misc2.c
15
src/misc2.c
@@ -2772,13 +2772,14 @@ find_special_key(
|
|||||||
int modifiers;
|
int modifiers;
|
||||||
int bit;
|
int bit;
|
||||||
int key;
|
int key;
|
||||||
int endchar = (flags & FSK_CURLY) ? '}' : '>';
|
|
||||||
uvarnumber_T n;
|
uvarnumber_T n;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
src = *srcp;
|
src = *srcp;
|
||||||
if (src[0] != ((flags & FSK_CURLY) ? '{' : '<'))
|
if (src[0] != '<')
|
||||||
return 0;
|
return 0;
|
||||||
|
if (src[1] == '*') // <*xxx>: do not simplify
|
||||||
|
++src;
|
||||||
|
|
||||||
// Find end of modifier list
|
// Find end of modifier list
|
||||||
last_dash = src;
|
last_dash = src;
|
||||||
@@ -2796,15 +2797,15 @@ find_special_key(
|
|||||||
// Anything accepted, like <C-?>.
|
// Anything accepted, like <C-?>.
|
||||||
// <C-"> or <M-"> are not special in strings as " is
|
// <C-"> or <M-"> are not special in strings as " is
|
||||||
// the string delimiter. With a backslash it works: <M-\">
|
// the string delimiter. With a backslash it works: <M-\">
|
||||||
if (!(in_string && bp[1] == '"') && bp[l + 1] == endchar)
|
if (!(in_string && bp[1] == '"') && bp[l + 1] == '>')
|
||||||
bp += l;
|
bp += l;
|
||||||
else if (in_string && bp[1] == '\\' && bp[2] == '"'
|
else if (in_string && bp[1] == '\\' && bp[2] == '"'
|
||||||
&& bp[3] == endchar)
|
&& bp[3] == '>')
|
||||||
bp += 2;
|
bp += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3])
|
if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3])
|
||||||
bp += 3; // skip t_xx, xx may be '-' or '>'/'}'
|
bp += 3; // skip t_xx, xx may be '-' or '>'
|
||||||
else if (STRNICMP(bp, "char-", 5) == 0)
|
else if (STRNICMP(bp, "char-", 5) == 0)
|
||||||
{
|
{
|
||||||
vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE);
|
vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE);
|
||||||
@@ -2818,7 +2819,7 @@ find_special_key(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*bp == endchar) // found matching '>' or '}'
|
if (*bp == '>') // found matching '>'
|
||||||
{
|
{
|
||||||
end_of_name = bp + 1;
|
end_of_name = bp + 1;
|
||||||
|
|
||||||
@@ -2864,7 +2865,7 @@ find_special_key(
|
|||||||
l = mb_ptr2len(last_dash + off);
|
l = mb_ptr2len(last_dash + off);
|
||||||
else
|
else
|
||||||
l = 1;
|
l = 1;
|
||||||
if (modifiers != 0 && last_dash[l + off] == endchar)
|
if (modifiers != 0 && last_dash[l + off] == '>')
|
||||||
key = PTR2CHAR(last_dash + off);
|
key = PTR2CHAR(last_dash + off);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@@ -86,7 +86,7 @@ func Test_backspace_ctrl_u()
|
|||||||
|
|
||||||
set cpo-=<
|
set cpo-=<
|
||||||
inoremap <c-u> <left><c-u>
|
inoremap <c-u> <left><c-u>
|
||||||
exe "normal Avim3\{C-U}\<Esc>\<CR>"
|
exe "normal Avim3\<*C-U>\<Esc>\<CR>"
|
||||||
iunmap <c-u>
|
iunmap <c-u>
|
||||||
exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>"
|
exe "normal Avim4\<C-U>\<C-U>\<Esc>\<CR>"
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ func Test_backspace_ctrl_u()
|
|||||||
exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>"
|
exe "normal A vim6\<Esc>Azwei\<C-G>u\<C-U>\<Esc>\<CR>"
|
||||||
|
|
||||||
inoremap <c-u> <left><c-u>
|
inoremap <c-u> <left><c-u>
|
||||||
exe "normal A vim7\{C-U}\{C-U}\<Esc>\<CR>"
|
exe "normal A vim7\<*C-U>\<*C-U>\<Esc>\<CR>"
|
||||||
|
|
||||||
call assert_equal([
|
call assert_equal([
|
||||||
\ "1 this shouldn't be deleted",
|
\ "1 this shouldn't be deleted",
|
||||||
|
@@ -76,7 +76,7 @@ func Test_map_ctrl_c_insert()
|
|||||||
inoremap <c-c> <ctrl-c>
|
inoremap <c-c> <ctrl-c>
|
||||||
cnoremap <c-c> dummy
|
cnoremap <c-c> dummy
|
||||||
cunmap <c-c>
|
cunmap <c-c>
|
||||||
call feedkeys("GoTEST2: CTRL-C |\{C-C}A|\<Esc>", "xt")
|
call feedkeys("GoTEST2: CTRL-C |\<*C-C>A|\<Esc>", "xt")
|
||||||
call assert_equal('TEST2: CTRL-C |<ctrl-c>A|', getline('$'))
|
call assert_equal('TEST2: CTRL-C |<ctrl-c>A|', getline('$'))
|
||||||
unmap! <c-c>
|
unmap! <c-c>
|
||||||
set nomodified
|
set nomodified
|
||||||
@@ -85,7 +85,7 @@ endfunc
|
|||||||
func Test_map_ctrl_c_visual()
|
func Test_map_ctrl_c_visual()
|
||||||
" mapping of ctrl-c in Visual mode
|
" mapping of ctrl-c in Visual mode
|
||||||
vnoremap <c-c> :<C-u>$put ='vmap works'
|
vnoremap <c-c> :<C-u>$put ='vmap works'
|
||||||
call feedkeys("GV\{C-C}\<CR>", "xt")
|
call feedkeys("GV\<*C-C>\<CR>", "xt")
|
||||||
call assert_equal('vmap works', getline('$'))
|
call assert_equal('vmap works', getline('$'))
|
||||||
vunmap <c-c>
|
vunmap <c-c>
|
||||||
set nomodified
|
set nomodified
|
||||||
@@ -235,7 +235,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_map_meta_quotes()
|
func Test_map_meta_quotes()
|
||||||
imap <M-"> foo
|
imap <M-"> foo
|
||||||
call feedkeys("Go-\{M-\"}-\<Esc>", "xt")
|
call feedkeys("Go-\<*M-\">-\<Esc>", "xt")
|
||||||
call assert_equal("-foo-", getline('$'))
|
call assert_equal("-foo-", getline('$'))
|
||||||
set nomodified
|
set nomodified
|
||||||
iunmap <M-">
|
iunmap <M-">
|
||||||
|
@@ -306,7 +306,7 @@ endfunc
|
|||||||
func Test_mapping_at_hit_return_prompt()
|
func Test_mapping_at_hit_return_prompt()
|
||||||
nnoremap <C-B> :echo "hit ctrl-b"<CR>
|
nnoremap <C-B> :echo "hit ctrl-b"<CR>
|
||||||
call feedkeys(":ls\<CR>", "xt")
|
call feedkeys(":ls\<CR>", "xt")
|
||||||
call feedkeys("\{C-B}", "xt")
|
call feedkeys("\<*C-B>", "xt")
|
||||||
call assert_match('hit ctrl-b', Screenline(&lines - 1))
|
call assert_match('hit ctrl-b', Screenline(&lines - 1))
|
||||||
nunmap <C-B>
|
nunmap <C-B>
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -1285,16 +1285,13 @@ get_string_tv(char_u **arg, typval_T *rettv, int evaluate)
|
|||||||
++name;
|
++name;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Special key, e.g.: "\<C-W>" or "\{C-W}"
|
// Special key, e.g.: "\<C-W>"
|
||||||
case '<':
|
case '<':
|
||||||
case '{':
|
|
||||||
{
|
{
|
||||||
int flags = FSK_KEYCODE | FSK_IN_STRING;
|
int flags = FSK_KEYCODE | FSK_IN_STRING;
|
||||||
|
|
||||||
if (*p == '<')
|
if (p[1] != '*')
|
||||||
flags |= FSK_SIMPLIFY;
|
flags |= FSK_SIMPLIFY;
|
||||||
else
|
|
||||||
flags |= FSK_CURLY;
|
|
||||||
extra = trans_special(&p, name, flags, NULL);
|
extra = trans_special(&p, name, flags, NULL);
|
||||||
if (extra != 0)
|
if (extra != 0)
|
||||||
{
|
{
|
||||||
|
@@ -746,6 +746,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
867,
|
||||||
/**/
|
/**/
|
||||||
866,
|
866,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -2666,6 +2666,5 @@ long elapsed(DWORD start_tick);
|
|||||||
#define FSK_KEEP_X_KEY 0x02 // don't translate xHome to Home key
|
#define FSK_KEEP_X_KEY 0x02 // don't translate xHome to Home key
|
||||||
#define FSK_IN_STRING 0x04 // TRUE in string, double quote is escaped
|
#define FSK_IN_STRING 0x04 // TRUE in string, double quote is escaped
|
||||||
#define FSK_SIMPLIFY 0x08 // simplify <C-H> and <A-x>
|
#define FSK_SIMPLIFY 0x08 // simplify <C-H> and <A-x>
|
||||||
#define FSK_CURLY 0x10 // {C-x} instead of <C-x>
|
|
||||||
|
|
||||||
#endif // VIM__H
|
#endif // VIM__H
|
||||||
|
Reference in New Issue
Block a user