To: vim_dev@googlegroups.com Subject: Patch 8.2.0815 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0815 Problem: maparg() does not provide enough information for mapset(). Solution: Add "lhsraw" and "lhsrawalt" items. Drop "simplified" Files: src/map.c, runtime/doc/eval.txt, src/testdir/test_maparg.vim *** ../vim-8.2.0814/src/map.c 2020-05-22 20:01:02.424452078 +0200 --- src/map.c 2020-05-23 23:08:02.733121015 +0200 *************** *** 2176,2190 **** --- 2176,2195 ---- get_maparg(typval_T *argvars, typval_T *rettv, int exact) { char_u *keys; + char_u *keys_simplified; char_u *which; char_u buf[NUMBUFLEN]; char_u *keys_buf = NULL; + char_u *alt_keys_buf = NULL; + int did_simplify = FALSE; char_u *rhs; int mode; int abbr = FALSE; int get_dict = FALSE; mapblock_T *mp; + mapblock_T *mp_simplified; int buffer_local; + int flags = REPTERM_FROM_PART | REPTERM_DO_LT; // return empty string for failure rettv->v_type = VAR_STRING; *************** *** 2211,2220 **** mode = get_map_mode(&which, 0); ! keys = replace_termcodes(keys, &keys_buf, ! REPTERM_FROM_PART | REPTERM_DO_LT, NULL); ! rhs = check_map(keys, mode, exact, FALSE, abbr, &mp, &buffer_local); ! vim_free(keys_buf); if (!get_dict) { --- 2216,2235 ---- mode = get_map_mode(&which, 0); ! keys_simplified = replace_termcodes(keys, &keys_buf, flags, &did_simplify); ! rhs = check_map(keys_simplified, mode, exact, FALSE, abbr, ! &mp, &buffer_local); ! if (did_simplify) ! { ! // When the lhs is being simplified the not-simplified keys are ! // preferred for priting, like in do_map(). ! // The "rhs" and "buffer_local" values are not expected to change. ! mp_simplified = mp; ! (void)replace_termcodes(keys, &alt_keys_buf, ! flags | REPTERM_NO_SIMPLIFY, NULL); ! rhs = check_map(alt_keys_buf, mode, exact, FALSE, abbr, &mp, ! &buffer_local); ! } if (!get_dict) { *************** *** 2236,2241 **** --- 2251,2261 ---- dict_T *dict = rettv->vval.v_dict; dict_add_string(dict, "lhs", lhs); + vim_free(lhs); + dict_add_string(dict, "lhsraw", mp->m_keys); + if (did_simplify) + // Also add the value for the simplified entry. + dict_add_string(dict, "lhsrawalt", mp_simplified->m_keys); dict_add_string(dict, "rhs", mp->m_orig_str); dict_add_number(dict, "noremap", mp->m_noremap ? 1L : 0L); dict_add_number(dict, "script", mp->m_noremap == REMAP_SCRIPT *************** *** 2247,2257 **** dict_add_number(dict, "buffer", (long)buffer_local); dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L); dict_add_string(dict, "mode", mapmode); - dict_add_number(dict, "simplified", mp->m_simplified); - vim_free(lhs); vim_free(mapmode); } } /* --- 2267,2278 ---- dict_add_number(dict, "buffer", (long)buffer_local); dict_add_number(dict, "nowait", mp->m_nowait ? 1L : 0L); dict_add_string(dict, "mode", mapmode); vim_free(mapmode); } + + vim_free(keys_buf); + vim_free(alt_keys_buf); } /* *************** *** 2260,2266 **** void f_mapset(typval_T *argvars, typval_T *rettv UNUSED) { - char_u *keys; char_u *keys_buf = NULL; char_u *which; int mode; --- 2281,2286 ---- *************** *** 2268,2273 **** --- 2288,2295 ---- int is_abbr; dict_T *d; char_u *lhs; + char_u *lhsraw; + char_u *lhsrawalt; char_u *rhs; char_u *orig_rhs; char_u *arg_buf = NULL; *************** *** 2279,2285 **** mapblock_T **map_table = maphash; mapblock_T **abbr_table = &first_abbr; int nowait; - int simplified; char_u *arg; which = tv_get_string_buf_chk(&argvars[0], buf); --- 2301,2306 ---- *************** *** 2295,2309 **** // Get the values in the same order as above in get_maparg(). lhs = dict_get_string(d, (char_u *)"lhs", FALSE); ! if (lhs == NULL) ! { ! emsg(_("E99: lhs entry missing in mapset() dict argument")); ! return; ! } rhs = dict_get_string(d, (char_u *)"rhs", FALSE); ! if (rhs == NULL) { ! emsg(_("E99: rhs entry missing in mapset() dict argument")); return; } orig_rhs = rhs; --- 2316,2327 ---- // Get the values in the same order as above in get_maparg(). lhs = dict_get_string(d, (char_u *)"lhs", FALSE); ! lhsraw = dict_get_string(d, (char_u *)"lhsraw", FALSE); ! lhsrawalt = dict_get_string(d, (char_u *)"lhsrawalt", FALSE); rhs = dict_get_string(d, (char_u *)"rhs", FALSE); ! if (lhs == NULL || lhsraw == NULL || rhs == NULL) { ! emsg(_("E460: entries missing in mapset() dict argument")); return; } orig_rhs = rhs; *************** *** 2324,2330 **** } nowait = dict_get_number(d, (char_u *)"nowait") != 0; // mode from the dict is not used - simplified = dict_get_number(d, (char_u *)"simplified") != 0; // Delete any existing mapping for this lhs and mode. arg = vim_strsave(lhs); --- 2342,2347 ---- *************** *** 2333,2342 **** do_map(1, arg, mode, is_abbr); vim_free(arg); ! keys = replace_termcodes(lhs, &keys_buf, ! REPTERM_FROM_PART | REPTERM_DO_LT, NULL); ! (void)map_add(map_table, abbr_table, keys, rhs, orig_rhs, noremap, ! nowait, silent, mode, is_abbr, expr, sid, lnum, simplified); vim_free(keys_buf); vim_free(arg_buf); } --- 2350,2360 ---- do_map(1, arg, mode, is_abbr); vim_free(arg); ! (void)map_add(map_table, abbr_table, lhsraw, rhs, orig_rhs, noremap, ! nowait, silent, mode, is_abbr, expr, sid, lnum, 0); ! if (lhsrawalt != NULL) ! (void)map_add(map_table, abbr_table, lhsrawalt, rhs, orig_rhs, noremap, ! nowait, silent, mode, is_abbr, expr, sid, lnum, 1); vim_free(keys_buf); vim_free(arg_buf); } *** ../vim-8.2.0814/runtime/doc/eval.txt 2020-05-22 13:09:55.316226075 +0200 --- runtime/doc/eval.txt 2020-05-23 22:16:19.292833238 +0200 *************** *** 2582,2588 **** rhs of mapping {name} in mode {mode} mapcheck({name} [, {mode} [, {abbr}]]) String check for mappings matching {name} ! mapset({name}, {mode}, {abbr}, {dict} none restore mapping from |maparg()| result match({expr}, {pat} [, {start} [, {count}]]) Number position where {pat} matches in {expr} --- 2586,2592 ---- rhs of mapping {name} in mode {mode} mapcheck({name} [, {mode} [, {abbr}]]) String check for mappings matching {name} ! mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result match({expr}, {pat} [, {start} [, {count}]]) Number position where {pat} matches in {expr} *************** *** 6820,6826 **** When {dict} is there and it is |TRUE| return a dictionary containing all the information of the mapping with the following items: ! "lhs" The {lhs} of the mapping. "rhs" The {rhs} of the mapping as typed. "silent" 1 for a |:map-silent| mapping, else 0. "noremap" 1 if the {rhs} of the mapping is not remappable. --- 6830,6839 ---- When {dict} is there and it is |TRUE| return a dictionary containing all the information of the mapping with the following items: ! "lhs" The {lhs} of the mapping as it would be typed ! "lhsraw" The {lhs} of the mapping as raw bytes ! "lhsrawalt" The {lhs} of the mapping as raw bytes, alternate ! form, only present when it differs from "lhsraw" "rhs" The {rhs} of the mapping as typed. "silent" 1 for a |:map-silent| mapping, else 0. "noremap" 1 if the {rhs} of the mapping is not remappable. *************** *** 6838,6844 **** "lnum" The line number in "sid", zero if unknown. "nowait" Do not wait for other, longer mappings. (|:map-|). - "simplified" The dictionary can be used to restore a mapping with |mapset()|. --- 6851,6856 ---- *************** *** 6888,6897 **** Can also be used as a |method|: > GetKey()->mapcheck('n') mapset({mode}, {abbr}, {dict}) *mapset()* Restore a mapping from a dictionary returned by |maparg()|. ! {name}, {mode} and {abbr} should be the same as for the call ! to |maparg()|. {mode} is used to define the mode in which the mapping is set, not the "mode" entry in {dict}. Example for saving and restoring a mapping: > --- 6900,6910 ---- Can also be used as a |method|: > GetKey()->mapcheck('n') + mapset({mode}, {abbr}, {dict}) *mapset()* Restore a mapping from a dictionary returned by |maparg()|. ! {mode} and {abbr} should be the same as for the call to ! |maparg()|. *E460* {mode} is used to define the mode in which the mapping is set, not the "mode" entry in {dict}. Example for saving and restoring a mapping: > *************** *** 6899,6905 **** nnoremap K somethingelse ... call mapset('n', 0, save_map) ! < match({expr}, {pat} [, {start} [, {count}]]) *match()* When {expr} is a |List| then this returns the index of the first item where {pat} matches. Each item is used as a --- 6912,6922 ---- nnoremap K somethingelse ... call mapset('n', 0, save_map) ! < Note that if you are going to replace a map in several modes, ! e.g. with `:map!`, you need to save the mapping for all of ! them, since they can differe. ! ! match({expr}, {pat} [, {start} [, {count}]]) *match()* When {expr} is a |List| then this returns the index of the first item where {pat} matches. Each item is used as a *** ../vim-8.2.0814/src/testdir/test_maparg.vim 2020-05-22 20:01:02.424452078 +0200 --- src/testdir/test_maparg.vim 2020-05-23 23:31:09.022180976 +0200 *************** *** 17,40 **** vnoremap