From e6be6c307a832d661d2a6269ad2d322e4bf5e9cc Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Thu, 5 Aug 2021 19:46:42 +0100 Subject: vim-patch:8.1.1803: all builtin functions are global Problem: All builtin functions are global. Solution: Add the method call operator ->. Implemented for a limited number of functions. https://github.com/vim/vim/commit/ac92e25a33c37ec5becbfffeccda136c73b761ac - Note that to *exactly* port hunk @@ -7376,18 +7444,19 from handle_subscript(), we need the :scriptversion patches (I have an open PR for those, but this patch works fine without them anyway). - Port call_internal_func() from v7.4.2058. - Adjust some error messages in tests, as they rely on the Blob patches. - Add a modeline to test_method.vim. Ignore the global_functions and base_method tables and prefer the current GPerf implementation. Instead, add an extra base_arg field to VimLFuncDef that holds the number of the argument to use as the base (1-indexed, so that 0 may be used to refer to functions that cannot be used as methods). This also means we support using any argument as a base from the get-go, rather than just the first (Vim includes this ability in future patches, however). To mark a function as usable as a method, use the "base" key as described in eval.lua. --- runtime/doc/eval.txt | 72 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index a76298c86c..eee401baa1 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -942,6 +942,8 @@ in any order. E.g., these are all possible: expr9[expr1].name expr9.name[expr1] expr9(expr1, ...)[expr1].name + expr9->(expr1, ...)[expr1] +Evaluation is always from left to right. expr8[expr1] item of String or |List| *expr-[]* *E111* @@ -1043,6 +1045,11 @@ expr8(expr1, ...) |Funcref| function call When expr8 is a |Funcref| type variable, invoke the function it refers to. +expr8->name([args]) method call *method* + +For global methods this is the same as: > + name(expr8 [, args]) +There can also be methods specifically for the type of "expr8". *expr9* number @@ -2603,6 +2610,8 @@ add({list}, {expr}) *add()* < Note that when {expr} is a |List| it is appended as a single item. Use |extend()| to concatenate |Lists|. Use |insert()| to add an item at another position. + Can also be used as a |method|: > + mylist->add(val1)->add(val2) and({expr}, {expr}) *and()* @@ -3215,6 +3224,8 @@ copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't changing an item changes the contents of both |Lists|. A |Dictionary| is copied in a similar way as a |List|. Also see |deepcopy()|. + Can also be used as a |method|: > + mylist->copy() cos({expr}) *cos()* Return the cosine of {expr}, measured in radians, as a |Float|. @@ -3249,6 +3260,8 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()* When {comp} is a string then the number of not overlapping occurrences of {expr} is returned. Zero is returned when {expr} is an empty string. + Can also be used as a |method|: > + mylist->count(val) *cscope_connection()* cscope_connection([{num} , {dbpath} [, {prepend}]]) @@ -3479,6 +3492,8 @@ empty({expr}) *empty()* A |List| or |Dictionary| is empty when it does not have any items. A Number is empty when its value is zero. Special variable is empty when it is |v:false| or |v:null|. + Can also be used as a |method|: > + mylist->empty() environ() *environ()* Return all of environment variables as dictionary. You can @@ -3794,6 +3809,8 @@ extend({expr1}, {expr2} [, {expr3}]) *extend()* fails. Returns {expr1}. + Can also be used as a |method|: > + mylist->extend(otherlist) feedkeys({string} [, {mode}]) *feedkeys()* Characters in {string} are queued for processing as if they @@ -3903,6 +3920,8 @@ filter({expr1}, {expr2}) *filter()* Funcref errors inside a function are ignored, unless it was defined with the "abort" flag. + Can also be used as a |method|: > + mylist->filter(expr2) finddir({name} [, {path} [, {count}]]) *finddir()* Find directory {name} in {path}. Supports both downwards and @@ -4159,6 +4178,8 @@ get({list}, {idx} [, {default}]) *get()* Get item {idx} from |List| {list}. When this item is not available return {default}. Return zero when {default} is omitted. + Can also be used as a |method|: > + mylist->get(idx) get({dict}, {key} [, {default}]) Get item with key {key} from |Dictionary| {dict}. When this item is not available return {default}. Return zero when @@ -5513,6 +5534,9 @@ insert({list}, {item} [, {idx}]) *insert()* Note that when {item} is a |List| it is inserted as a single item. Use |extend()| to concatenate |Lists|. + Can also be used as a |method|: > + mylist->insert(item) + interrupt() *interrupt()* Interrupt script execution. It works more or less like the user typing CTRL-C, most commands won't execute and control @@ -5580,6 +5604,8 @@ items({dict}) *items()* |List| item is a list with two items: the key of a {dict} entry and the value of this entry. The |List| is in arbitrary order. + Can also be used as a |method|: > + mydict->items() isnan({expr}) *isnan()* Return |TRUE| if {expr} is a float with value NaN. > @@ -5713,6 +5739,9 @@ join({list} [, {sep}]) *join()* converted into a string like with |string()|. The opposite function is |split()|. + Can also be used as a |method|: > + mylist->join() + json_decode({expr}) *json_decode()* Convert {expr} from JSON object. Accepts |readfile()|-style list as the input, as well as regular string. May output any @@ -5743,8 +5772,10 @@ json_encode({expr}) *json_encode()* keys({dict}) *keys()* Return a |List| with all the keys of {dict}. The |List| is in arbitrary order. + Can also be used as a |method|: > + mydict->keys() - *len()* *E701* +< *len()* *E701* len({expr}) The result is a Number, which is the length of the argument. When {expr} is a String or a Number the length in bytes is used, as with |strlen()|. @@ -5755,7 +5786,10 @@ len({expr}) The result is a Number, which is the length of the argument. |Dictionary| is returned. Otherwise an error is given. - *libcall()* *E364* *E368* + Can also be used as a |method|: > + mylist->len() + +< *libcall()* *E364* *E368* libcall({libname}, {funcname}, {argument}) Call function {funcname} in the run-time library {libname} with single argument {argument}. @@ -5938,6 +5972,8 @@ map({expr1}, {expr2}) *map()* Funcref errors inside a function are ignored, unless it was defined with the "abort" flag. + Can also be used as a |method|: > + mylist->map(expr2) maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()* When {dict} is omitted or zero: Return the rhs of mapping @@ -6273,6 +6309,9 @@ max({expr}) Return the maximum value of all items in {expr}. items in {expr} cannot be used as a Number this results in an error. An empty |List| or |Dictionary| results in zero. + Can also be used as a |method|: > + mylist->max() + menu_get({path}, {modes}) *menu_get()* Returns a |List| of |Dictionaries| describing |menus| (defined by |:menu|, |:amenu|, …), including |hidden-menus|. @@ -6327,7 +6366,10 @@ min({expr}) Return the minimum value of all items in {expr}. items in {expr} cannot be used as a Number this results in an error. An empty |List| or |Dictionary| results in zero. - *mkdir()* *E739* + Can also be used as a |method|: > + mylist->min() + +< *mkdir()* *E739* mkdir({name} [, {path} [, {prot}]]) Create directory {name}. If {path} is "p" then intermediate directories are created as @@ -7085,6 +7127,10 @@ remove({list}, {idx} [, {end}]) *remove()* Example: > :echo "last item: " . remove(mylist, -1) :call remove(mylist, 0, 9) + +< Can also be used as a |method|: > + mylist->remove(idx) + remove({dict}, {key}) Remove the entry from {dict} with key {key} and return it. Example: > @@ -7111,6 +7157,8 @@ repeat({expr}, {count}) *repeat()* :let longlist = repeat(['a', 'b'], 3) < Results in ['a', 'b', 'a', 'b', 'a', 'b']. + Can also be used as a |method|: > + mylist->repeat(count) resolve({filename}) *resolve()* *E655* On MS-Windows, when {filename} is a shortcut (a .lnk file), @@ -7130,6 +7178,8 @@ reverse({list}) Reverse the order of items in {list} in-place. Returns {list}. If you want a list to remain unmodified make a copy first: > :let revlist = reverse(copy(mylist)) +< Can also be used as a |method|: > + mylist->reverse() round({expr}) *round()* Round off {expr} to the nearest integral value and return it @@ -8209,7 +8259,10 @@ sort({list} [, {func} [, {dict}]]) *sort()* *E702* on numbers, text strings will sort next to each other, in the same order as they were originally. - Also see |uniq()|. + Can also be used as a |method|: > + mylist->sort() + +< Also see |uniq()|. Example: > func MyCompare(i1, i2) @@ -8504,6 +8557,9 @@ string({expr}) Return {expr} converted to a String. If {expr} is a Number, method, use |msgpackdump()| or |json_encode()| if you need to share data with other application. + Can also be used as a |method|: > + mylist->string() + *strlen()* strlen({expr}) The result is a Number, which is the length of the String {expr} in bytes. @@ -9149,6 +9205,9 @@ type({expr}) *type()* < To check if the v:t_ variables exist use this: > :if exists('v:t_number') +< Can also be used as a |method|: > + mylist->type() + undofile({name}) *undofile()* Return the name of the undo file that would be used for a file with name {name} when writing. This uses the 'undodir' @@ -9211,10 +9270,15 @@ uniq({list} [, {func} [, {dict}]]) *uniq()* *E882* < The default compare function uses the string representation of each item. For the use of {func} and {dict} see |sort()|. + Can also be used as a |method|: > + mylist->uniq() + values({dict}) *values()* Return a |List| with all the values of {dict}. The |List| is in arbitrary order. + Can also be used as a |method|: > + mydict->values() virtcol({expr}) *virtcol()* The result is a Number, which is the screen column of the file -- cgit From 003c8acc8a9863932430bfb51bee8403b964c19b Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 6 Aug 2021 17:09:47 +0100 Subject: vim-patch:8.1.1807: more functions can be used as a method Problem: More functions can be used as a method. Solution: Add append(), appendbufline(), assert_equal(), etc. Also add the :eval command. https://github.com/vim/vim/commit/25e42231d3ee27feec2568fa4be2aa2bfba82ae5 :eval is already ported. --- runtime/doc/eval.txt | 43 +++++++++++++++++++++++++++++++++---------- runtime/doc/testing.txt | 10 ++++++++-- 2 files changed, 41 insertions(+), 12 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index eee401baa1..070c94da3b 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -669,12 +669,14 @@ Expression syntax summary, from least to most significant: expr8[expr1 : expr1] substring of a String or sublist of a |List| expr8.name entry in a |Dictionary| expr8(expr1, ...) function call with |Funcref| variable + expr8->name(expr1, ...) |method| call |expr9| number number constant "string" string constant, backslash is special 'string' string constant, ' is doubled [expr1, ...] |List| {expr1: expr1, ...} |Dictionary| + #{key: expr1, ...} |Dictionary| &option option value (expr1) nested expression variable internal variable @@ -939,10 +941,10 @@ expr8 *expr8* ----- This expression is either |expr9| or a sequence of the alternatives below, in any order. E.g., these are all possible: - expr9[expr1].name - expr9.name[expr1] - expr9(expr1, ...)[expr1].name - expr9->(expr1, ...)[expr1] + expr8[expr1].name + expr8.name[expr1] + expr8(expr1, ...)[expr1].name + expr8->(expr1, ...)[expr1] Evaluation is always from left to right. @@ -1047,10 +1049,17 @@ When expr8 is a |Funcref| type variable, invoke the function it refers to. expr8->name([args]) method call *method* -For global methods this is the same as: > +For methods that are also available as global functions this is the same as: > name(expr8 [, args]) There can also be methods specifically for the type of "expr8". +"->name(" must not contain white space. There can be white space before "->" +and after the "(". + +This allows for chaining, using the type that the method returns: > + mylist->filter(filterexpr)->map(mapexpr)->sort()->join() +< + *expr9* number ------ @@ -2637,6 +2646,9 @@ append({lnum}, {text}) *append()* :let failed = append(line('$'), "# THE END") :let failed = append(0, ["Chapter 1", "the beginning"]) +< Can also be used as a |method| after a List: > + mylist->append(lnum) + appendbufline({expr}, {lnum}, {text}) *appendbufline()* Like |append()| but append the text in buffer {expr}. @@ -2655,8 +2667,10 @@ appendbufline({expr}, {lnum}, {text}) *appendbufline()* error message is given. Example: > :let failed = appendbufline(13, 0, "# THE START") < - *argc()* -argc([{winid}]) + Can also be used as a |method| after a List: > + mylist->appendbufline(buf, lnum) + +argc([{winid}]) *argc()* The result is the number of files in the argument list. See |arglist|. If {winid} is not supplied, the argument list of the current @@ -3518,6 +3532,9 @@ eval({string}) Evaluate {string} and return the result. Especially useful to them. Also works for |Funcref|s that refer to existing functions. + Can also be used as a |method|: > + argv->join()->eval() + eventhandler() *eventhandler()* Returns 1 when inside an event handler. That is that Vim got interrupted while waiting for the user to type a character, @@ -3864,7 +3881,11 @@ filereadable({file}) *filereadable()* expression, which is used as a String. If you don't care about the file being readable you can use |glob()|. - + {file} is used as-is, you may want to expand wildcards first: > + echo filereadable('~/.vimrc') + 0 + echo filereadable(expand('~/.vimrc')) + 1 filewritable({file}) *filewritable()* The result is a Number, which is 1 when a file with the @@ -10006,7 +10027,9 @@ This function can then be called with: > The recursiveness of user functions is restricted with the |'maxfuncdepth'| option. -It is also possible to use `:eval`. It does not support a range. +It is also possible to use `:eval`. It does not support a range, but does +allow for method chaining, e.g.: > + eval GetList()->Filter()->append('$') AUTOMATICALLY LOADING FUNCTIONS ~ @@ -10749,7 +10772,7 @@ text... < *:eval* :eval {expr} Evaluate {expr} and discard the result. Example: > - :eval append(Filter(Getlist()), '$') + :eval Getlist()->Filter()->append('$') < The expression is supposed to have a side effect, since the resulting value is not used. In the example diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index ef8d6b5ea9..eca2025ed7 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -69,7 +69,10 @@ assert_equal({expected}, {actual} [, {msg}]) < Will result in a string to be added to |v:errors|: test.vim line 12: Expected 'foo' but got 'bar' ~ - *assert_equalfile()* + Can also be used as a |method|: > + mylist->assert_equal([1, 2, 3]) + +< *assert_equalfile()* assert_equalfile({fname-one}, {fname-two}) When the files {fname-one} and {fname-two} do not contain exactly the same text an error message is added to |v:errors|. @@ -145,7 +148,10 @@ assert_notequal({expected}, {actual} [, {msg}]) |v:errors| when {expected} and {actual} are equal. Also see |assert-return|. - *assert_notmatch()* + Can also be used as a |method|: > + mylist->assert_notequal([1, 2, 3]) + +< *assert_notmatch()* assert_notmatch({pattern}, {actual} [, {msg}]) The opposite of `assert_match()`: add an error message to |v:errors| when {pattern} matches {actual}. -- cgit From aa2dc8b7b4e0e86c9102f2df6b670317c5693657 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 6 Aug 2021 18:10:30 +0100 Subject: vim-patch:8.1.1809: more functions can be used as a method Problem: More functions can be used as a method. Solution: Add has_key(), split(), str2list(), etc. https://github.com/vim/vim/commit/a74e4946de074d2916e3d6004f7fa1810d12dda9 --- runtime/doc/eval.txt | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 070c94da3b..a5940a963c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3274,6 +3274,7 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()* When {comp} is a string then the number of not overlapping occurrences of {expr} is returned. Zero is returned when {expr} is an empty string. + Can also be used as a |method|: > mylist->count(val) @@ -5212,6 +5213,9 @@ has_key({dict}, {key}) *has_key()* The result is a Number, which is TRUE if |Dictionary| {dict} has an entry with key {key}. FALSE otherwise. + Can also be used as a |method|: > + mydict->has_key(key) + haslocaldir([{winnr}[, {tabnr}]]) *haslocaldir()* The result is a Number, which is 1 when the tabpage or window has set a local path via |:tcd| or |:lcd|, otherwise 0. @@ -8376,6 +8380,8 @@ split({expr} [, {pattern} [, {keepempty}]]) *split()* :let items = split(line, ':', 1) < The opposite function is |join()|. + Can also be used as a |method|: > + GetString()->split() sqrt({expr}) *sqrt()* Return the non-negative square root of Float {expr} as a @@ -8454,12 +8460,18 @@ str2list({expr} [, {utf8}]) *str2list()* properly: > str2list("á") returns [97, 769] +< Can also be used as a |method|: > + GetString()->str2list() + str2nr({expr} [, {base}]) *str2nr()* Convert string {expr} to a number. {base} is the conversion base, it can be 2, 8, 10 or 16. + When {base} is omitted base 10 is used. This also means that a leading zero doesn't cause octal conversion to be used, as - with the default String to Number conversion. + with the default String to Number conversion. Example: > + let nr = str2nr('123') +< When {base} is 16 a leading "0x" or "0X" is ignored. With a different base the result will be zero. Similarly, when {base} is 8 a leading "0" is ignored, and when {base} is 2 a leading @@ -8590,6 +8602,9 @@ strlen({expr}) The result is a Number, which is the length of the String |strchars()|. Also see |len()|, |strdisplaywidth()| and |strwidth()|. + Can also be used as a |method|: > + GetString()->strlen() + strpart({src}, {start} [, {len} [, {chars}]]) *strpart()* The result is a String, which is part of {src}, starting from byte {start}, with the byte length {len}. @@ -8664,6 +8679,9 @@ strtrans({expr}) *strtrans()* < This displays a newline in register a as "^@" instead of starting a new line. + Can also be used as a |method|: > + GetString()->strtrans() + strwidth({expr}) *strwidth()* The result is a Number, which is the number of display cells String {expr} occupies. A Tab character is counted as one @@ -8672,6 +8690,9 @@ strwidth({expr}) *strwidth()* Ambiguous, this function's return value depends on 'ambiwidth'. Also see |strlen()|, |strdisplaywidth()| and |strchars()|. + Can also be used as a |method|: > + GetString()->strwidth() + submatch({nr} [, {list}]) *submatch()* *E935* Only for an expression in a |:substitute| command or substitute() function. @@ -8739,6 +8760,9 @@ substitute({expr}, {pat}, {sub}, {flags}) *substitute()* |submatch()| returns. Example: > :echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g') +< Can also be used as a |method|: > + GetString()->substitute(pat, sub, flags) + swapinfo({fname}) *swapinfo()* The result is a dictionary, which holds information about the swapfile {fname}. The available fields are: @@ -8823,12 +8847,18 @@ synIDattr({synID}, {what} [, {mode}]) *synIDattr()* cursor): > :echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg") < + Can also be used as a |method|: > + :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") + synIDtrans({synID}) *synIDtrans()* The result is a Number, which is the translated syntax ID of {synID}. This is the syntax group ID of what is being used to highlight the character. Highlight links given with ":highlight link" are followed. + Can also be used as a |method|: > + :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg") + synconcealed({lnum}, {col}) *synconcealed()* The result is a |List| with currently three items: 1. The first item in the list is 0 if the character at the @@ -8925,6 +8955,8 @@ system({cmd} [, {input}]) *system()* *E677* Unlike ":!cmd" there is no automatic check for changed files. Use |:checktime| to force a check. + Can also be used as a |method|: > + :echo GetCmd()->system() systemlist({cmd} [, {input} [, {keepempty}]]) *systemlist()* Same as |system()|, but returns a |List| with lines (parts of @@ -8940,6 +8972,8 @@ systemlist({cmd} [, {input} [, {keepempty}]]) *systemlist()* < Returns an empty string on error. + Can also be used as a |method|: > + :echo GetCmd()->systemlist() tabpagebuflist([{arg}]) *tabpagebuflist()* The result is a |List|, where each item is the number of the -- cgit From 32589341a41f49a11e68d5b080271115787f2dc5 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 6 Aug 2021 21:04:17 +0100 Subject: vim-patch:8.1.1828: not strict enough checking syntax of method invocation Problem: Not strict enough checking syntax of method invocation. Solution: Check there is no white space inside ->method(. https://github.com/vim/vim/commit/5184132ec015f5889a3195d911e609d214f06bed --- runtime/doc/eval.txt | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index a5940a963c..b397328bc0 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1053,12 +1053,19 @@ For methods that are also available as global functions this is the same as: > name(expr8 [, args]) There can also be methods specifically for the type of "expr8". -"->name(" must not contain white space. There can be white space before "->" -and after the "(". - -This allows for chaining, using the type that the method returns: > +This allows for chaining, passing the value that one method returns to the +next method: > mylist->filter(filterexpr)->map(mapexpr)->sort()->join() < + *E274* +"->name(" must not contain white space. There can be white space before the +"->" and after the "(", thus you can split the lines like this: > + mylist + \ ->filter(filterexpr) + \ ->map(mapexpr) + \ ->sort() + \ ->join() +< *expr9* number -- cgit From 5811390f82c51a4bb15b2e8901e6b5a1d453480a Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 6 Aug 2021 21:08:20 +0100 Subject: vim-patch:8.1.1834: cannot use a lambda as a method Problem: Cannot use a lambda as a method. Solution: Implement ->{lambda}(). (closes vim/vim#4768) https://github.com/vim/vim/commit/22a0c0c4ecd23b6c43f79ba9b92899ca0b426e29 Add an additional lua_funcname argument to call_func_rettv() to maintain support for v:lua. A memory leak was introduced with this patch that was fixed in v8.1.2107. --- runtime/doc/eval.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index b397328bc0..321da32bf0 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1047,7 +1047,8 @@ expr8(expr1, ...) |Funcref| function call When expr8 is a |Funcref| type variable, invoke the function it refers to. -expr8->name([args]) method call *method* +expr8->name([args]) method call *method* *->* +expr8->{lambda}([args]) For methods that are also available as global functions this is the same as: > name(expr8 [, args]) @@ -1057,6 +1058,9 @@ This allows for chaining, passing the value that one method returns to the next method: > mylist->filter(filterexpr)->map(mapexpr)->sort()->join() < +Example of using a lambda: > + GetPercentage->{x -> x * 100}()->printf('%d%%') + *E274* "->name(" must not contain white space. There can be white space before the "->" and after the "(", thus you can split the lines like this: > -- cgit From f03dd22f0d37af88f40a27c694c3265026178e80 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 01:08:22 +0100 Subject: vim-patch:8.1.1835: cannot use printf() as a method Problem: Cannot use printf() as a method. Solution: Pass the base as the second argument to printf(). https://github.com/vim/vim/commit/fd8ca21b3ff207e44891aef922935d4adcd140cf --- runtime/doc/eval.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 321da32bf0..e180836917 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -6653,7 +6653,11 @@ printf({fmt}, {expr1} ...) *printf()* < May result in: " 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~ - Often used items are: + When used as a |method| the base is passed as the second + argument: > + Compute()->printf("result: %d") + +< Often used items are: %s string %6S string right-aligned in 6 display cells %6s string right-aligned in 6 bytes -- cgit From 287a77ef51a7a12813d3fa6e1c49c595e5951ba5 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 01:28:52 +0100 Subject: vim-patch:8.1.1861: only some assert functions can be used as a method Problem: Only some assert functions can be used as a method. Solution: Allow using most assert functions as a method. https://github.com/vim/vim/commit/24278d2407dfbc8d93eb36593cdd006ff5d86f94 Port tests to assert_spec.lua. --- runtime/doc/testing.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index eca2025ed7..fc841dfc9c 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -53,6 +53,9 @@ assert_beeps({cmd}) *assert_beeps()* Also see |assert_fails()|, |assert_nobeep()| and |assert-return|. + Can also be used as a |method|: > + GetCmd()->assert_beeps() +< *assert_equal()* assert_equal({expected}, {actual} [, {msg}]) When {expected} and {actual} are not equal an error message is @@ -100,6 +103,9 @@ assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()* Note that beeping is not considered an error, and some failing commands only beep. Use |assert_beeps()| for those. + Can also be used as a |method|: > + GetCmd()->assert_fails('E99:') + assert_false({actual} [, {msg}]) *assert_false()* When {actual} is not false an error message is added to |v:errors|, like with |assert_equal()|. @@ -109,6 +115,9 @@ assert_false({actual} [, {msg}]) *assert_false()* When {msg} is omitted an error in the form "Expected False but got {actual}" is produced. + Can also be used as a |method|: > + GetResult()->assert_false() + assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()* This asserts number and |Float| values. When {actual} is lower than {lower} or higher than {upper} an error message is added @@ -137,6 +146,9 @@ assert_match({pattern}, {actual} [, {msg}]) < Will result in a string to be added to |v:errors|: test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~ + Can also be used as a |method|: > + getFile()->assert_match('foo.*') +< assert_nobeep({cmd}) *assert_nobeep()* Run {cmd} and add an error message to |v:errors| if it produces a beep or visual bell. @@ -157,6 +169,9 @@ assert_notmatch({pattern}, {actual} [, {msg}]) |v:errors| when {pattern} matches {actual}. Also see |assert-return|. + Can also be used as a |method|: > + getFile()->assert_notmatch('bar.*') + assert_report({msg}) *assert_report()* Report a test failure directly, using {msg}. Always returns one. @@ -170,5 +185,8 @@ assert_true({actual} [, {msg}]) *assert_true()* When {msg} is omitted an error in the form "Expected True but got {actual}" is produced. + Can also be used as a |method|: > + GetResult()->assert_true() +< vim:tw=78:ts=8:noet:ft=help:norl: -- cgit From 41dbd3a2e05f5f4d59e076f8b8c82ad974d2bbd5 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 16:27:23 +0100 Subject: vim-patch:8.1.1879: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make float functions usable as a method. https://github.com/vim/vim/commit/93cf85f9ef02931de3f8c8e536a137da0b48b7dc Fix atan2() doc typo (patch referred to it as atan()). Adjust Test_fmod() method test to expect "str2float('nan')". --- runtime/doc/eval.txt | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index e180836917..814931ff2b 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -1060,7 +1060,14 @@ next method: > < Example of using a lambda: > GetPercentage->{x -> x * 100}()->printf('%d%%') - +< +When using -> the |expr7| operators will be applied first, thus: > + -1.234->string() +Is equivalent to: > + (-1.234)->string() +And NOT: > + -(1.234->string()) +< *E274* "->name(" must not contain white space. There can be white space before the "->" and after the "(", thus you can split the lines like this: > @@ -2609,6 +2616,8 @@ abs({expr}) *abs()* echo abs(-4) < 4 + Can also be used as a |method|: > + Compute()->abs() acos({expr}) *acos()* Return the arc cosine of {expr} measured in radians, as a @@ -2621,6 +2630,8 @@ acos({expr}) *acos()* :echo acos(-0.5) < 2.094395 + Can also be used as a |method|: > + Compute()->acos() add({list}, {expr}) *add()* Append the item {expr} to |List| {list}. Returns the @@ -2630,10 +2641,10 @@ add({list}, {expr}) *add()* < Note that when {expr} is a |List| it is appended as a single item. Use |extend()| to concatenate |Lists|. Use |insert()| to add an item at another position. + Can also be used as a |method|: > mylist->add(val1)->add(val2) - and({expr}, {expr}) *and()* Bitwise AND on the two arguments. The arguments are converted to a number. A List, Dict or Float argument causes an error. @@ -2735,6 +2746,9 @@ asin({expr}) *asin()* :echo asin(-0.5) < -0.523599 + Can also be used as a |method|: > + Compute()->asin() + assert_ functions are documented here: |assert-functions-details| @@ -2749,6 +2763,8 @@ atan({expr}) *atan()* :echo atan(-4.01) < -1.326405 + Can also be used as a |method|: > + Compute()->atan() atan2({expr1}, {expr2}) *atan2()* Return the arc tangent of {expr1} / {expr2}, measured in @@ -2760,6 +2776,8 @@ atan2({expr1}, {expr2}) *atan2()* :echo atan2(1, -1) < 2.356194 + Can also be used as a |method|: > + Compute()->atan2(1) *browse()* browse({save}, {title}, {initdir}, {default}) @@ -2966,6 +2984,9 @@ ceil({expr}) *ceil()* echo ceil(4.0) < 4.0 + Can also be used as a |method|: > + Compute()->ceil() + changenr() *changenr()* Return the number of the most recent change. This is the same number as what is displayed with |:undolist| and can be used @@ -3261,6 +3282,8 @@ cos({expr}) *cos()* :echo cos(-4.01) < -0.646043 + Can also be used as a |method|: > + Compute()->cos() cosh({expr}) *cosh()* Return the hyperbolic cosine of {expr} as a |Float| in the range @@ -3272,6 +3295,8 @@ cosh({expr}) *cosh()* :echo cosh(-0.5) < -1.127626 + Can also be used as a |method|: > + Compute()->cosh() count({comp}, {expr} [, {ic} [, {start}]]) *count()* Return the number of times an item with value {expr} appears @@ -3704,6 +3729,9 @@ exp({expr}) *exp()* :echo exp(-1) < 0.367879 + Can also be used as a |method|: > + Compute()->exp() + debugbreak({pid}) *debugbreak()* Specifically used to interrupt a program being debugged. It will cause process {pid} to get a SIGTRAP. Behavior for other @@ -4017,6 +4045,8 @@ float2nr({expr}) *float2nr()* echo float2nr(1.0e-100) < 0 + Can also be used as a |method|: > + Compute()->float2nr() floor({expr}) *floor()* Return the largest integral value less than or equal to @@ -4030,6 +4060,8 @@ floor({expr}) *floor()* echo floor(4.0) < 4.0 + Can also be used as a |method|: > + Compute()->floor() fmod({expr1}, {expr2}) *fmod()* Return the remainder of {expr1} / {expr2}, even if the @@ -4045,6 +4077,8 @@ fmod({expr1}, {expr2}) *fmod()* :echo fmod(-12.33, 1.22) < -0.13 + Can also be used as a |method|: > + Compute()->fmod(1.22) fnameescape({string}) *fnameescape()* Escape {string} for use as file name command argument. All @@ -5605,6 +5639,9 @@ isinf({expr}) *isinf()* :echo isinf(-1.0 / 0.0) < -1 + Can also be used as a |method|: > + Compute()->isinf() + islocked({expr}) *islocked()* *E786* The result is a Number, which is |TRUE| when {expr} is the name of a locked variable. @@ -5648,6 +5685,9 @@ isnan({expr}) *isnan()* echo isnan(0.0 / 0.0) < 1 + Can also be used as a |method|: > + Compute()->isnan() + jobpid({job}) *jobpid()* Return the PID (process id) of |job-id| {job}. @@ -5950,6 +5990,8 @@ log({expr}) *log()* :echo log(exp(5)) < 5.0 + Can also be used as a |method|: > + Compute()->log() log10({expr}) *log10()* Return the logarithm of Float {expr} to base 10 as a |Float|. @@ -5960,6 +6002,9 @@ log10({expr}) *log10()* :echo log10(0.01) < -2.0 + Can also be used as a |method|: > + Compute()->log10() + luaeval({expr}[, {expr}]) Evaluate Lua expression {expr} and return its result converted to Vim data structures. See |lua-eval| for more details. @@ -6637,6 +6682,9 @@ pow({x}, {y}) *pow()* :echo pow(32, 0.20) < 2.0 + Can also be used as a |method|: > + Compute()->pow(3) + prevnonblank({lnum}) *prevnonblank()* Return the line number of the first line at or above {lnum} that is not blank. Example: > @@ -7234,6 +7282,9 @@ round({expr}) *round()* echo round(-4.5) < -5.0 + Can also be used as a |method|: > + Compute()->round() + rpcnotify({channel}, {event}[, {args}...]) *rpcnotify()* Sends {event} to {channel} via |RPC| and returns immediately. If {channel} is 0, the event is broadcast to all channels. @@ -8210,6 +8261,8 @@ sin({expr}) *sin()* :echo sin(-4.01) < 0.763301 + Can also be used as a |method|: > + Compute()->sin() sinh({expr}) *sinh()* Return the hyperbolic sine of {expr} as a |Float| in the range @@ -8221,6 +8274,9 @@ sinh({expr}) *sinh()* :echo sinh(-0.9) < -1.026517 + Can also be used as a |method|: > + Compute()->sinh() + sockconnect({mode}, {address}, {opts}) *sockconnect()* Connect a socket to an address. If {mode} is "pipe" then {address} should be the path of a named pipe. If {mode} is @@ -8410,6 +8466,8 @@ sqrt({expr}) *sqrt()* < nan "nan" may be different, it depends on system libraries. + Can also be used as a |method|: > + Compute()->sqrt() stdioopen({opts}) *stdioopen()* With |--headless| this opens stdin and stdout as a |channel|. @@ -8461,6 +8519,9 @@ str2float({expr}) *str2float()* 12.0. You can strip out thousands separators with |substitute()|: > let f = str2float(substitute(text, ',', '', 'g')) +< + Can also be used as a |method|: > + let f = text->substitute(',', '', 'g')->str2float() str2list({expr} [, {utf8}]) *str2list()* Return a list containing the number values which represent @@ -9112,6 +9173,8 @@ tan({expr}) *tan()* :echo tan(-4.01) < -1.181502 + Can also be used as a |method|: > + Compute()->tan() tanh({expr}) *tanh()* Return the hyperbolic tangent of {expr} as a |Float| in the @@ -9123,6 +9186,8 @@ tanh({expr}) *tanh()* :echo tanh(-1) < -0.761594 + Can also be used as a |method|: > + Compute()->tanh() *timer_info()* timer_info([{id}]) @@ -9249,6 +9314,9 @@ trunc({expr}) *trunc()* echo trunc(4.0) < 4.0 + Can also be used as a |method|: > + Compute()->trunc() + type({expr}) *type()* The result is a Number representing the type of {expr}. Instead of using the number directly, it is better to use the -- cgit From 5fbc1a49c719c0c93fa73277ac30d17f797d096d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 17:06:08 +0100 Subject: vim-patch:8.1.1888: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make various functions usable as a method. https://github.com/vim/vim/commit/073e4b92e613d22ce7b16e0fbf5c0e40cb5f9b2c test_popup.vim already has the changes from this patch (they're N/A anyway). --- runtime/doc/eval.txt | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 814931ff2b..511d072366 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2650,6 +2650,8 @@ and({expr}, {expr}) *and()* to a number. A List, Dict or Float argument causes an error. Example: > :let flag = and(bits, 0x80) +< Can also be used as a |method|: > + :let flag = bits->and(0x80) api_info() *api_info()* Returns Dictionary of |api-metadata|. @@ -2788,8 +2790,8 @@ browse({save}, {title}, {initdir}, {default}) {title} title for the requester {initdir} directory to start browsing in {default} default file name - When the "Cancel" button is hit, something went wrong, or - browsing is not possible, an empty string is returned. + An empty string is returned when the "Cancel" button is hit, + something went wrong, or browsing is not possible. *browsedir()* browsedir({title}, {initdir}) @@ -2811,6 +2813,8 @@ bufadd({name}) *bufadd()* created buffer. When {name} is an empty string then a new buffer is always created. The buffer will not have' 'buflisted' set. +< Can also be used as a |method|: > + let bufnr = 'somename'->bufadd() bufexists({expr}) *bufexists()* The result is a Number, which is |TRUE| if a buffer called @@ -2834,11 +2838,17 @@ bufexists({expr}) *bufexists()* Use "bufexists(0)" to test for the existence of an alternate file name. + Can also be used as a |method|: > + let exists = 'somename'->bufexists() + buflisted({expr}) *buflisted()* The result is a Number, which is |TRUE| if a buffer called {expr} exists and is listed (has the 'buflisted' option set). The {expr} argument is used like with |bufexists()|. + Can also be used as a |method|: > + let listed = 'somename'->buflisted() + bufload({expr}) *bufload()* Ensure the buffer {expr} is loaded. When the buffer name refers to an existing file then the file is read. Otherwise @@ -2848,15 +2858,21 @@ bufload({expr}) *bufload()* there will be no dialog, the buffer will be loaded anyway. The {expr} argument is used like with |bufexists()|. + Can also be used as a |method|: > + eval 'somename'->bufload() + bufloaded({expr}) *bufloaded()* The result is a Number, which is |TRUE| if a buffer called {expr} exists and is loaded (shown in a window or hidden). The {expr} argument is used like with |bufexists()|. + Can also be used as a |method|: > + let loaded = 'somename'->bufloaded() + bufname([{expr}]) *bufname()* The result is the name of a buffer, as it is displayed by the ":ls" command. -+ If {expr} is omitted the current buffer is used. + If {expr} is omitted the current buffer is used. If {expr} is a Number, that buffer number's name is given. Number zero is the alternate buffer for the current window. If {expr} is a String, it is used as a |file-pattern| to match @@ -2875,6 +2891,9 @@ bufname([{expr}]) *bufname()* If the {expr} is a String, but you want to use it as a buffer number, force it to be a Number by adding zero to it: > :echo bufname("3" + 0) +< Can also be used as a |method|: > + echo bufnr->bufname() + < If the buffer doesn't exist, or doesn't have a name, an empty string is returned. > bufname("#") alternate buffer name @@ -2897,6 +2916,9 @@ bufnr([{expr} [, {create}]]) number necessarily exist, because ":bwipeout" may have removed them. Use bufexists() to test for the existence of a buffer. + Can also be used as a |method|: > + echo bufref->bufnr() + bufwinid({expr}) *bufwinid()* The result is a Number, which is the |window-ID| of the first window associated with buffer {expr}. For the use of {expr}, @@ -5624,6 +5646,8 @@ invert({expr}) *invert()* Bitwise invert. The argument is converted to a number. A List, Dict or Float argument causes an error. Example: > :let bits = invert(bits) +< Can also be used as a |method|: > + :let bits = bits->invert() isdirectory({directory}) *isdirectory()* The result is a Number, which is |TRUE| when a directory @@ -6645,7 +6669,8 @@ or({expr}, {expr}) *or()* to a number. A List, Dict or Float argument causes an error. Example: > :let bits = or(bits, 0x80) - +< Can also be used as a |method|: > + :let bits = bits->or(0x80) pathshorten({expr}) *pathshorten()* Shorten directory names in the path {expr} and return the @@ -9807,6 +9832,8 @@ xor({expr}, {expr}) *xor()* to a number. A List, Dict or Float argument causes an error. Example: > :let bits = xor(bits, 0x80) +< Can also be used as a |method|: > + :let bits = bits->xor(0x80) < -- cgit From 7925f0b6330c18c9391d02f844cd17b41fbb3d2e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 17:53:43 +0100 Subject: vim-patch:8.1.1909: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make a few more functions usable as a method. https://github.com/vim/vim/commit/e49fbff384e45dd17fed72321c26937edf6de16b --- runtime/doc/eval.txt | 17 ++++++++++++----- runtime/doc/testing.txt | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 511d072366..5754742c6d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2929,18 +2929,22 @@ bufwinid({expr}) *bufwinid()* < Only deals with the current tab page. + Can also be used as a |method|: > + FindBuffer()->bufwinid() + bufwinnr({expr}) *bufwinnr()* - The result is a Number, which is the number of the first - window associated with buffer {expr}. For the use of {expr}, - see |bufname()| above. If buffer {expr} doesn't exist or - there is no such window, -1 is returned. Example: > + Like |bufwinid()| but return the window number instead of the + |window-ID|. + If buffer {expr} doesn't exist or there is no such window, -1 + is returned. Example: > echo "A window containing buffer 1 is " . (bufwinnr(1)) < The number can be used with |CTRL-W_w| and ":wincmd w" |:wincmd|. - Only deals with the current tab page. + Can also be used as a |method|: > + FindBuffer()->bufwinnr() byte2line({byte}) *byte2line()* Return the line number that contains the character at byte @@ -9618,6 +9622,9 @@ winbufnr({nr}) The result is a Number, which is the number of the buffer When window {nr} doesn't exist, -1 is returned. Example: > :echo "The file in the current window is " . bufname(winbufnr(0)) +< + Can also be used as a |method|: > + FindWindow()->winbufnr()->bufname() < *wincol()* wincol() The result is a Number, which is the virtual column of the diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index fc841dfc9c..3b59dfa908 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -83,6 +83,9 @@ assert_equalfile({fname-one}, {fname-two}) When {fname-one} or {fname-two} does not exist the error will mention that. + Can also be used as a |method|: > + GetLog()->assert_equalfile('expected.log') + assert_exception({error} [, {msg}]) *assert_exception()* When v:exception does not contain the string {error} an error message is added to |v:errors|. Also see |assert-return|. @@ -172,10 +175,15 @@ assert_notmatch({pattern}, {actual} [, {msg}]) Can also be used as a |method|: > getFile()->assert_notmatch('bar.*') + assert_report({msg}) *assert_report()* Report a test failure directly, using {msg}. Always returns one. + Can also be used as a |method|: > + GetMessage()->assert_report() + + assert_true({actual} [, {msg}]) *assert_true()* When {actual} is not true an error message is added to |v:errors|, like with |assert_equal()|. -- cgit From 56b56a76e8294a319d2db32581f82421d4a4d446 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 18:09:39 +0100 Subject: vim-patch:8.1.1911: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make a few more functions usable as a method. https://github.com/vim/vim/commit/64b4d73524b9a2304d89b87529cd8d3cef14b856 Note that the old-style version of Test_byteidx() was already translated to a Lua test in 069_multibyte_formatting_spec.lua. Keep both versions, using Test_byteidx() to mainly test the method call syntax for byteidx() and byteidxcomp(). --- runtime/doc/eval.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 5754742c6d..5cf0c0d239 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2954,6 +2954,9 @@ byte2line({byte}) *byte2line()* one. Also see |line2byte()|, |go| and |:goto|. + Can also be used as a |method|: > + GetOffset()->byte2line() + byteidx({expr}, {nr}) *byteidx()* Return byte index of the {nr}'th character in the string {expr}. Use zero for the first character, it then returns @@ -2976,6 +2979,9 @@ byteidx({expr}, {nr}) *byteidx()* If there are exactly {nr} characters the length of the string in bytes is returned. + Can also be used as a |method|: > + GetName()->byteidx(idx) + byteidxcomp({expr}, {nr}) *byteidxcomp()* Like byteidx(), except that a composing character is counted as a separate character. Example: > @@ -2989,6 +2995,9 @@ byteidxcomp({expr}, {nr}) *byteidxcomp()* Only works differently from byteidx() when 'encoding' is set to a Unicode encoding. + Can also be used as a |method|: > + GetName()->byteidxcomp(idx) + call({func}, {arglist} [, {dict}]) *call()* *E699* Call function {func} with the items in |List| {arglist} as arguments. @@ -2998,6 +3007,9 @@ call({func}, {arglist} [, {dict}]) *call()* *E699* {dict} is for functions with the "dict" attribute. It will be used to set the local variable "self". |Dictionary-function| + Can also be used as a |method|: > + GetFunc()->call([arg, arg], dict) + ceil({expr}) *ceil()* Return the smallest integral value greater than or equal to {expr} as a |Float| (round up). -- cgit From 5d883498179651c6da95b10959e83cf8707eaa4f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 7 Aug 2021 22:39:23 +0100 Subject: feat(eval): partially port v8.1.1915 Cannot be fully ported as chdir() hasn't been ported yet. --- runtime/doc/eval.txt | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 5cf0c0d239..f70eb9e759 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3074,6 +3074,9 @@ char2nr({expr} [, {utf8}]) *char2nr()* A combining character is a separate character. |nr2char()| does the opposite. + Can also be used as a |method|: > + GetChar()->char2nr() + *charidx()* charidx({string}, {idx} [, {countcc}]) Return the character index of the byte at {idx} in {string}. @@ -3105,12 +3108,18 @@ cindent({lnum}) *cindent()* When {lnum} is invalid -1 is returned. See |C-indenting|. + Can also be used as a |method|: > + GetLnum()->cindent() + clearmatches([{win}]) *clearmatches()* Clears all matches previously defined for the current window by |matchadd()| and the |:match| commands. If {win} is specified, use the window with this number or window ID instead of the current window. + Can also be used as a |method|: > + GetWin()->clearmatches() +< *col()* col({expr}) The result is a Number, which is the byte index of the column position given with {expr}. The accepted positions are: @@ -3146,6 +3155,9 @@ col({expr}) The result is a Number, which is the byte index of the column \:set ve=all \:echo col(".") . "\n" \let &ve = save_ve + +< Can also be used as a |method|: > + GetPos()->col() < complete({startcol}, {matches}) *complete()* *E785* @@ -3177,6 +3189,10 @@ complete({startcol}, {matches}) *complete()* *E785* < This isn't very useful, but it shows how it works. Note that an empty string is returned to avoid a zero being inserted. + Can also be used as a |method|, the second argument is passed + in: > + GetMatches()->complete(col('.')) + complete_add({expr}) *complete_add()* Add {expr} to the list of matches. Only to be used by the function specified with the 'completefunc' option. @@ -3186,6 +3202,9 @@ complete_add({expr}) *complete_add()* See |complete-functions| for an explanation of {expr}. It is the same as one item in the list that 'omnifunc' would return. + Can also be used as a |method|: > + GetMoreMatches()->complete_add() + complete_check() *complete_check()* Check for a key typed while looking for completion matches. This is to be used when looking for matches takes some time. @@ -3246,6 +3265,9 @@ complete_info([{what}]) call complete_info(['mode']) " Get only 'mode' and 'pum_visible' call complete_info(['mode', 'pum_visible']) + +< Can also be used as a |method|: > + GetItems()->complete_info() < *confirm()* confirm({msg} [, {choices} [, {default} [, {type}]]]) @@ -3299,6 +3321,9 @@ confirm({msg} [, {choices} [, {default} [, {type}]]]) don't fit, a vertical layout is used anyway. For some systems the horizontal layout is always used. + Can also be used as a |method|in: > + BuildMessage()->confirm("&Yes\n&No") + *copy()* copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't different from using {expr} directly. @@ -3447,6 +3472,8 @@ cursor({list}) position within a or after the last character. Returns 0 when the position could be set, -1 otherwise. + Can also be used as a |method|: > + GetCursorPos()->cursor() deepcopy({expr}[, {noref}]) *deepcopy()* *E698* Make a copy of {expr}. For Numbers and Strings this isn't @@ -3468,6 +3495,9 @@ deepcopy({expr}[, {noref}]) *deepcopy()* *E698* {noref} set to 1 will fail. Also see |copy()|. + Can also be used as a |method|: > + GetObject()->deepcopy() + delete({fname} [, {flags}]) *delete()* Without {flags} or with {flags} empty: Deletes the file by the name {fname}. This also works when {fname} is a symbolic link. @@ -3485,6 +3515,9 @@ delete({fname} [, {flags}]) *delete()* operation was successful and -1/true when the deletion failed or partly failed. + Can also be used as a |method|: > + GetName()->delete() + deletebufline({expr}, {first}[, {last}]) *deletebufline()* Delete lines {first} to {last} (inclusive) from buffer {expr}. If {last} is omitted then delete line {first} only. @@ -3499,6 +3532,9 @@ deletebufline({expr}, {first}[, {last}]) *deletebufline()* when using |line()| this refers to the current buffer. Use "$" to refer to the last line in buffer {expr}. + Can also be used as a |method|: > + GetBuffer()->deletebufline(1) + dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()* Adds a watcher to a dictionary. A dictionary watcher is identified by three components: @@ -3565,6 +3601,9 @@ diff_filler({lnum}) *diff_filler()* line, "'m" mark m, etc. Returns 0 if the current window is not in diff mode. + Can also be used as a |method|: > + GetLnum()->diff_filler() + diff_hlID({lnum}, {col}) *diff_hlID()* Returns the highlight ID for diff mode at line {lnum} column {col} (byte index). When the current line does not have a @@ -3576,6 +3615,9 @@ diff_hlID({lnum}, {col}) *diff_hlID()* The highlight ID can be used with |synIDattr()| to obtain syntax information about the highlighting. + Can also be used as a |method|: > + GetLnum()->diff_hlID(col) + empty({expr}) *empty()* Return the Number 1 if {expr} is empty, zero otherwise. A |List| or |Dictionary| is empty when it does not have any @@ -3776,6 +3818,9 @@ debugbreak({pid}) *debugbreak()* processes is undefined. See |terminal-debugger|. {Sends a SIGINT to a process {pid} other than MS-Windows} + Can also be used as a |method|: > + GetPid()->debugbreak() + expand({expr} [, {nosuf} [, {list}]]) *expand()* Expand wildcards and the following special keywords in {expr}. 'wildignorecase' applies. -- cgit From b2994e35c9357a8144beaf27e1a8ea4dd133f5d4 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Wed, 11 Aug 2021 13:47:33 +0100 Subject: feat(v:lua): support calling v:lua as a method --- runtime/doc/lua.txt | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'runtime') diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index fd1bedd8ef..1bbfde1980 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -391,6 +391,10 @@ where the args are converted to Lua values. The expression > is equivalent to the Lua chunk > return somemod.func(...) +The `v:lua` prefix may be used to call Lua functions as |method|s. For +example: > + arg1->v:lua.somemod.func(arg2) + You can use `v:lua` in "func" options like 'tagfunc', 'omnifunc', etc. For example consider the following Lua omnifunc handler: > -- cgit