aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2023-08-17 12:37:52 +0800
committerzeertzjq <zeertzjq@outlook.com>2023-08-17 13:14:32 +0800
commitd9e7dad13945ce1f4110c37d5388b5c532dec0d3 (patch)
tree0cf385ae282fa00e739b1eb0926b86262b3b555a /runtime
parent8861f2af72481b1759a6935afa6dce2aae512359 (diff)
downloadrneovim-d9e7dad13945ce1f4110c37d5388b5c532dec0d3.tar.gz
rneovim-d9e7dad13945ce1f4110c37d5388b5c532dec0d3.tar.bz2
rneovim-d9e7dad13945ce1f4110c37d5388b5c532dec0d3.zip
vim-patch:8.2.3818: cannot filter or map characters in a string
Problem: Cannot filter or map characters in a string. Solution: Make filter() and map() work on a string. (Naruhiko Nishino, closes vim/vim#9327) https://github.com/vim/vim/commit/c479ce032f5d4d14bab9e479acbf42d758879893 Co-authored-by: rbtnn <naru123456789@gmail.com>
Diffstat (limited to 'runtime')
-rw-r--r--runtime/doc/builtin.txt47
-rw-r--r--runtime/lua/vim/_meta/vimfn.lua47
2 files changed, 54 insertions, 40 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index a51f14aab0..0b24ed8d85 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -1623,10 +1623,11 @@ filewritable({file}) *filewritable()*
directory, and we can write to it, the result is 2.
filter({expr1}, {expr2}) *filter()*
- {expr1} must be a |List|, |Blob|, or a |Dictionary|.
+ {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
For each item in {expr1} evaluate {expr2} and when the result
- is zero remove the item from the |List| or |Dictionary|. For a
- |Blob| each byte is removed.
+ is zero or false remove the item from the |List| or
+ |Dictionary|. Similarly for each byte in a |Blob| and each
+ character in a |String|.
{expr2} must be a |string| or |Funcref|.
@@ -1662,14 +1663,16 @@ filter({expr1}, {expr2}) *filter()*
< If you do not use "val" you can leave it out: >vim
call filter(myList, {idx -> idx % 2 == 1})
<
- The operation is done in-place. If you want a |List| or
- |Dictionary| to remain unmodified make a copy first: >vim
+ For a |List| and a |Dictionary| the operation is done
+ in-place. If you want it to remain unmodified make a copy
+ first: >vim
let l = filter(copy(mylist), 'v:val =~ "KEEP"')
-< Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
- filtered. When an error is encountered while evaluating
- {expr2} no further items in {expr1} are processed. When
- {expr2} is a Funcref errors inside a function are ignored,
+< Returns {expr1}, the |List| or |Dictionary| that was filtered,
+ or a new |Blob| or |String|.
+ When an error is encountered while evaluating {expr2} no
+ further items in {expr1} are processed.
+ When {expr2} is a Funcref errors inside a function are ignored,
unless it was defined with the "abort" flag.
finddir({name} [, {path} [, {count}]]) *finddir()*
@@ -4062,15 +4065,18 @@ luaeval({expr} [, {expr}]) *luaeval()*
to Vim data structures. See |lua-eval| for more details.
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.
+ {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
+ When {expr1} is a |List|| or |Dictionary|, replace each
+ item in {expr1} with the result of evaluating {expr2}.
+ For a |Blob| each byte is replaced.
+ For a |String|, each character, including composing
+ characters, 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|.
+ {expr2} must be a |String| or |Funcref|.
- If {expr2} is a |string|, inside {expr2} |v:val| has the value
+ If {expr2} is a |String|, inside {expr2} |v:val| has the value
of the current item. For a |Dictionary| |v:key| has the key
of the current item and for a |List| |v:key| has the index of
the current item. For a |Blob| |v:key| has the index of the
@@ -4100,14 +4106,15 @@ map({expr1}, {expr2}) *map()*
< If you do not use "key" you can use a short name: >vim
call map(myDict, {_, val -> 'item: ' .. val})
<
- The operation is done in-place. If you want a |List| or
- |Dictionary| to remain unmodified make a copy first: >vim
+ The operation is done in-place for a |List| and |Dictionary|.
+ If you want it to remain unmodified make a copy first: >vim
let tlist = map(copy(mylist), ' v:val .. "\t"')
-< Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
- filtered. When an error is encountered while evaluating
- {expr2} no further items in {expr1} are processed. When
- {expr2} is a Funcref errors inside a function are ignored,
+< Returns {expr1}, the |List| or |Dictionary| that was filtered,
+ or a new |Blob| or |String|.
+ When an error is encountered while evaluating {expr2} no
+ further items in {expr1} are processed.
+ When {expr2} is a Funcref errors inside a function are ignored,
unless it was defined with the "abort" flag.
maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
diff --git a/runtime/lua/vim/_meta/vimfn.lua b/runtime/lua/vim/_meta/vimfn.lua
index b48e2beb8d..4b90a9e3c0 100644
--- a/runtime/lua/vim/_meta/vimfn.lua
+++ b/runtime/lua/vim/_meta/vimfn.lua
@@ -2005,10 +2005,11 @@ function vim.fn.filereadable(file) end
--- @return 0|1
function vim.fn.filewritable(file) end
---- {expr1} must be a |List|, |Blob|, or a |Dictionary|.
+--- {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
--- For each item in {expr1} evaluate {expr2} and when the result
---- is zero remove the item from the |List| or |Dictionary|. For a
---- |Blob| each byte is removed.
+--- is zero or false remove the item from the |List| or
+--- |Dictionary|. Similarly for each byte in a |Blob| and each
+--- character in a |String|.
---
--- {expr2} must be a |string| or |Funcref|.
---
@@ -2044,14 +2045,16 @@ function vim.fn.filewritable(file) end
--- <If you do not use "val" you can leave it out: >vim
--- call filter(myList, {idx -> idx % 2 == 1})
--- <
---- The operation is done in-place. If you want a |List| or
---- |Dictionary| to remain unmodified make a copy first: >vim
+--- For a |List| and a |Dictionary| the operation is done
+--- in-place. If you want it to remain unmodified make a copy
+--- first: >vim
--- let l = filter(copy(mylist), 'v:val =~ "KEEP"')
---
---- <Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
---- filtered. When an error is encountered while evaluating
---- {expr2} no further items in {expr1} are processed. When
---- {expr2} is a Funcref errors inside a function are ignored,
+--- <Returns {expr1}, the |List| or |Dictionary| that was filtered,
+--- or a new |Blob| or |String|.
+--- When an error is encountered while evaluating {expr2} no
+--- further items in {expr1} are processed.
+--- When {expr2} is a Funcref errors inside a function are ignored,
--- unless it was defined with the "abort" flag.
---
--- @param expr1 any
@@ -4919,15 +4922,18 @@ function vim.fn.log(expr) end
--- @return any
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.
+--- {expr1} must be a |List|, |String|, |Blob| or |Dictionary|.
+--- When {expr1} is a |List|| or |Dictionary|, replace each
+--- item in {expr1} with the result of evaluating {expr2}.
+--- For a |Blob| each byte is replaced.
+--- For a |String|, each character, including composing
+--- characters, 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|.
+--- {expr2} must be a |String| or |Funcref|.
---
---- If {expr2} is a |string|, inside {expr2} |v:val| has the value
+--- If {expr2} is a |String|, inside {expr2} |v:val| has the value
--- of the current item. For a |Dictionary| |v:key| has the key
--- of the current item and for a |List| |v:key| has the index of
--- the current item. For a |Blob| |v:key| has the index of the
@@ -4957,14 +4963,15 @@ function vim.fn.log10(expr) end
--- <If you do not use "key" you can use a short name: >vim
--- call map(myDict, {_, val -> 'item: ' .. val})
--- <
---- The operation is done in-place. If you want a |List| or
---- |Dictionary| to remain unmodified make a copy first: >vim
+--- The operation is done in-place for a |List| and |Dictionary|.
+--- If you want it to remain unmodified make a copy first: >vim
--- let tlist = map(copy(mylist), ' v:val .. "\t"')
---
---- <Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
---- filtered. When an error is encountered while evaluating
---- {expr2} no further items in {expr1} are processed. When
---- {expr2} is a Funcref errors inside a function are ignored,
+--- <Returns {expr1}, the |List| or |Dictionary| that was filtered,
+--- or a new |Blob| or |String|.
+--- When an error is encountered while evaluating {expr2} no
+--- further items in {expr1} are processed.
+--- When {expr2} is a Funcref errors inside a function are ignored,
--- unless it was defined with the "abort" flag.
---
--- @param expr1 any