@@ -2176,15 +2176,20 @@ check_map(
21762176get_maparg (typval_T * argvars , typval_T * rettv , int exact )
21772177{
21782178 char_u * keys ;
2179+ char_u * keys_simplified ;
21792180 char_u * which ;
21802181 char_u buf [NUMBUFLEN ];
21812182 char_u * keys_buf = NULL ;
2183+ char_u * alt_keys_buf = NULL ;
2184+ int did_simplify = FALSE;
21822185 char_u * rhs ;
21832186 int mode ;
21842187 int abbr = FALSE;
21852188 int get_dict = FALSE;
21862189 mapblock_T * mp ;
2190+ mapblock_T * mp_simplified ;
21872191 int buffer_local ;
2192+ int flags = REPTERM_FROM_PART | REPTERM_DO_LT ;
21882193
21892194 // return empty string for failure
21902195 rettv -> v_type = VAR_STRING ;
@@ -2211,10 +2216,20 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
22112216
22122217 mode = get_map_mode (& which , 0 );
22132218
2214- keys = replace_termcodes (keys , & keys_buf ,
2215- REPTERM_FROM_PART | REPTERM_DO_LT , NULL );
2216- rhs = check_map (keys , mode , exact , FALSE, abbr , & mp , & buffer_local );
2217- vim_free (keys_buf );
2219+ keys_simplified = replace_termcodes (keys , & keys_buf , flags , & did_simplify );
2220+ rhs = check_map (keys_simplified , mode , exact , FALSE, abbr ,
2221+ & mp , & buffer_local );
2222+ if (did_simplify )
2223+ {
2224+ // When the lhs is being simplified the not-simplified keys are
2225+ // preferred for priting, like in do_map().
2226+ // The "rhs" and "buffer_local" values are not expected to change.
2227+ mp_simplified = mp ;
2228+ (void )replace_termcodes (keys , & alt_keys_buf ,
2229+ flags | REPTERM_NO_SIMPLIFY , NULL );
2230+ rhs = check_map (alt_keys_buf , mode , exact , FALSE, abbr , & mp ,
2231+ & buffer_local );
2232+ }
22182233
22192234 if (!get_dict )
22202235 {
@@ -2236,6 +2251,11 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
22362251 dict_T * dict = rettv -> vval .v_dict ;
22372252
22382253 dict_add_string (dict , "lhs" , lhs );
2254+ vim_free (lhs );
2255+ dict_add_string (dict , "lhsraw" , mp -> m_keys );
2256+ if (did_simplify )
2257+ // Also add the value for the simplified entry.
2258+ dict_add_string (dict , "lhsrawalt" , mp_simplified -> m_keys );
22392259 dict_add_string (dict , "rhs" , mp -> m_orig_str );
22402260 dict_add_number (dict , "noremap" , mp -> m_noremap ? 1L : 0L );
22412261 dict_add_number (dict , "script" , mp -> m_noremap == REMAP_SCRIPT
@@ -2247,11 +2267,12 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
22472267 dict_add_number (dict , "buffer" , (long )buffer_local );
22482268 dict_add_number (dict , "nowait" , mp -> m_nowait ? 1L : 0L );
22492269 dict_add_string (dict , "mode" , mapmode );
2250- dict_add_number (dict , "simplified" , mp -> m_simplified );
22512270
2252- vim_free (lhs );
22532271 vim_free (mapmode );
22542272 }
2273+
2274+ vim_free (keys_buf );
2275+ vim_free (alt_keys_buf );
22552276}
22562277
22572278/*
@@ -2260,14 +2281,15 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
22602281 void
22612282f_mapset (typval_T * argvars , typval_T * rettv UNUSED )
22622283{
2263- char_u * keys ;
22642284 char_u * keys_buf = NULL ;
22652285 char_u * which ;
22662286 int mode ;
22672287 char_u buf [NUMBUFLEN ];
22682288 int is_abbr ;
22692289 dict_T * d ;
22702290 char_u * lhs ;
2291+ char_u * lhsraw ;
2292+ char_u * lhsrawalt ;
22712293 char_u * rhs ;
22722294 char_u * orig_rhs ;
22732295 char_u * arg_buf = NULL ;
@@ -2279,7 +2301,6 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
22792301 mapblock_T * * map_table = maphash ;
22802302 mapblock_T * * abbr_table = & first_abbr ;
22812303 int nowait ;
2282- int simplified ;
22832304 char_u * arg ;
22842305
22852306 which = tv_get_string_buf_chk (& argvars [0 ], buf );
@@ -2295,15 +2316,12 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
22952316
22962317 // Get the values in the same order as above in get_maparg().
22972318 lhs = dict_get_string (d , (char_u * )"lhs" , FALSE);
2298- if (lhs == NULL )
2299- {
2300- emsg (_ ("E99: lhs entry missing in mapset() dict argument" ));
2301- return ;
2302- }
2319+ lhsraw = dict_get_string (d , (char_u * )"lhsraw" , FALSE);
2320+ lhsrawalt = dict_get_string (d , (char_u * )"lhsrawalt" , FALSE);
23032321 rhs = dict_get_string (d , (char_u * )"rhs" , FALSE);
2304- if (rhs == NULL )
2322+ if (lhs == NULL || lhsraw == NULL || rhs == NULL )
23052323 {
2306- emsg (_ ("E99: rhs entry missing in mapset() dict argument" ));
2324+ emsg (_ ("E460: entries missing in mapset() dict argument" ));
23072325 return ;
23082326 }
23092327 orig_rhs = rhs ;
@@ -2324,7 +2342,6 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
23242342 }
23252343 nowait = dict_get_number (d , (char_u * )"nowait" ) != 0 ;
23262344 // mode from the dict is not used
2327- simplified = dict_get_number (d , (char_u * )"simplified" ) != 0 ;
23282345
23292346 // Delete any existing mapping for this lhs and mode.
23302347 arg = vim_strsave (lhs );
@@ -2333,10 +2350,11 @@ f_mapset(typval_T *argvars, typval_T *rettv UNUSED)
23332350 do_map (1 , arg , mode , is_abbr );
23342351 vim_free (arg );
23352352
2336- keys = replace_termcodes (lhs , & keys_buf ,
2337- REPTERM_FROM_PART | REPTERM_DO_LT , NULL );
2338- (void )map_add (map_table , abbr_table , keys , rhs , orig_rhs , noremap ,
2339- nowait , silent , mode , is_abbr , expr , sid , lnum , simplified );
2353+ (void )map_add (map_table , abbr_table , lhsraw , rhs , orig_rhs , noremap ,
2354+ nowait , silent , mode , is_abbr , expr , sid , lnum , 0 );
2355+ if (lhsrawalt != NULL )
2356+ (void )map_add (map_table , abbr_table , lhsrawalt , rhs , orig_rhs , noremap ,
2357+ nowait , silent , mode , is_abbr , expr , sid , lnum , 1 );
23402358 vim_free (keys_buf );
23412359 vim_free (arg_buf );
23422360}
0 commit comments