diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2023-02-26 23:50:35 +0800 |
|---|---|---|
| committer | zeertzjq <zeertzjq@outlook.com> | 2023-02-27 07:53:17 +0800 |
| commit | 13da3d469ae10201de00ae89277c53c40342f4df (patch) | |
| tree | 963f105baad90689714a467b08d4c0d49b20c2c4 /runtime/doc | |
| parent | 0972d7a12468d6914a70e453af85c307b167c55b (diff) | |
| download | rneovim-13da3d469ae10201de00ae89277c53c40342f4df.tar.gz rneovim-13da3d469ae10201de00ae89277c53c40342f4df.tar.bz2 rneovim-13da3d469ae10201de00ae89277c53c40342f4df.zip | |
vim-patch:partial:9.0.0202: code and help for indexof() is not ideal
Problem: Code and help for indexof() is not ideal.
Solution: Refactor the code, improve the help. (Yegappan Lakshmanan,
closes vim/vim#10908)
https://github.com/vim/vim/commit/3fbf6cd355de2212e9227f57d545592aae3f688f
Skip CHECK_LIST_MATERIALIZE and set_vim_var_type().
Use tv_list_uidx() instead of lv_idx.
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Diffstat (limited to 'runtime/doc')
| -rw-r--r-- | runtime/doc/builtin.txt | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt index 1168d7ff1d..35f1b7cd6f 100644 --- a/runtime/doc/builtin.txt +++ b/runtime/doc/builtin.txt @@ -4087,7 +4087,7 @@ indent({lnum}) The result is a Number, which is indent of line {lnum} in the index({object}, {expr} [, {start} [, {ic}]]) *index()* Find {expr} in {object} and return its index. See - |filterof()| for using a lambda to select the item. + |indexof()| for using a lambda to select the item. If {object} is a |List| return the lowest index where the item has a value equal to {expr}. There is no automatic @@ -4113,15 +4113,17 @@ index({object}, {expr} [, {start} [, {ic}]]) *index()* < Can also be used as a |method|: > GetObject()->index(what) -indexof({object}, {expr} [, {opt}]) *indexof()* - {object} must be a |List| or a |Blob|. +indexof({object}, {expr} [, {opts}]) *indexof()* + Returns the index of an item in {object} where {expr} is + v:true. {object} must be a |List| or a |Blob|. + If {object} is a |List|, evaluate {expr} for each item in the - List until the expression returns v:true and return the index - of this item. + List until the expression is v:true and return the index of + this item. If {object} is a |Blob| evaluate {expr} for each byte in the - Blob until the expression returns v:true and return the index - of this byte. + Blob until the expression is v:true and return the index of + this byte. {expr} must be a |string| or |Funcref|. @@ -4137,16 +4139,17 @@ indexof({object}, {expr} [, {opt}]) *indexof()* The function must return |TRUE| if the item is found and the search should stop. - The optional argument {opt} is a Dict and supports the + The optional argument {opts} is a Dict and supports the following items: - start start evaluating {expr} at the item with index - {start} (may be negative for an item relative - to the end). + startidx start evaluating {expr} at the item with this + index; may be negative for an item relative to + the end Returns -1 when {expr} evaluates to v:false for all the items. Example: > - :let l = [#{n: 10}, #{n: 20}, #{n: 30]] - :let idx = indexof(l, "v:val.n == 20") - :let idx = indexof(l, {i, v -> v.n == 30}) + :let l = [#{n: 10}, #{n: 20}, #{n: 30}] + :echo indexof(l, "v:val.n == 20") + :echo indexof(l, {i, v -> v.n == 30}) + :echo indexof(l, "v:val.n == 20", #{startidx: 1}) < Can also be used as a |method|: > mylist->indexof(expr) |