forked from aniani/vim
patch 8.2.4825: can only get a list of mappings
Problem: Can only get a list of mappings. Solution: Add the optional {abbr} argument. (Ernie Rael, closes #10277) Rename to maplist(). Rename test file.
This commit is contained in:
committed by
Bram Moolenaar
parent
23d5770ef5
commit
09661203ec
@@ -235,7 +235,6 @@ getline({lnum}) String line {lnum} of current buffer
|
|||||||
getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
|
getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
|
||||||
getloclist({nr}) List list of location list items
|
getloclist({nr}) List list of location list items
|
||||||
getloclist({nr}, {what}) Dict get specific location list properties
|
getloclist({nr}, {what}) Dict get specific location list properties
|
||||||
getmappings() List list of all mappings, a dict for each
|
|
||||||
getmarklist([{buf}]) List list of global/local marks
|
getmarklist([{buf}]) List list of global/local marks
|
||||||
getmatches([{win}]) List list of current matches
|
getmatches([{win}]) List list of current matches
|
||||||
getmousepos() Dict last known mouse position
|
getmousepos() Dict last known mouse position
|
||||||
@@ -338,6 +337,7 @@ maparg({name} [, {mode} [, {abbr} [, {dict}]]])
|
|||||||
rhs of mapping {name} in mode {mode}
|
rhs of mapping {name} in mode {mode}
|
||||||
mapcheck({name} [, {mode} [, {abbr}]])
|
mapcheck({name} [, {mode} [, {abbr}]])
|
||||||
String check for mappings matching {name}
|
String check for mappings matching {name}
|
||||||
|
maplist([{abbr}]) List list of all mappings, a dict for each
|
||||||
mapnew({expr1}, {expr2}) List/Dict/Blob/String
|
mapnew({expr1}, {expr2}) List/Dict/Blob/String
|
||||||
like |map()| but creates a new List or
|
like |map()| but creates a new List or
|
||||||
Dictionary
|
Dictionary
|
||||||
@@ -3571,17 +3571,6 @@ getloclist({nr} [, {what}]) *getloclist()*
|
|||||||
:echo getloclist(5, {'filewinid': 0})
|
:echo getloclist(5, {'filewinid': 0})
|
||||||
|
|
||||||
|
|
||||||
getmappings() *getmappings()*
|
|
||||||
Returns a |List| of all mappings. Each List item is a |Dict|,
|
|
||||||
the same as what is returned by |maparg()|, see
|
|
||||||
|mapping-dict|.
|
|
||||||
|
|
||||||
Example to show all mappings with 'MultiMatch' in rhs: >
|
|
||||||
vim9script
|
|
||||||
echo getmappings()->filter(
|
|
||||||
(_, m) => match(m.rhs, 'MultiMatch') >= 0)
|
|
||||||
|
|
||||||
|
|
||||||
getmarklist([{buf}]) *getmarklist()*
|
getmarklist([{buf}]) *getmarklist()*
|
||||||
Without the {buf} argument returns a |List| with information
|
Without the {buf} argument returns a |List| with information
|
||||||
about all the global marks. |mark|
|
about all the global marks. |mark|
|
||||||
@@ -5247,7 +5236,8 @@ maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
|
|||||||
When {dict} is omitted or zero: Return the rhs of mapping
|
When {dict} is omitted or zero: Return the rhs of mapping
|
||||||
{name} in mode {mode}. The returned String has special
|
{name} in mode {mode}. The returned String has special
|
||||||
characters translated like in the output of the ":map" command
|
characters translated like in the output of the ":map" command
|
||||||
listing.
|
listing. When {dict} is TRUE a dictionary is returned, see
|
||||||
|
below. To get a list of all mappings see |maplist()|.
|
||||||
|
|
||||||
When there is no mapping for {name}, an empty String is
|
When there is no mapping for {name}, an empty String is
|
||||||
returned. When the mapping for {name} is empty, then "<Nop>"
|
returned. When the mapping for {name} is empty, then "<Nop>"
|
||||||
@@ -5348,6 +5338,18 @@ mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
|
|||||||
GetKey()->mapcheck('n')
|
GetKey()->mapcheck('n')
|
||||||
|
|
||||||
|
|
||||||
|
maplist([{abbr}]) *maplist()*
|
||||||
|
Returns a |List| of all mappings. Each List item is a |Dict|,
|
||||||
|
the same as what is returned by |maparg()|, see
|
||||||
|
|mapping-dict|. When {abbr} is there and it is |TRUE| use
|
||||||
|
abbreviations instead of mappings.
|
||||||
|
|
||||||
|
Example to show all mappings with 'MultiMatch' in rhs: >
|
||||||
|
vim9script
|
||||||
|
echo maplist()->filter(
|
||||||
|
(_, m) => match(m.rhs, 'MultiMatch') >= 0)
|
||||||
|
|
||||||
|
|
||||||
mapnew({expr1}, {expr2}) *mapnew()*
|
mapnew({expr1}, {expr2}) *mapnew()*
|
||||||
Like |map()| but instead of replacing items in {expr1} a new
|
Like |map()| but instead of replacing items in {expr1} a new
|
||||||
List or Dictionary is created and returned. {expr1} remains
|
List or Dictionary is created and returned. {expr1} remains
|
||||||
|
@@ -1089,10 +1089,10 @@ Mappings and Menus: *mapping-functions*
|
|||||||
digraph_getlist() get all |digraph|s
|
digraph_getlist() get all |digraph|s
|
||||||
digraph_set() register |digraph|
|
digraph_set() register |digraph|
|
||||||
digraph_setlist() register multiple |digraph|s
|
digraph_setlist() register multiple |digraph|s
|
||||||
getmappings() get list of all mappings
|
|
||||||
hasmapto() check if a mapping exists
|
hasmapto() check if a mapping exists
|
||||||
mapcheck() check if a matching mapping exists
|
mapcheck() check if a matching mapping exists
|
||||||
maparg() get rhs of a mapping
|
maparg() get rhs of a mapping
|
||||||
|
maplist() get list of all mappings
|
||||||
mapset() restore a mapping
|
mapset() restore a mapping
|
||||||
menu_info() get information about a menu item
|
menu_info() get information about a menu item
|
||||||
wildmenumode() check if the wildmode is active
|
wildmenumode() check if the wildmode is active
|
||||||
|
@@ -1871,8 +1871,6 @@ static funcentry_T global_functions[] =
|
|||||||
ret_getline, f_getline},
|
ret_getline, f_getline},
|
||||||
{"getloclist", 1, 2, 0, arg2_number_dict_any,
|
{"getloclist", 1, 2, 0, arg2_number_dict_any,
|
||||||
ret_list_or_dict_1, f_getloclist},
|
ret_list_or_dict_1, f_getloclist},
|
||||||
{"getmappings", 0, 0, 0, NULL,
|
|
||||||
ret_list_dict_any, f_getmappings},
|
|
||||||
{"getmarklist", 0, 1, FEARG_1, arg1_buffer,
|
{"getmarklist", 0, 1, FEARG_1, arg1_buffer,
|
||||||
ret_list_dict_any, f_getmarklist},
|
ret_list_dict_any, f_getmarklist},
|
||||||
{"getmatches", 0, 1, 0, arg1_number,
|
{"getmatches", 0, 1, 0, arg1_number,
|
||||||
@@ -2049,6 +2047,8 @@ static funcentry_T global_functions[] =
|
|||||||
ret_maparg, f_maparg},
|
ret_maparg, f_maparg},
|
||||||
{"mapcheck", 1, 3, FEARG_1, arg3_string_string_bool,
|
{"mapcheck", 1, 3, FEARG_1, arg3_string_string_bool,
|
||||||
ret_string, f_mapcheck},
|
ret_string, f_mapcheck},
|
||||||
|
{"maplist", 0, 1, 0, arg1_bool,
|
||||||
|
ret_list_dict_any, f_maplist},
|
||||||
{"mapnew", 2, 2, FEARG_1, arg2_mapnew,
|
{"mapnew", 2, 2, FEARG_1, arg2_mapnew,
|
||||||
ret_first_cont, f_mapnew},
|
ret_first_cont, f_mapnew},
|
||||||
{"mapset", 3, 3, FEARG_1, arg3_string_bool_dict,
|
{"mapset", 3, 3, FEARG_1, arg3_string_bool_dict,
|
||||||
|
21
src/map.c
21
src/map.c
@@ -2389,10 +2389,10 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "getmappings()" function
|
* "maplist()" function
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
|
f_maplist(typval_T *argvars UNUSED, typval_T *rettv)
|
||||||
{
|
{
|
||||||
dict_T *d;
|
dict_T *d;
|
||||||
mapblock_T *mp;
|
mapblock_T *mp;
|
||||||
@@ -2402,6 +2402,12 @@ f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
int hash;
|
int hash;
|
||||||
char_u *lhs;
|
char_u *lhs;
|
||||||
const int flags = REPTERM_FROM_PART | REPTERM_DO_LT;
|
const int flags = REPTERM_FROM_PART | REPTERM_DO_LT;
|
||||||
|
int abbr = FALSE;
|
||||||
|
|
||||||
|
if (in_vim9script() && check_for_opt_bool_arg(argvars, 0) == FAIL)
|
||||||
|
return;
|
||||||
|
if (argvars[0].v_type != VAR_UNKNOWN)
|
||||||
|
abbr = tv_get_bool(&argvars[0]);
|
||||||
|
|
||||||
if (rettv_list_alloc(rettv) != OK)
|
if (rettv_list_alloc(rettv) != OK)
|
||||||
return;
|
return;
|
||||||
@@ -2413,7 +2419,16 @@ f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
|
|||||||
{
|
{
|
||||||
for (hash = 0; hash < 256; ++hash)
|
for (hash = 0; hash < 256; ++hash)
|
||||||
{
|
{
|
||||||
if (buffer_local)
|
if (abbr)
|
||||||
|
{
|
||||||
|
if (hash > 0) // there is only one abbr list
|
||||||
|
break;
|
||||||
|
if (buffer_local)
|
||||||
|
mp = curbuf->b_first_abbr;
|
||||||
|
else
|
||||||
|
mp = first_abbr;
|
||||||
|
}
|
||||||
|
else if (buffer_local)
|
||||||
mp = curbuf->b_maphash[hash];
|
mp = curbuf->b_maphash[hash];
|
||||||
else
|
else
|
||||||
mp = maphash[hash];
|
mp = maphash[hash];
|
||||||
|
@@ -8,7 +8,7 @@ int mode_str2flags(char_u *modechars);
|
|||||||
int map_to_exists(char_u *str, char_u *modechars, int abbr);
|
int map_to_exists(char_u *str, char_u *modechars, int abbr);
|
||||||
int map_to_exists_mode(char_u *rhs, int mode, int abbr);
|
int map_to_exists_mode(char_u *rhs, int mode, int abbr);
|
||||||
char_u *set_context_in_map_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forceit, int isabbrev, int isunmap, cmdidx_T cmdidx);
|
char_u *set_context_in_map_cmd(expand_T *xp, char_u *cmd, char_u *arg, int forceit, int isabbrev, int isunmap, cmdidx_T cmdidx);
|
||||||
int ExpandMappings(char_u *pat, regmatch_T *regmatch, int *num_file, char_u ***file);
|
int ExpandMappings(char_u *pat, regmatch_T *regmatch, int *numMatches, char_u ***matches);
|
||||||
int check_abbr(int c, char_u *ptr, int col, int mincol);
|
int check_abbr(int c, char_u *ptr, int col, int mincol);
|
||||||
char_u *eval_map_expr(mapblock_T *mp, int c);
|
char_u *eval_map_expr(mapblock_T *mp, int c);
|
||||||
char_u *vim_strsave_escape_csi(char_u *p);
|
char_u *vim_strsave_escape_csi(char_u *p);
|
||||||
@@ -17,7 +17,7 @@ int makemap(FILE *fd, buf_T *buf);
|
|||||||
int put_escstr(FILE *fd, char_u *strstart, int what);
|
int put_escstr(FILE *fd, char_u *strstart, int what);
|
||||||
void check_map_keycodes(void);
|
void check_map_keycodes(void);
|
||||||
char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr);
|
char_u *check_map(char_u *keys, int mode, int exact, int ign_mod, int abbr, mapblock_T **mp_ptr, int *local_ptr);
|
||||||
void f_getmappings(typval_T *argvars, typval_T *rettv);
|
void f_maplist(typval_T *argvars, typval_T *rettv);
|
||||||
void f_maparg(typval_T *argvars, typval_T *rettv);
|
void f_maparg(typval_T *argvars, typval_T *rettv);
|
||||||
void f_mapcheck(typval_T *argvars, typval_T *rettv);
|
void f_mapcheck(typval_T *argvars, typval_T *rettv);
|
||||||
void f_mapset(typval_T *argvars, typval_T *rettv);
|
void f_mapset(typval_T *argvars, typval_T *rettv);
|
||||||
|
@@ -184,7 +184,7 @@ NEW_TESTS = \
|
|||||||
test_lua \
|
test_lua \
|
||||||
test_makeencoding \
|
test_makeencoding \
|
||||||
test_man \
|
test_man \
|
||||||
test_maparg \
|
test_map_functions \
|
||||||
test_mapping \
|
test_mapping \
|
||||||
test_marks \
|
test_marks \
|
||||||
test_match \
|
test_match \
|
||||||
@@ -425,7 +425,7 @@ NEW_TESTS_RES = \
|
|||||||
test_lua.res \
|
test_lua.res \
|
||||||
test_makeencoding.res \
|
test_makeencoding.res \
|
||||||
test_man.res \
|
test_man.res \
|
||||||
test_maparg.res \
|
test_map_functions.res \
|
||||||
test_mapping.res \
|
test_mapping.res \
|
||||||
test_marks.res \
|
test_marks.res \
|
||||||
test_match.res \
|
test_match.res \
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
" Tests for maparg(), mapcheck() and mapset().
|
" Tests for maparg(), mapcheck(), mapset(), maplist()
|
||||||
" Also test utf8 map with a 0x80 byte.
|
" Also test utf8 map with a 0x80 byte.
|
||||||
" Also test mapcheck()
|
|
||||||
|
|
||||||
func s:SID()
|
func s:SID()
|
||||||
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
|
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
|
||||||
@@ -297,15 +296,16 @@ func Test_map_restore()
|
|||||||
|
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
def Test_getmappings()
|
def Test_maplist()
|
||||||
new
|
new
|
||||||
def ClearMaps()
|
def ClearMappingsAbbreviations()
|
||||||
mapclear | nmapclear | vmapclear | xmapclear | smapclear | omapclear
|
mapclear | nmapclear | vmapclear | xmapclear | smapclear | omapclear
|
||||||
mapclear! | imapclear | lmapclear | cmapclear | tmapclear
|
mapclear! | imapclear | lmapclear | cmapclear | tmapclear
|
||||||
mapclear <buffer> | nmapclear <buffer> | vmapclear <buffer>
|
mapclear <buffer> | nmapclear <buffer> | vmapclear <buffer>
|
||||||
xmapclear <buffer> | smapclear <buffer> | omapclear <buffer>
|
xmapclear <buffer> | smapclear <buffer> | omapclear <buffer>
|
||||||
mapclear! <buffer> | imapclear <buffer> | lmapclear <buffer>
|
mapclear! <buffer> | imapclear <buffer> | lmapclear <buffer>
|
||||||
cmapclear <buffer> | tmapclear <buffer>
|
cmapclear <buffer> | tmapclear <buffer>
|
||||||
|
abclear | abclear <buffer>
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def AddMaps(new: list<string>, accum: list<string>)
|
def AddMaps(new: list<string>, accum: list<string>)
|
||||||
@@ -314,8 +314,9 @@ def Test_getmappings()
|
|||||||
endif
|
endif
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
ClearMaps()
|
ClearMappingsAbbreviations()
|
||||||
assert_equal(0, len(getmappings()))
|
assert_equal(0, len(maplist()))
|
||||||
|
assert_equal(0, len(maplist(true)))
|
||||||
|
|
||||||
# Set up some mappings.
|
# Set up some mappings.
|
||||||
map dup bar
|
map dup bar
|
||||||
@@ -331,10 +332,16 @@ def Test_getmappings()
|
|||||||
map abc <Nop>
|
map abc <Nop>
|
||||||
nmap <M-j> x
|
nmap <M-j> x
|
||||||
nmap <M-Space> y
|
nmap <M-Space> y
|
||||||
|
# And abbreviations
|
||||||
|
abbreviate xy he
|
||||||
|
abbreviate xx she
|
||||||
|
abbreviate <buffer> x they
|
||||||
|
|
||||||
# Get a list of the mappings with the ':map' commands.
|
# Get a list of the mappings with the ':map' commands.
|
||||||
# Check getmappings() return a list of the same size.
|
# Check maplist() return a list of the same size.
|
||||||
assert_equal(13, len(getmappings()))
|
assert_equal(13, len(maplist()))
|
||||||
|
assert_equal(3, len(maplist(true)))
|
||||||
|
assert_equal(13, len(maplist(false)))
|
||||||
|
|
||||||
# collect all the current maps using :map commands
|
# collect all the current maps using :map commands
|
||||||
var maps_command: list<string>
|
var maps_command: list<string>
|
||||||
@@ -343,20 +350,20 @@ def Test_getmappings()
|
|||||||
AddMaps(split(execute('tmap'), '\n'), maps_command)
|
AddMaps(split(execute('tmap'), '\n'), maps_command)
|
||||||
AddMaps(split(execute('lmap'), '\n'), maps_command)
|
AddMaps(split(execute('lmap'), '\n'), maps_command)
|
||||||
|
|
||||||
# Use getmappings to get all the maps
|
# Use maplist to get all the maps
|
||||||
var maps_getmappings = getmappings()
|
var maps_maplist = maplist()
|
||||||
assert_equal(len(maps_command), len(maps_getmappings))
|
assert_equal(len(maps_command), len(maps_maplist))
|
||||||
|
|
||||||
# make sure all the mode-lhs are unique, no duplicates
|
# make sure all the mode-lhs are unique, no duplicates
|
||||||
var map_set: dict<number>
|
var map_set: dict<number>
|
||||||
for d in maps_getmappings
|
for d in maps_maplist
|
||||||
map_set[d.mode .. "-" .. d.lhs .. "-" .. d.buffer] = 0
|
map_set[d.mode .. "-" .. d.lhs .. "-" .. d.buffer] = 0
|
||||||
endfor
|
endfor
|
||||||
assert_equal(len(maps_getmappings), len(map_set))
|
assert_equal(len(maps_maplist), len(map_set))
|
||||||
|
|
||||||
# For everything returned by getmappings, should be the same as from maparg.
|
# For everything returned by maplist, should be the same as from maparg.
|
||||||
# Except for "map dup", bacause maparg returns the <buffer> version
|
# Except for "map dup", bacause maparg returns the <buffer> version
|
||||||
for d in maps_getmappings
|
for d in maps_maplist
|
||||||
if d.lhs == 'dup' && d.buffer == 0
|
if d.lhs == 'dup' && d.buffer == 0
|
||||||
continue
|
continue
|
||||||
endif
|
endif
|
||||||
@@ -364,8 +371,16 @@ def Test_getmappings()
|
|||||||
assert_equal(d_maparg, d)
|
assert_equal(d_maparg, d)
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
ClearMaps()
|
# Check abbr matches maparg
|
||||||
assert_equal(0, len(getmappings()))
|
for d in maplist(true)
|
||||||
|
# Note, d.mode is '!', but can't use that with maparg
|
||||||
|
var d_maparg = maparg(d.lhs, 'i', true, true)
|
||||||
|
assert_equal(d_maparg, d)
|
||||||
|
endfor
|
||||||
|
|
||||||
|
ClearMappingsAbbreviations()
|
||||||
|
assert_equal(0, len(maplist()))
|
||||||
|
assert_equal(0, len(maplist(true)))
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
4825,
|
||||||
/**/
|
/**/
|
||||||
4824,
|
4824,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user