diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2023-03-20 08:12:33 +0100 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2023-03-22 17:46:01 +0100 |
commit | 9c49c1047079427ff0a2356cb37302934845108e (patch) | |
tree | c945be220cf47635dd553cc7d0b611853c033123 /runtime/doc/lua.txt | |
parent | 3285cd6eccd9b7f33cc32f992c2607c3fc4ca13f (diff) | |
download | rneovim-9c49c1047079427ff0a2356cb37302934845108e.tar.gz rneovim-9c49c1047079427ff0a2356cb37302934845108e.tar.bz2 rneovim-9c49c1047079427ff0a2356cb37302934845108e.zip |
feat(vim.gsplit): gain features of vim.split
Problem:
- vim.split has more features than vim.gsplit.
- Cannot inspect the "separator" segments of vim.split or vim.gsplit.
Solution:
- Move common implementation from vim.split into vim.gsplit.
- TODO: deprecate vim.split in favor of vim.totable(vim.gsplit())?
- Introduce `keepsep` parameter.
Related: 84f66909e4008a57da947f1640bfc24da5e41a72
Diffstat (limited to 'runtime/doc/lua.txt')
-rw-r--r-- | runtime/doc/lua.txt | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 4f56593491..a1fb7aa344 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -1649,14 +1649,25 @@ endswith({s}, {suffix}) *vim.endswith()* Return: ~ (boolean) `true` if `suffix` is a suffix of `s` -gsplit({s}, {sep}, {plain}) *vim.gsplit()* +gsplit({s}, {sep}, {opts}) *vim.gsplit()* Splits a string at each instance of a separator. + Example: >lua + + for s in vim.gsplit(':aa::b:', ':', {plain=true}) do + print(s) + end +< + Parameters: ~ - • {s} (string) String to split - • {sep} (string) Separator or pattern - • {plain} (boolean|nil) If `true` use `sep` literally (passed to - string.find) + • {s} (string) String to split + • {sep} (string) Separator or pattern + • {opts} (table|nil) Keyword arguments |kwargs|: + • keepsep: (boolean) Return segments matching `sep` instead of + discarding them. + • plain: (boolean) Use `sep` literally (as in string.find). + • trimempty: (boolean) Discard empty segments at start and end + of the sequence. Return: ~ (function) Iterator over the split components @@ -1729,7 +1740,7 @@ spairs({t}) *vim.spairs()* See also: ~ • Based on https://github.com/premake/premake-core/blob/master/src/base/table.lua -split({s}, {sep}, {kwargs}) *vim.split()* +split({s}, {sep}, {opts}) *vim.split()* Splits a string at each instance of a separator. Examples: >lua @@ -1738,16 +1749,14 @@ split({s}, {sep}, {kwargs}) *vim.split()* split("axaby", "ab?") --> {'','x','y'} split("x*yz*o", "*", {plain=true}) --> {'x','yz','o'} split("|x|y|z|", "|", {trimempty=true}) --> {'x', 'y', 'z'} + split("|x|y|z|", "|", {keepsep=true}) --> {'|', 'x', '|', 'y', '|', 'z', '|'} < Parameters: ~ - • {s} (string) String to split - • {sep} (string) Separator or pattern - • {kwargs} (table|nil) 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 + • {s} (string) String to split + • {sep} (string) Separator or pattern + • {opts} (table|nil) Keyword arguments |kwargs| accepted by + |vim.gsplit()| Return: ~ string[] List of split components |