To: vim_dev@googlegroups.com Subject: Patch 8.2.0855 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0855 Problem: GUI tests fail because the test doesn't use a modifier. Solution: Add "\{xxx}" to be able to encode a modifier. Files: runtime/doc/eval.txt, src/typval.c, src/misc2.c, src/vim.h, src/proto/misc2.pro, src/gui_mac.c, src/option.c, src/highlight.c, src/term.c, src/testdir/test_backspace_opt.vim, src/testdir/test_mapping.vim, src/testdir/test_messages.vim *** ../vim-8.2.0854/runtime/doc/eval.txt 2020-05-30 18:37:51.031344270 +0200 --- runtime/doc/eval.txt 2020-05-30 21:07:24.221084848 +0200 *************** *** 1351,1356 **** --- 1353,1361 ---- To use the double quote character it must be escaped: "". Don't use to get a utf-8 character, use \uxxxx as mentioned above. + \{xxx} like \ but prepends a modifier instead of including it in the + character. E.g. "\" is one character 0x17 while "\{C-w}" is four + 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 encodings. Use "\u00ff" to store character 255 according to the current value *** ../vim-8.2.0854/src/typval.c 2020-05-30 17:05:57.032692393 +0200 --- src/typval.c 2020-05-30 21:27:03.484695691 +0200 *************** *** 1285,1299 **** ++name; break; ! // Special key, e.g.: "\" ! case '<': extra = trans_special(&p, name, TRUE, TRUE, ! TRUE, NULL); ! if (extra != 0) { ! name += extra; ! if (name >= rettv->vval.v_string + len) ! iemsg("get_string_tv() used more space than allocated"); ! break; } // FALLTHROUGH --- 1285,1308 ---- ++name; break; ! // Special key, e.g.: "\" or "\{C-W}" ! case '<': ! case '{': { ! int flags = FSK_KEYCODE | FSK_IN_STRING; ! ! if (*p == '<') ! flags |= FSK_SIMPLIFY; ! else ! flags |= FSK_CURLY; ! extra = trans_special(&p, name, flags, NULL); ! if (extra != 0) ! { ! name += extra; ! if (name >= rettv->vval.v_string + len) ! iemsg("get_string_tv() used more space than allocated"); ! break; ! } } // FALLTHROUGH *** ../vim-8.2.0854/src/misc2.c 2020-05-13 22:44:18.138288820 +0200 --- src/misc2.c 2020-05-30 21:34:57.038919735 +0200 *************** *** 2703,2722 **** trans_special( char_u **srcp, char_u *dst, ! int keycode, // prefer key code, e.g. K_DEL instead of DEL ! int in_string, // TRUE when inside a double quoted string ! int simplify, // simplify and ! int *did_simplify) // found or { int modifiers = 0; int key; ! key = find_special_key(srcp, &modifiers, keycode, FALSE, in_string, ! simplify, did_simplify); if (key == 0) return 0; ! return special_to_buf(key, modifiers, keycode, dst); } /* --- 2703,2719 ---- trans_special( char_u **srcp, char_u *dst, ! int flags, // FSK_ values ! int *did_simplify) // FSK_SIMPLIFY and found or { int modifiers = 0; int key; ! key = find_special_key(srcp, &modifiers, flags, did_simplify); if (key == 0) return 0; ! return special_to_buf(key, modifiers, flags & FSK_KEYCODE, dst); } /* *************** *** 2764,2787 **** find_special_key( char_u **srcp, int *modp, ! int keycode, // prefer key code, e.g. K_DEL instead of DEL ! int keep_x_key, // don't translate xHome to Home key ! int in_string, // TRUE in string, double quote is escaped ! int simplify, // simplify and int *did_simplify) // found or { char_u *last_dash; char_u *end_of_name; char_u *src; char_u *bp; int modifiers; int bit; int key; uvarnumber_T n; int l; src = *srcp; ! if (src[0] != '<') return 0; // Find end of modifier list --- 2761,2783 ---- find_special_key( char_u **srcp, int *modp, ! int flags, // FSK_ values int *did_simplify) // found or { char_u *last_dash; char_u *end_of_name; char_u *src; char_u *bp; + int in_string = flags & FSK_IN_STRING; int modifiers; int bit; int key; + int endchar = (flags & FSK_CURLY) ? '}' : '>'; uvarnumber_T n; int l; src = *srcp; ! if (src[0] != ((flags & FSK_CURLY) ? '{' : '<')) return 0; // Find end of modifier list *************** *** 2800,2814 **** // Anything accepted, like . // or are not special in strings as " is // the string delimiter. With a backslash it works: ! if (!(in_string && bp[1] == '"') && bp[l + 1] == '>') bp += l; else if (in_string && bp[1] == '\\' && bp[2] == '"' ! && bp[3] == '>') bp += 2; } } if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) ! bp += 3; // skip t_xx, xx may be '-' or '>' else if (STRNICMP(bp, "char-", 5) == 0) { vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE); --- 2796,2810 ---- // Anything accepted, like . // or are not special in strings as " is // the string delimiter. With a backslash it works: ! if (!(in_string && bp[1] == '"') && bp[l + 1] == endchar) bp += l; else if (in_string && bp[1] == '\\' && bp[2] == '"' ! && bp[3] == endchar) bp += 2; } } if (bp[0] == 't' && bp[1] == '_' && bp[2] && bp[3]) ! bp += 3; // skip t_xx, xx may be '-' or '>'/'}' else if (STRNICMP(bp, "char-", 5) == 0) { vim_str2nr(bp + 5, NULL, &l, STR2NR_ALL, NULL, NULL, 0, TRUE); *************** *** 2822,2828 **** } } ! if (*bp == '>') // found matching '>' { end_of_name = bp + 1; --- 2818,2824 ---- } } ! if (*bp == endchar) // found matching '>' or '}' { end_of_name = bp + 1; *************** *** 2868,2879 **** l = mb_ptr2len(last_dash + off); else l = 1; ! if (modifiers != 0 && last_dash[l + off] == '>') key = PTR2CHAR(last_dash + off); else { key = get_special_key_code(last_dash + off); ! if (!keep_x_key) key = handle_x_keys(key); } } --- 2864,2875 ---- l = mb_ptr2len(last_dash + off); else l = 1; ! if (modifiers != 0 && last_dash[l + off] == endchar) key = PTR2CHAR(last_dash + off); else { key = get_special_key_code(last_dash + off); ! if (!(flags & FSK_KEEP_X_KEY)) key = handle_x_keys(key); } } *************** *** 2890,2896 **** */ key = simplify_key(key, &modifiers); ! if (!keycode) { // don't want keycode, use single byte code if (key == K_BS) --- 2886,2892 ---- */ key = simplify_key(key, &modifiers); ! if (!(flags & FSK_KEYCODE)) { // don't want keycode, use single byte code if (key == K_BS) *************** *** 2902,2908 **** // Normal Key with modifier: Try to make a single byte code. if (!IS_SPECIAL(key)) key = extract_modifiers(key, &modifiers, ! simplify, did_simplify); *modp = modifiers; *srcp = end_of_name; --- 2898,2904 ---- // Normal Key with modifier: Try to make a single byte code. if (!IS_SPECIAL(key)) key = extract_modifiers(key, &modifiers, ! flags & FSK_SIMPLIFY, did_simplify); *modp = modifiers; *srcp = end_of_name; *** ../vim-8.2.0854/src/vim.h 2020-05-30 18:14:37.828521058 +0200 --- src/vim.h 2020-05-30 21:11:21.400206402 +0200 *************** *** 2661,2664 **** --- 2661,2671 ---- #define EVAL_EVALUATE 1 // when missing don't actually evaluate #define EVAL_CONSTANT 2 // when not a constant return FAIL + // Flags for find_special_key() + #define FSK_KEYCODE 0x01 // prefer key code, e.g. K_DEL instead of DEL + #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_SIMPLIFY 0x08 // simplify and + #define FSK_CURLY 0x10 // {C-x} instead of + #endif // VIM__H *** ../vim-8.2.0854/src/proto/misc2.pro 2020-05-13 22:44:18.138288820 +0200 --- src/proto/misc2.pro 2020-05-30 21:20:57.438061455 +0200 *************** *** 68,76 **** int simplify_key(int key, int *modifiers); int handle_x_keys(int key); char_u *get_special_key_name(int c, int modifiers); ! int trans_special(char_u **srcp, char_u *dst, int keycode, int in_string, int simplify, int *did_simplify); int special_to_buf(int key, int modifiers, int keycode, char_u *dst); ! int find_special_key(char_u **srcp, int *modp, int keycode, int keep_x_key, int in_string, int simplify, int *did_simplify); int extract_modifiers(int key, int *modp, int simplify, int *did_simplify); int find_special_key_in_table(int c); int get_special_key_code(char_u *name); --- 68,76 ---- int simplify_key(int key, int *modifiers); int handle_x_keys(int key); char_u *get_special_key_name(int c, int modifiers); ! int trans_special(char_u **srcp, char_u *dst, int flags, int *did_simplify); int special_to_buf(int key, int modifiers, int keycode, char_u *dst); ! int find_special_key(char_u **srcp, int *modp, int flags, int *did_simplify); int extract_modifiers(int key, int *modp, int simplify, int *did_simplify); int find_special_key_in_table(int c); int get_special_key_code(char_u *name); *** ../vim-8.2.0854/src/gui_mac.c 2020-05-16 14:01:48.117547771 +0200 --- src/gui_mac.c 2020-05-30 21:12:57.583848324 +0200 *************** *** 4755,4762 **** char_u *p_actext; p_actext = menu->actext; ! key = find_special_key(&p_actext, &modifiers, FALSE, FALSE, FALSE, ! TRUE, NULL); if (*p_actext != 0) key = 0; // error: trailing text // find_special_key() returns a keycode with as many of the --- 4755,4761 ---- char_u *p_actext; p_actext = menu->actext; ! key = find_special_key(&p_actext, &modifiers, FSK_SIMPLIFY, NULL); if (*p_actext != 0) key = 0; // error: trailing text // find_special_key() returns a keycode with as many of the *** ../vim-8.2.0854/src/option.c 2020-05-03 17:19:30.037025895 +0200 --- src/option.c 2020-05-30 21:15:15.615332886 +0200 *************** *** 4330,4336 **** { --arg; // put arg at the '<' modifiers = 0; ! key = find_special_key(&arg, &modifiers, TRUE, TRUE, FALSE, TRUE, NULL); if (modifiers) // can't handle modifiers here key = 0; } --- 4330,4337 ---- { --arg; // put arg at the '<' modifiers = 0; ! key = find_special_key(&arg, &modifiers, ! FSK_KEYCODE | FSK_KEEP_X_KEY | FSK_SIMPLIFY, NULL); if (modifiers) // can't handle modifiers here key = 0; } *** ../vim-8.2.0854/src/highlight.c 2020-05-13 22:44:18.142288807 +0200 --- src/highlight.c 2020-05-30 21:16:01.883159769 +0200 *************** *** 1412,1419 **** */ for (p = arg, off = 0; off < 100 - 6 && *p; ) { ! len = trans_special(&p, buf + off, FALSE, FALSE, ! TRUE, NULL); if (len > 0) // recognized special char off += len; else // copy as normal char --- 1412,1418 ---- */ for (p = arg, off = 0; off < 100 - 6 && *p; ) { ! len = trans_special(&p, buf + off, FSK_SIMPLIFY, NULL); if (len > 0) // recognized special char off += len; else // copy as normal char *** ../vim-8.2.0854/src/term.c 2020-05-30 18:14:37.828521058 +0200 --- src/term.c 2020-05-30 21:18:47.326543887 +0200 *************** *** 5488,5495 **** } #endif ! slen = trans_special(&src, result + dlen, TRUE, FALSE, ! (flags & REPTERM_NO_SIMPLIFY) == 0, did_simplify); if (slen) { dlen += slen; --- 5488,5496 ---- } #endif ! slen = trans_special(&src, result + dlen, FSK_KEYCODE ! | ((flags & REPTERM_NO_SIMPLIFY) ? 0 : FSK_SIMPLIFY), ! did_simplify); if (slen) { dlen += slen; *** ../vim-8.2.0854/src/testdir/test_backspace_opt.vim 2020-04-17 19:41:16.100078313 +0200 --- src/testdir/test_backspace_opt.vim 2020-05-30 21:28:21.616403251 +0200 *************** *** 86,92 **** set cpo-=< inoremap ! exe "normal Avim3\\\" iunmap exe "normal Avim4\\\\" --- 86,92 ---- set cpo-=< inoremap ! exe "normal Avim3\{C-U}\\" iunmap exe "normal Avim4\\\\" *************** *** 96,102 **** exe "normal A vim6\Azwei\u\\\" inoremap ! exe "normal A vim7\\\\" call assert_equal([ \ "1 this shouldn't be deleted", --- 96,102 ---- exe "normal A vim6\Azwei\u\\\" inoremap ! exe "normal A vim7\{C-U}\{C-U}\\" call assert_equal([ \ "1 this shouldn't be deleted", *** ../vim-8.2.0854/src/testdir/test_mapping.vim 2020-04-08 21:50:18.872619665 +0200 --- src/testdir/test_mapping.vim 2020-05-30 21:38:14.618177070 +0200 *************** *** 76,82 **** inoremap cnoremap dummy cunmap ! call feedkeys("GoTEST2: CTRL-C |\A|\", "xt") call assert_equal('TEST2: CTRL-C |A|', getline('$')) unmap! set nomodified --- 76,82 ---- inoremap cnoremap dummy cunmap ! call feedkeys("GoTEST2: CTRL-C |\{C-C}A|\", "xt") call assert_equal('TEST2: CTRL-C |A|', getline('$')) unmap! set nomodified *************** *** 85,91 **** func Test_map_ctrl_c_visual() " mapping of ctrl-c in Visual mode vnoremap :$put ='vmap works' ! call feedkeys("GV\\", "xt") call assert_equal('vmap works', getline('$')) vunmap set nomodified --- 85,91 ---- func Test_map_ctrl_c_visual() " mapping of ctrl-c in Visual mode vnoremap :$put ='vmap works' ! call feedkeys("GV\{C-C}\", "xt") call assert_equal('vmap works', getline('$')) vunmap set nomodified *************** *** 235,241 **** func Test_map_meta_quotes() imap foo ! call feedkeys("Go-\-\", "xt") call assert_equal("-foo-", getline('$')) set nomodified iunmap --- 235,241 ---- func Test_map_meta_quotes() imap foo ! call feedkeys("Go-\{M-\"}-\", "xt") call assert_equal("-foo-", getline('$')) set nomodified iunmap *** ../vim-8.2.0854/src/testdir/test_messages.vim 2020-05-29 22:41:36.929691032 +0200 --- src/testdir/test_messages.vim 2020-05-30 21:49:32.403626519 +0200 *************** *** 309,315 **** func Test_mapping_at_hit_return_prompt() nnoremap :echo "hit ctrl-b" call feedkeys(":ls\", "xt") ! call feedkeys("\", "xt") call assert_match('hit ctrl-b', Screenline(&lines - 1)) nunmap endfunc --- 309,315 ---- func Test_mapping_at_hit_return_prompt() nnoremap :echo "hit ctrl-b" call feedkeys(":ls\", "xt") ! call feedkeys("\{C-B}", "xt") call assert_match('hit ctrl-b', Screenline(&lines - 1)) nunmap endfunc *** ../vim-8.2.0854/src/version.c 2020-05-30 20:50:21.900629437 +0200 --- src/version.c 2020-05-30 21:40:26.169682322 +0200 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 855, /**/ -- hundred-and-one symptoms of being an internet addict: 221. Your wife melts your keyboard in the oven. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///