To: vim_dev@googlegroups.com Subject: Patch 8.2.5106 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.5106 Problem: Default cmdwin mappings are re-mappable. Solution: Make the default mappings not re-mappable. (closes #10580) Use symbols for the first do_map() argument. Files: src/vim.h, src/ex_getln.c, src/map.c, src/proto/map.pro, src/digraph.c, src/netbeans.c *** ../vim-8.2.5105/src/vim.h 2022-06-04 22:15:48.788982835 +0100 --- src/vim.h 2022-06-16 11:08:37.009420193 +0100 *************** *** 17,23 **** # define MSWIN #endif ! #ifdef MSWIN # include #endif --- 17,23 ---- # define MSWIN #endif ! #if defined(MSWIN) && !defined(PROTO) # include #endif *************** *** 378,384 **** * We assume that when fseeko() is available then ftello() is too. * Note that Windows has different function names. */ ! #ifdef MSWIN typedef __int64 off_T; # ifdef __MINGW32__ # define vim_lseek lseek64 --- 378,384 ---- * We assume that when fseeko() is available then ftello() is too. * Note that Windows has different function names. */ ! #if defined(MSWIN) && !defined(PROTO) typedef __int64 off_T; # ifdef __MINGW32__ # define vim_lseek lseek64 *************** *** 967,972 **** --- 967,977 ---- #define KEY_OPEN_BACK 0x102 #define KEY_COMPLETE 0x103 // end of completion + // Used for the first argument of do_map() + #define MAPTYPE_MAP 0 + #define MAPTYPE_UNMAP 1 + #define MAPTYPE_NOREMAP 2 + // Values for "noremap" argument of ins_typebuf(). Also used for // map->m_noremap and menu->noremap[]. #define REMAP_YES 0 // allow remapping *** ../vim-8.2.5105/src/ex_getln.c 2022-06-14 13:30:31.640876084 +0100 --- src/ex_getln.c 2022-06-16 11:02:57.893063379 +0100 *************** *** 4463,4470 **** { if (p_wc == TAB) { ! add_map((char_u *)" ", MODE_INSERT); ! add_map((char_u *)" a", MODE_NORMAL); } set_option_value_give_err((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); --- 4463,4470 ---- { if (p_wc == TAB) { ! add_map((char_u *)" ", MODE_INSERT, TRUE); ! add_map((char_u *)" a", MODE_NORMAL, TRUE); } set_option_value_give_err((char_u *)"ft", 0L, (char_u *)"vim", OPT_LOCAL); *** ../vim-8.2.5105/src/map.c 2022-05-27 17:26:50.542119974 +0100 --- src/map.c 2022-06-16 11:11:25.325556135 +0100 *************** *** 293,299 **** * noreabbr {lhs} {rhs} : same, but no remapping for {rhs} * unabbr {lhs} : remove abbreviation for {lhs} * ! * maptype: 0 for :map, 1 for :unmap, 2 for noremap. * * arg is pointer to any arguments. Note: arg cannot be a read-only string, * it will be modified. --- 293,301 ---- * noreabbr {lhs} {rhs} : same, but no remapping for {rhs} * unabbr {lhs} : remove abbreviation for {lhs} * ! * maptype: MAPTYPE_MAP for :map ! * MAPTYPE_UNMAP for :unmap ! * MAPTYPE_NOREMAP for noremap * * arg is pointer to any arguments. Note: arg cannot be a read-only string, * it will be modified. *************** *** 360,366 **** abbr_table = &first_abbr; // For ":noremap" don't remap, otherwise do remap. ! if (maptype == 2) noremap = REMAP_NONE; else noremap = REMAP_YES; --- 362,368 ---- abbr_table = &first_abbr; // For ":noremap" don't remap, otherwise do remap. ! if (maptype == MAPTYPE_NOREMAP) noremap = REMAP_NONE; else noremap = REMAP_YES; *************** *** 436,442 **** // with :unmap white space is included in the keys, no argument possible. p = keys; do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); ! while (*p && (maptype == 1 || !VIM_ISWHITE(*p))) { if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && p[1] != NUL) --- 438,444 ---- // with :unmap white space is included in the keys, no argument possible. p = keys; do_backslash = (vim_strchr(p_cpo, CPO_BSLASH) == NULL); ! while (*p && (maptype == MAPTYPE_UNMAP || !VIM_ISWHITE(*p))) { if ((p[0] == Ctrl_V || (do_backslash && p[0] == '\\')) && p[1] != NUL) *************** *** 450,459 **** rhs = p; hasarg = (*rhs != NUL); haskey = (*keys != NUL); ! do_print = !haskey || (maptype != 1 && !hasarg); // check for :unmap without argument ! if (maptype == 1 && !haskey) { retval = 1; goto theend; --- 452,461 ---- rhs = p; hasarg = (*rhs != NUL); haskey = (*keys != NUL); ! do_print = !haskey || (maptype != MAPTYPE_UNMAP && !hasarg); // check for :unmap without argument ! if (maptype == MAPTYPE_UNMAP && !haskey) { retval = 1; goto theend; *************** *** 524,530 **** goto theend; } ! if (abbrev && maptype != 1) { // If an abbreviation ends in a keyword character, the // rest must be all keyword-char or all non-keyword-char. --- 526,532 ---- goto theend; } ! if (abbrev && maptype != MAPTYPE_UNMAP) { // If an abbreviation ends in a keyword character, the // rest must be all keyword-char or all non-keyword-char. *************** *** 580,586 **** // Check if a new local mapping wasn't already defined globally. if (unique && map_table == curbuf->b_maphash ! && haskey && hasarg && maptype != 1) { // need to loop over all global hash lists for (hash = 0; hash < 256 && !got_int; ++hash) --- 582,588 ---- // Check if a new local mapping wasn't already defined globally. if (unique && map_table == curbuf->b_maphash ! && haskey && hasarg && maptype != MAPTYPE_UNMAP) { // need to loop over all global hash lists for (hash = 0; hash < 256 && !got_int; ++hash) *************** *** 615,621 **** } // When listing global mappings, also list buffer-local ones here. ! if (map_table != curbuf->b_maphash && !hasarg && maptype != 1) { // need to loop over all global hash lists for (hash = 0; hash < 256 && !got_int; ++hash) --- 617,624 ---- } // When listing global mappings, also list buffer-local ones here. ! if (map_table != curbuf->b_maphash && !hasarg ! && maptype != MAPTYPE_UNMAP) { // need to loop over all global hash lists for (hash = 0; hash < 256 && !got_int; ++hash) *************** *** 659,665 **** // an entry with a matching 'to' part. This was done to allow // ":ab foo bar" to be unmapped by typing ":unab foo", where "foo" will // be replaced by "bar" because of the abbreviation. ! for (round = 0; (round == 0 || maptype == 1) && round <= 1 && !did_it && !got_int; ++round) { // need to loop over all hash lists --- 662,668 ---- // an entry with a matching 'to' part. This was done to allow // ":ab foo bar" to be unmapped by typing ":unab foo", where "foo" will // be replaced by "bar" because of the abbreviation. ! for (round = 0; (round == 0 || maptype == MAPTYPE_UNMAP) && round <= 1 && !did_it && !got_int; ++round) { // need to loop over all hash lists *************** *** 704,710 **** } if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0) { ! if (maptype == 1) { // Delete entry. // Only accept a full match. For abbreviations --- 707,713 ---- } if (STRNCMP(p, keys, (size_t)(n < len ? n : len)) == 0) { ! if (maptype == MAPTYPE_UNMAP) { // Delete entry. // Only accept a full match. For abbreviations *************** *** 805,811 **** } } ! if (maptype == 1) { // delete entry if (!did_it) --- 808,814 ---- } } ! if (maptype == MAPTYPE_UNMAP) { // delete entry if (!did_it) *************** *** 2661,2667 **** if (arg == NULL) return; } ! do_map(1, arg, mode, is_abbr); vim_free(arg); (void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap, --- 2664,2670 ---- if (arg == NULL) return; } ! do_map(MAPTYPE_UNMAP, arg, mode, is_abbr); vim_free(arg); (void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap, *************** *** 2766,2777 **** # endif { for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i) ! add_map(cinitmappings[i].arg, cinitmappings[i].mode); } # endif # if defined(FEAT_GUI_MSWIN) || defined(MACOS_X) for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i) ! add_map(initmappings[i].arg, initmappings[i].mode); # endif #endif } --- 2769,2780 ---- # endif { for (i = 0; i < (int)ARRAY_LENGTH(cinitmappings); ++i) ! add_map(cinitmappings[i].arg, cinitmappings[i].mode, FALSE); } # endif # if defined(FEAT_GUI_MSWIN) || defined(MACOS_X) for (i = 0; i < (int)ARRAY_LENGTH(initmappings); ++i) ! add_map(initmappings[i].arg, initmappings[i].mode, FALSE); # endif #endif } *************** *** 2780,2789 **** || defined(PROTO) /* * Add a mapping "map" for mode "mode". * Need to put string in allocated memory, because do_map() will modify it. */ void ! add_map(char_u *map, int mode) { char_u *s; char_u *cpo_save = p_cpo; --- 2783,2793 ---- || defined(PROTO) /* * Add a mapping "map" for mode "mode". + * When "nore" is TRUE use MAPTYPE_NOREMAP. * Need to put string in allocated memory, because do_map() will modify it. */ void ! add_map(char_u *map, int mode, int nore) { char_u *s; char_u *cpo_save = p_cpo; *************** *** 2792,2798 **** s = vim_strsave(map); if (s != NULL) { ! (void)do_map(0, s, mode, FALSE); vim_free(s); } p_cpo = cpo_save; --- 2796,2802 ---- s = vim_strsave(map); if (s != NULL) { ! (void)do_map(nore ? MAPTYPE_NOREMAP : MAPTYPE_MAP, s, mode, FALSE); vim_free(s); } p_cpo = cpo_save; *************** *** 2999,3005 **** cmdp = eap->cmd; mode = get_map_mode(&cmdp, eap->forceit || isabbrev); ! switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'), eap->arg, mode, isabbrev)) { case 1: emsg(_(e_invalid_argument)); --- 3003,3010 ---- cmdp = eap->cmd; mode = get_map_mode(&cmdp, eap->forceit || isabbrev); ! switch (do_map(*cmdp == 'n' ? MAPTYPE_NOREMAP ! : *cmdp == 'u' ? MAPTYPE_UNMAP : MAPTYPE_MAP, eap->arg, mode, isabbrev)) { case 1: emsg(_(e_invalid_argument)); *** ../vim-8.2.5105/src/proto/map.pro 2022-04-25 14:37:42.410308492 +0100 --- src/proto/map.pro 2022-06-16 11:02:57.893063379 +0100 *************** *** 22,28 **** void f_mapcheck(typval_T *argvars, typval_T *rettv); void f_mapset(typval_T *argvars, typval_T *rettv); void init_mappings(void); ! void add_map(char_u *map, int mode); int langmap_adjust_mb(int c); void langmap_init(void); void langmap_set(void); --- 22,28 ---- void f_mapcheck(typval_T *argvars, typval_T *rettv); void f_mapset(typval_T *argvars, typval_T *rettv); void init_mappings(void); ! void add_map(char_u *map, int mode, int nore); int langmap_adjust_mb(int c); void langmap_init(void); void langmap_set(void); *** ../vim-8.2.5105/src/digraph.c 2022-05-09 20:09:19.278641427 +0100 --- src/digraph.c 2022-06-16 11:07:03.993335342 +0100 *************** *** 2567,2573 **** vim_snprintf((char *)buf, sizeof(buf), " %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); ! (void)do_map(2, buf, MODE_LANGMAP, FALSE); } p_cpo = save_cpo; --- 2567,2573 ---- vim_snprintf((char *)buf, sizeof(buf), " %s %s", ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].from, ((kmap_T *)curbuf->b_kmap_ga.ga_data)[i].to); ! (void)do_map(MAPTYPE_NOREMAP, buf, MODE_LANGMAP, FALSE); } p_cpo = save_cpo; *************** *** 2598,2604 **** for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), " %s", kp[i].from); ! (void)do_map(1, buf, MODE_LANGMAP, FALSE); } keymap_clear(&curbuf->b_kmap_ga); --- 2598,2604 ---- for (i = 0; i < curbuf->b_kmap_ga.ga_len; ++i) { vim_snprintf((char *)buf, sizeof(buf), " %s", kp[i].from); ! (void)do_map(MAPTYPE_UNMAP, buf, MODE_LANGMAP, FALSE); } keymap_clear(&curbuf->b_kmap_ga); *** ../vim-8.2.5105/src/netbeans.c 2022-05-07 20:01:10.062731687 +0100 --- src/netbeans.c 2022-06-16 11:08:29.821413914 +0100 *************** *** 2323,2329 **** strcpy(&keybuf[i], tok); vim_snprintf(cmdbuf, sizeof(cmdbuf), "<%s> :nbkey %s", keybuf, keybuf); ! do_map(0, (char_u *)cmdbuf, MODE_NORMAL, FALSE); } tok = strtok(NULL, " "); } --- 2323,2329 ---- strcpy(&keybuf[i], tok); vim_snprintf(cmdbuf, sizeof(cmdbuf), "<%s> :nbkey %s", keybuf, keybuf); ! do_map(MAPTYPE_MAP, (char_u *)cmdbuf, MODE_NORMAL, FALSE); } tok = strtok(NULL, " "); } *** ../vim-8.2.5105/src/version.c 2022-06-15 22:11:41.371540580 +0100 --- src/version.c 2022-06-16 11:12:29.205602865 +0100 *************** *** 736,737 **** --- 736,739 ---- { /* Add new patch number below this line */ + /**/ + 5106, /**/ -- A year spent in artificial intelligence is enough to make one believe in God. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///