diff options
author | Gregory Anders <greg@gpanders.com> | 2021-09-25 20:08:36 -0600 |
---|---|---|
committer | Gregory Anders <greg@gpanders.com> | 2021-09-25 20:11:32 -0600 |
commit | 84f66909e4008a57da947f1640bfc24da5e41a72 (patch) | |
tree | 4f61309a1c3a9f901c39899397555c6a30eb34ed /runtime/lua/vim/shared.lua | |
parent | 5fa26e2c2fcc208ca31187de4338d5b6f746f2e1 (diff) | |
download | rneovim-84f66909e4008a57da947f1640bfc24da5e41a72.tar.gz rneovim-84f66909e4008a57da947f1640bfc24da5e41a72.tar.bz2 rneovim-84f66909e4008a57da947f1640bfc24da5e41a72.zip |
refactor: use kwargs parameter in vim.split
Diffstat (limited to 'runtime/lua/vim/shared.lua')
-rw-r--r-- | runtime/lua/vim/shared.lua | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index e18dec9a45..b57b7ad4ad 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -98,20 +98,32 @@ end --- <pre> --- split(":aa::b:", ":") --> {'','aa','','b',''} --- split("axaby", "ab?") --> {'','x','y'} ---- split("x*yz*o", "*", true) --> {'x','yz','o'} ---- split("|x|y|z|", "|", true, true) --> {'x', 'y', 'z'} +--- split("x*yz*o", "*", {plain=true}) --> {'x','yz','o'} +--- split("|x|y|z|", "|", {trimempty=true}) --> {'x', 'y', 'z'} --- </pre> --- ---@see |vim.gsplit()| --- ---@param s String to split ---@param sep Separator string or pattern ----@param plain If `true` use `sep` literally (passed to String.find) ----@param trimempty If `true` remove empty items from the front and back of the list +---@param kwargs Keyword arguments: +--- - plain: (boolean) If `true` use `sep` literally (passed to string.find) +--- - trimempty: (boolean) If `true` remove empty items from the front +--- and back of the list ---@returns List-like table of the split components. -function vim.split(s, sep, plain, trimempty) - -- Only need to validate trimempty since the rest are validated by vim.gsplit - vim.validate{trimempty={trimempty, 'b', true}} +function vim.split(s, sep, kwargs) + local plain + local trimempty = false + if type(kwargs) == 'boolean' then + -- Support old signature for backward compatibility + plain = kwargs + else + vim.validate { kwargs = {kwargs, 't', true} } + kwargs = kwargs or {} + plain = kwargs.plain + trimempty = kwargs.trimempty + end + local t = {} local skip = trimempty for c in vim.gsplit(s, sep, plain) do |