comparison runtime/doc/eval.txt @ 22844:36fc73078bce v8.2.1969

patch 8.2.1969: Vim9: map() may change the list or dict item type Commit: https://github.com/vim/vim/commit/ea696852e7abcdebaf7f17a7f23dc90df1f5e2ed Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 9 18:31:39 2020 +0100 patch 8.2.1969: Vim9: map() may change the list or dict item type Problem: Vim9: map() may change the list or dict item type. Solution: Add mapnew().
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 Nov 2020 18:45:04 +0100
parents 8dad79c661d1
children 6d50182e7e24
comparison
equal deleted inserted replaced
22843:b80694c9bb40 22844:36fc73078bce
2667 maparg({name} [, {mode} [, {abbr} [, {dict}]]]) 2667 maparg({name} [, {mode} [, {abbr} [, {dict}]]])
2668 String or Dict 2668 String or Dict
2669 rhs of mapping {name} in mode {mode} 2669 rhs of mapping {name} in mode {mode}
2670 mapcheck({name} [, {mode} [, {abbr}]]) 2670 mapcheck({name} [, {mode} [, {abbr}]])
2671 String check for mappings matching {name} 2671 String check for mappings matching {name}
2672 mapset({mode}, {abbr}, {dict}) 2672 mapnew({expr1}, {expr2}) List/Dict like |map()| but creates a new List
2673 none restore mapping from |maparg()| result 2673 or Dictionary
2674 mapset({mode}, {abbr}, {dict}) none restore mapping from |maparg()| result
2674 match({expr}, {pat} [, {start} [, {count}]]) 2675 match({expr}, {pat} [, {start} [, {count}]])
2675 Number position where {pat} matches in {expr} 2676 Number position where {pat} matches in {expr}
2676 matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]]) 2677 matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
2677 Number highlight {pattern} with {group} 2678 Number highlight {pattern} with {group}
2678 matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]]) 2679 matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
6985 GetExpr()->luaeval() 6986 GetExpr()->luaeval()
6986 6987
6987 < {only available when compiled with the |+lua| feature} 6988 < {only available when compiled with the |+lua| feature}
6988 6989
6989 map({expr1}, {expr2}) *map()* 6990 map({expr1}, {expr2}) *map()*
6990 {expr1} must be a |List| or a |Dictionary|. 6991 {expr1} must be a |List|, |Blob| or |Dictionary|.
6991 Replace each item in {expr1} with the result of evaluating 6992 Replace each item in {expr1} with the result of evaluating
6992 {expr2}. {expr2} must be a |string| or |Funcref|. 6993 {expr2}. For a |Blob| each byte is replaced.
6994 If the item type changes you may want to use |mapnew()| to
6995 create a new List or Dictionary. This is required when using
6996 Vim9 script.
6997
6998 {expr2} must be a |string| or |Funcref|.
6993 6999
6994 If {expr2} is a |string|, inside {expr2} |v:val| has the value 7000 If {expr2} is a |string|, inside {expr2} |v:val| has the value
6995 of the current item. For a |Dictionary| |v:key| has the key 7001 of the current item. For a |Dictionary| |v:key| has the key
6996 of the current item and for a |List| |v:key| has the index of 7002 of the current item and for a |List| |v:key| has the index of
6997 the current item. 7003 the current item.
7022 < 7028 <
7023 The operation is done in-place. If you want a |List| or 7029 The operation is done in-place. If you want a |List| or
7024 |Dictionary| to remain unmodified make a copy first: > 7030 |Dictionary| to remain unmodified make a copy first: >
7025 :let tlist = map(copy(mylist), ' v:val . "\t"') 7031 :let tlist = map(copy(mylist), ' v:val . "\t"')
7026 7032
7027 < Returns {expr1}, the |List| or |Dictionary| that was filtered. 7033 < Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
7028 When an error is encountered while evaluating {expr2} no 7034 filtered. When an error is encountered while evaluating
7029 further items in {expr1} are processed. When {expr2} is a 7035 {expr2} no further items in {expr1} are processed. When
7030 Funcref errors inside a function are ignored, unless it was 7036 {expr2} is a Funcref errors inside a function are ignored,
7031 defined with the "abort" flag. 7037 unless it was defined with the "abort" flag.
7032 7038
7033 Can also be used as a |method|: > 7039 Can also be used as a |method|: >
7034 mylist->map(expr2) 7040 mylist->map(expr2)
7035 7041
7036 7042
7135 7141
7136 Can also be used as a |method|: > 7142 Can also be used as a |method|: >
7137 GetKey()->mapcheck('n') 7143 GetKey()->mapcheck('n')
7138 7144
7139 7145
7140 mapset({mode}, {abbr}, {dict}) *mapset()* 7146 mapnew({expr1}, {expr2}) *mapnew()*
7147 Like |map()| but instead of replacing items in {expr1} a new
7148 List or Dictionary is created and returned. {expr1} remains
7149 unchanged.
7150
7151
7152 mapset({mode}, {abbr}, {dict}) *mapset()*
7141 Restore a mapping from a dictionary returned by |maparg()|. 7153 Restore a mapping from a dictionary returned by |maparg()|.
7142 {mode} and {abbr} should be the same as for the call to 7154 {mode} and {abbr} should be the same as for the call to
7143 |maparg()|. *E460* 7155 |maparg()|. *E460*
7144 {mode} is used to define the mode in which the mapping is set, 7156 {mode} is used to define the mode in which the mapping is set,
7145 not the "mode" entry in {dict}. 7157 not the "mode" entry in {dict}.