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.
diff --git a/src/testdir/Make_all.mak b/src/testdir/Make_all.mak
index e1a786f..4a2ea88 100644
--- a/src/testdir/Make_all.mak
+++ b/src/testdir/Make_all.mak
@@ -184,7 +184,7 @@
test_lua \
test_makeencoding \
test_man \
- test_maparg \
+ test_map_functions \
test_mapping \
test_marks \
test_match \
@@ -425,7 +425,7 @@
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
similarity index 89%
rename from src/testdir/test_maparg.vim
rename to src/testdir/test_map_functions.vim
index 6e73b39..8b2f6a8 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 @@
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 @@
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 @@
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 @@
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 @@
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