diff options
author | Javier Lopez <graulopezjavier@gmail.com> | 2022-02-27 14:35:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-27 12:35:06 -0700 |
commit | 1b5767aa3480c0cdc43f7a4b78f36a14e85a182f (patch) | |
tree | 2329eff263bf6893de4108ab6890515e5f1c3970 /src/nvim/ex_docmd.c | |
parent | c65d93e60adcacded822f0ad5d539042e600f523 (diff) | |
download | rneovim-1b5767aa3480c0cdc43f7a4b78f36a14e85a182f.tar.gz rneovim-1b5767aa3480c0cdc43f7a4b78f36a14e85a182f.tar.bz2 rneovim-1b5767aa3480c0cdc43f7a4b78f36a14e85a182f.zip |
feat(lua): add <f-args> to user commands callback (#17522)
Works similar to ex <f-args>. It only splits the arguments if the
command has more than one posible argument. In cases were the command
can only have 1 argument opts.fargs = { opts.args }
Diffstat (limited to 'src/nvim/ex_docmd.c')
-rw-r--r-- | src/nvim/ex_docmd.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index 48749afcb3..152a41c407 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5802,6 +5802,30 @@ static void ex_delcommand(exarg_T *eap) } } +/// Split a string by unescaped whitespace (space & tab), used for f-args on Lua commands callback. +/// Similar to uc_split_args(), but does not allocate, add quotes, add commas and is an iterator. +/// +/// @note If no separator is found start = 0 and end = length - 1 +/// @param[in] arg String to split +/// @param[in] iter Iteration counter +/// @param[out] start Start of the split +/// @param[out] end End of the split +/// @param[in] length Length of the string +/// @return false if it's the last split (don't call again), true otherwise (call again). +bool uc_split_args_iter(const char_u *arg, int iter, int *start, int *end, int length) +{ + int pos; + *start = *end + (iter > 1 ? 2 : 0); // Skip whitespace after the first split + for (pos = *start; pos < length - 2; pos++) { + if (arg[pos] != '\\' && ascii_iswhite(arg[pos + 1])) { + *end = pos; + return true; + } + } + *end = length - 1; + return false; +} + /* * split and quote args for <f-args> */ |