summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorErnie Rael <errael@raelity.com>2022-04-25 14:40:44 +0100
committerBram Moolenaar <Bram@vim.org>2022-04-25 14:40:44 +0100
commit09661203ecefbee6a6f09438afcff1843e9dbfb4 (patch)
treee9287958ff8d1d65e4c5a66703cd9f1d16c237fb /src
parent23d5770ef5e2f5c6d20d123303b81327045e5a1e (diff)
patch 8.2.4825: can only get a list of mappingsv8.2.4825
Problem: Can only get a list of mappings. Solution: Add the optional {abbr} argument. (Ernie Rael, closes #10277) Rename to maplist(). Rename test file.
Diffstat (limited to 'src')
-rw-r--r--src/evalfunc.c4
-rw-r--r--src/map.c21
-rw-r--r--src/proto/map.pro4
-rw-r--r--src/testdir/Make_all.mak4
-rw-r--r--src/testdir/test_map_functions.vim (renamed from src/testdir/test_maparg.vim)49
-rw-r--r--src/version.c2
6 files changed, 58 insertions, 26 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 090f3a7364..86a7c0d138 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -1871,8 +1871,6 @@ static funcentry_T global_functions[] =
ret_getline, f_getline},
{"getloclist", 1, 2, 0, arg2_number_dict_any,
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,
ret_list_dict_any, f_getmarklist},
{"getmatches", 0, 1, 0, arg1_number,
@@ -2049,6 +2047,8 @@ static funcentry_T global_functions[] =
ret_maparg, f_maparg},
{"mapcheck", 1, 3, FEARG_1, arg3_string_string_bool,
ret_string, f_mapcheck},
+ {"maplist", 0, 1, 0, arg1_bool,
+ ret_list_dict_any, f_maplist},
{"mapnew", 2, 2, FEARG_1, arg2_mapnew,
ret_first_cont, f_mapnew},
{"mapset", 3, 3, FEARG_1, arg3_string_bool_dict,
diff --git a/src/map.c b/src/map.c
index b2f9dcf511..c7de5a15a6 100644
--- a/src/map.c
+++ b/src/map.c
@@ -2389,10 +2389,10 @@ get_maparg(typval_T *argvars, typval_T *rettv, int exact)
}
/*
- * "getmappings()" function
+ * "maplist()" function
*/
void
-f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
+f_maplist(typval_T *argvars UNUSED, typval_T *rettv)
{
dict_T *d;
mapblock_T *mp;
@@ -2402,6 +2402,12 @@ f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
int hash;
char_u *lhs;
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)
return;
@@ -2413,7 +2419,16 @@ f_getmappings(typval_T *argvars UNUSED, typval_T *rettv)
{
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];
else
mp = maphash[hash];
diff --git a/src/proto/map.pro b/src/proto/map.pro
index 88e61bd5e6..f92339f7da 100644
--- a/src/proto/map.pro
+++ b/src/proto/map.pro
@@ -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_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);
-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);
char_u *eval_map_expr(mapblock_T *mp, int c);
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);
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);
-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_mapcheck(typval_T *argvars, typval_T *rettv);
void f_mapset(typval_T *argvars, typval_T *rettv);
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index e1a786f291..4a2ea88947 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -184,7 +184,7 @@ NEW_TESTS = \
test_lua \
test_makeencoding \
test_man \
- test_maparg \
+ test_map_functions \
test_mapping \
test_marks \
test_match \
@@ -425,7 +425,7 @@ NEW_TESTS_RES = \
test_lua.res \
test_makeencoding.res \
test_man.res \
- test_maparg.res \
+ test_map_functions.res \
test_mapping.res \
test_marks.res \
test_match.res \
diff --git a/src/testdir/test_maparg.vim b/src/testdir/test_map_functions.vim
index 6e73b39553..8b2f6a8538 100644
--- a/src/testdir/test_maparg.vim
+++ b/src/testdir/test_map_functions.vim
@@ -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 mapcheck()
func s:SID()
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
@@ -297,15 +296,16 @@ func Test_map_restore()
endfunc
-def Test_getmappings()
+def Test_maplist()
new
- def ClearMaps()
+ def ClearMappingsAbbreviations()
mapclear | nmapclear | vmapclear | xmapclear | smapclear | omapclear
mapclear! | imapclear | lmapclear | cmapclear | tmapclear
mapclear <buffer> | nmapclear <buffer> | vmapclear <buffer>
xmapclear <buffer> | smapclear <buffer> | omapclear <buffer>
mapclear! <buffer> | imapclear <buffer> | lmapclear <buffer>
cmapclear <buffer> | tmapclear <buffer>
+ abclear | abclear <buffer>
enddef
def AddMaps(new: list<string>, accum: list<string>)
@@ -314,8 +314,9 @@ def Test_getmappings()
endif
enddef
- ClearMaps()
- assert_equal(0, len(getmappings()))
+ ClearMappingsAbbreviations()
+ assert_equal(0, len(maplist()))
+ assert_equal(0, len(maplist(true)))
# Set up some mappings.
map dup bar
@@ -331,10 +332,16 @@ def Test_getmappings()
map abc <Nop>
nmap <M-j> x
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.
- # Check getmappings() return a list of the same size.
- assert_equal(13, len(getmappings()))
+ # Check maplist() return a list of the same size.
+ 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
var maps_command: list<string>
@@ -343,20 +350,20 @@ def Test_getmappings()
AddMaps(split(execute('tmap'), '\n'), maps_command)
AddMaps(split(execute('lmap'), '\n'), maps_command)
- # Use getmappings to get all the maps
- var maps_getmappings = getmappings()
- assert_equal(len(maps_command), len(maps_getmappings))
+ # Use maplist to get all the maps
+ var maps_maplist = maplist()
+ assert_equal(len(maps_command), len(maps_maplist))
# make sure all the mode-lhs are unique, no duplicates
var map_set: dict<number>
- for d in maps_getmappings
+ for d in maps_maplist
map_set[d.mode .. "-" .. d.lhs .. "-" .. d.buffer] = 0
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
- for d in maps_getmappings
+ for d in maps_maplist
if d.lhs == 'dup' && d.buffer == 0
continue
endif
@@ -364,8 +371,16 @@ def Test_getmappings()
assert_equal(d_maparg, d)
endfor
- ClearMaps()
- assert_equal(0, len(getmappings()))
+ # Check abbr matches maparg
+ 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
diff --git a/src/version.c b/src/version.c
index 7ff5c6e0d8..daca23c2c6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4825,
+/**/
4824,
/**/
4823,