From d9e7dad13945ce1f4110c37d5388b5c532dec0d3 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 17 Aug 2023 12:37:52 +0800 Subject: 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 --- runtime/lua/vim/_meta/vimfn.lua | 47 +++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 20 deletions(-) (limited to 'runtime/lua/vim') 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 --- 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"') --- ---- 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"') --- ----