aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-17 11:47:40 +0800
committerGitHub <noreply@github.com>2023-08-17 11:47:40 +0800
commit8861f2af72481b1759a6935afa6dce2aae512359 (patch)
tree292843cc0ce14205b328fec6b75c1ad9a0ad7c9b /runtime
parent22d9338afceae5f8ef3845f152dea07a19d512d1 (diff)
parent3117dc70f1e60569f5c3cc0eee5f5005081722b5 (diff)
downloadrneovim-8861f2af72481b1759a6935afa6dce2aae512359.tar.gz
rneovim-8861f2af72481b1759a6935afa6dce2aae512359.tar.bz2
rneovim-8861f2af72481b1759a6935afa6dce2aae512359.zip
Merge pull request #24747 from zeertzjq/vim-8.2.1969
vim-patch:8.2.{1969,1971,2075}: mapnew()
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/builtin.txt8
-rw-r--r--runtime/doc/usr_41.txt2
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua12
3 files changed, 22 insertions, 0 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index bc5f0948e2..a51f14aab0 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -4065,6 +4065,8 @@ map({expr1}, {expr2}) *map()*
{expr1} must be a |List|, |Blob| or |Dictionary|.
Replace each item in {expr1} with the result of evaluating
{expr2}. For a |Blob| each byte is replaced.
+ If the item type changes you may want to use |mapnew()| to
+ create a new List or Dictionary.
{expr2} must be a |string| or |Funcref|.
@@ -4205,6 +4207,12 @@ mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
< This avoids adding the "_vv" mapping when there already is a
mapping for "_v" or for "_vvv".
+mapnew({expr1}, {expr2}) *mapnew()*
+ Like |map()| but instead of replacing items in {expr1} a new
+ List or Dictionary is created and returned. {expr1} remains
+ unchanged. Items can still be changed by {expr2}, if you
+ don't want that use |deepcopy()| first.
+
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
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index e6fcfa2fc6..ac371cf0e3 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -660,6 +660,7 @@ List manipulation: *list-functions*
deepcopy() make a full copy of a List
filter() remove selected items from a List
map() change each List item
+ mapnew() make a new List with changed items
reduce() reduce a List to a value
slice() take a slice of a List
sort() sort a List
@@ -690,6 +691,7 @@ Dictionary manipulation: *dict-functions*
extendnew() make a new Dictionary and append items
filter() remove selected entries from a Dictionary
map() change each Dictionary entry
+ mapnew() make a new Dictionary with changed items
keys() get List of Dictionary keys
values() get List of Dictionary values
items() get List of Dictionary key-value pairs
diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
index d1173e8a42..b48e2beb8d 100644
--- a/runtime/lua/vim/_meta/vimfn.lua
+++ b/runtime/lua/vim/_meta/vimfn.lua
@@ -4922,6 +4922,8 @@ function vim.fn.log10(expr) end
--- {expr1} must be a |List|, |Blob| or |Dictionary|.
--- Replace each item in {expr1} with the result of evaluating
--- {expr2}. For a |Blob| each byte is replaced.
+--- If the item type changes you may want to use |mapnew()| to
+--- create a new List or Dictionary.
---
--- {expr2} must be a |string| or |Funcref|.
---
@@ -5078,6 +5080,16 @@ function vim.fn.maparg(name, mode, abbr, dict) end
--- @return any
function vim.fn.mapcheck(name, mode, abbr) end
+--- Like |map()| but instead of replacing items in {expr1} a new
+--- List or Dictionary is created and returned. {expr1} remains
+--- unchanged. Items can still be changed by {expr2}, if you
+--- don't want that use |deepcopy()| first.
+---
+--- @param expr1 any
+--- @param expr2 any
+--- @return any
+function vim.fn.mapnew(expr1, expr2) end
+
--- Restore a mapping from a dictionary returned by |maparg()|.
--- {mode} and {abbr} should be the same as for the call to
--- |maparg()|. *E460*