From fa9076f276c16f64b96cd734f511e682a8621f6f Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 31 Oct 2021 16:26:48 +0000 Subject: [PATCH 01/16] vim-patch:8.1.1925: 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/4c313b13fb7bfa694ec6d2a13175e8650c007b2a The rest of this patch was ported in https://github.com/neovim/neovim/commit/3137c7d63574a86ddc44f11c839e8e58c2994bf9 N/A patches for version.c: vim-patch:8.1.2012: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make terminal functions usable as a method. Fix term_getattr(). https://github.com/vim/vim/commit/7ee80f766130f22598c928415c92ec612a8f18cf vim-patch:8.2.3576: some functions are not documented for use with a method Problem: Some functions are not documented for use with a method. Solution: Add examples. Fix that sign_unplacelist() only takes one argument. (Sean Dewar, closes vim/vim#9081) https://github.com/vim/vim/commit/a63780b9770699bf8fda93affeab2c728bc76912 Addressed in the port of v8.1.1995. --- src/nvim/testdir/test_cd.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/testdir/test_cd.vim b/src/nvim/testdir/test_cd.vim index 57db0a2544..76a2620be0 100644 --- a/src/nvim/testdir/test_cd.vim +++ b/src/nvim/testdir/test_cd.vim @@ -101,7 +101,7 @@ func Test_chdir_func() call assert_match('^\[global\] .*/Xdir$', trim(execute('verbose pwd'))) call chdir('..') call assert_equal('y', fnamemodify(getcwd(1, 2), ':t')) - call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) + call assert_equal('z', fnamemodify(3->getcwd(2), ':t')) tabnext | wincmd t call assert_match('^\[tabpage\] .*/y$', trim(execute('verbose pwd'))) call chdir('..') From 4efcb72bb758ce93e86fa3ef520e009d01d4891b Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 31 Oct 2021 16:41:39 +0000 Subject: [PATCH 02/16] feat(eval/method): partially port v8.1.1993 Problem: More functions can be used as methods. Solution: Make various functions usable as a method. https://github.com/vim/vim/commit/196b4664432f932625cfb6371dc42c24efe6c203 server2client requires +clientserver, which hasn't been ported yet. The eval.txt docs and test_clientserver.vim tests for server2client already exist, so include those changes. test_bufline.vim: Test for setbufline requires v8.1.1189 (which was reverted in #10848). --- runtime/doc/eval.txt | 46 ++++++++++++++++++- src/nvim/eval.lua | 28 +++++------ src/nvim/testdir/test_charsearch.vim | 2 +- src/nvim/testdir/test_clientserver.vim | 2 +- src/nvim/testdir/test_cmdline.vim | 2 +- src/nvim/testdir/test_cursor_func.vim | 2 +- src/nvim/testdir/test_diffmode.vim | 2 +- src/nvim/testdir/test_environ.vim | 2 +- src/nvim/testdir/test_functions.vim | 4 +- .../testdir/test_matchadd_conceal_utf8.vim | 2 +- src/nvim/testdir/test_search.vim | 37 ++++++++++++++- src/nvim/testdir/test_utf8.vim | 2 +- test/functional/legacy/searchpos_spec.lua | 2 +- 13 files changed, 106 insertions(+), 27 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 02ff9fc591..74b0351dbe 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5854,7 +5854,7 @@ histadd({history}, {item}) *histadd()* Can also be used as a |method|, the base is used for the second argument: > - GetPattern()->histadd('search') + GetHistory()->histadd('search') histdel({history} [, {item}]) *histdel()* Clear {history}, i.e. delete all its entries. See |hist-names| @@ -8072,6 +8072,9 @@ screenattr({row}, {col}) *screenattr()* arbitrary number that can only be used to compare to the attribute at other positions. + Can also be used as a |method|: > + GetRow()->screenattr(col) + screenchar({row}, {col}) *screenchar()* The result is a Number, which is the character at position [row, col] on the screen. This works for every possible @@ -8082,6 +8085,9 @@ screenchar({row}, {col}) *screenchar()* This is mainly to be used for testing. Returns -1 when row or col is out of range. + Can also be used as a |method|: > + GetRow()->screenchar(col) + screenchars({row}, {col}) *screenchars()* The result is a List of Numbers. The first number is the same as what |screenchar()| returns. Further numbers are @@ -8089,6 +8095,9 @@ screenchars({row}, {col}) *screenchars()* This is mainly to be used for testing. Returns an empty List when row or col is out of range. + Can also be used as a |method|: > + GetRow()->screenchars(col) + screencol() *screencol()* The result is a Number, which is the current screen column of the cursor. The leftmost column has number 1. @@ -8124,6 +8133,9 @@ screenpos({winid}, {lnum}, {col}) *screenpos()* right position and use |screencol()| to get the value with |conceal| taken into account. + Can also be used as a |method|: > + GetWinid()->screenpos(lnum, col) + screenrow() *screenrow()* The result is a Number, which is the current screen row of the cursor. The top line has number one. @@ -8140,6 +8152,9 @@ screenstring({row}, {col}) *screenstring()* This is mainly to be used for testing. Returns an empty String when row or col is out of range. + Can also be used as a |method|: > + GetRow()->screenstring(col) + search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()* Search for regexp pattern {pattern}. The search starts at the cursor position (you can use |cursor()| to set it). @@ -8230,6 +8245,8 @@ search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()* without the 'e' flag if the cursor is on the "f" of "if". The 'n' flag tells the function not to move the cursor. + Can also be used as a |method|: > + GetPattern()->search() searchcount([{options}]) *searchcount()* Get or update the last search count, like what is displayed @@ -8368,6 +8385,9 @@ searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()* if searchdecl('myvar') == 0 echo getline('.') endif +< + Can also be used as a |method|: > + GetName()->searchdecl() < *searchpair()* searchpair({start}, {middle}, {end} [, {flags} [, {skip} @@ -8483,6 +8503,9 @@ searchpos({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *searchpos()* < In this example "submatch" is 2 when a lowercase letter is found |/\l|, 3 when an uppercase letter is found |/\u|. + Can also be used as a |method|: > + GetPattern()->searchpos() + server2client({clientid}, {string}) *server2client()* Send a reply string to {clientid}. The most recent {clientid} that sent a string can be retrieved with expand(""). @@ -8494,6 +8517,9 @@ server2client({clientid}, {string}) *server2client()* See also |clientserver|. Example: > :echo server2client(expand(""), "HELLO") + +< Can also be used as a |method|: > + GetClientId()->server2client(string) < serverlist() *serverlist()* Returns a list of server addresses, or empty if all servers @@ -8559,6 +8585,9 @@ setbufline({buf}, {lnum}, {text}) *setbufline()* If {buf} is not a valid buffer or {lnum} is not valid, an error message is given. + Can also be used as a |method|: > + GetText()->setbufline(buf, lnum) + setbufvar({buf}, {varname}, {val}) *setbufvar()* Set option or local variable {varname} in buffer {buf} to {val}. @@ -8573,6 +8602,9 @@ setbufvar({buf}, {varname}, {val}) *setbufvar()* :call setbufvar("todo", "myvar", "foobar") < This function is not available in the |sandbox|. + Can also be used as a |method|: > + GetValue()->setbufvar(buf, varname) + setcharsearch({dict}) *setcharsearch()* Set the current character search information to {dict}, which contains one or more of the following entries: @@ -8593,6 +8625,9 @@ setcharsearch({dict}) *setcharsearch()* :call setcharsearch(prevsearch) < Also see |getcharsearch()|. + Can also be used as a |method|: > + SavedSearch()->setcharsearch() + setcmdpos({pos}) *setcmdpos()* Set the cursor position in the command line to byte position {pos}. The first position is 1. @@ -8608,6 +8643,9 @@ setcmdpos({pos}) *setcmdpos()* Returns FALSE when successful, TRUE when not editing the command line. + Can also be used as a |method|: > + GetPos()->setcmdpos() + setenv({name}, {val}) *setenv()* Set environment variable {name} to {val}. Example: > call setenv('HOME', '/home/myhome') @@ -8615,6 +8653,9 @@ setenv({name}, {val}) *setenv()* < When {val} is |v:null| the environment variable is deleted. See also |expr-env|. + Can also be used as a |method|, passing the value as the base: > + GetPath()->setenv('PATH') + setfperm({fname}, {mode}) *setfperm()* *chmod* Set the file permissions for {fname} to {mode}. {mode} must be a string with 9 characters. It is of the form @@ -8660,6 +8701,9 @@ setline({lnum}, {text}) *setline()* < Note: The '[ and '] marks are not set. + Can also be used as a |method|, passing the text as the base: > + GetText()->setline(lnum) + setloclist({nr}, {list}[, {action}[, {what}]]) *setloclist()* Create or replace or add to the location list for window {nr}. {nr} can be the window number or the |window-ID|. diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index dfc51d80af..d6b285eab0 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -291,29 +291,29 @@ return { rpcstart={args={1, 2}}, rpcstop={args=1}, rubyeval={args=1, base=1}, - screenattr={args=2}, - screenchar={args=2}, - screenchars={args=2}, + screenattr={args=2, base=1}, + screenchar={args=2, base=1}, + screenchars={args=2, base=1}, screencol={}, - screenpos={args=3}, + screenpos={args=3, base=1}, screenrow={}, - screenstring={args=2}, - search={args={1, 4}}, + screenstring={args=2, base=1}, + search={args={1, 4}, base=1}, searchcount={args={0,1}}, - searchdecl={args={1, 3}}, + searchdecl={args={1, 3}, base=1}, searchpair={args={3, 7}}, searchpairpos={args={3, 7}}, - searchpos={args={1, 4}}, + searchpos={args={1, 4}, base=1}, serverlist={}, serverstart={args={0, 1}}, serverstop={args=1}, - setbufline={args=3}, - setbufvar={args=3}, - setcharsearch={args=1}, - setcmdpos={args=1}, - setenv={args=2}, + setbufline={args=3, base=3}, + setbufvar={args=3, base=3}, + setcharsearch={args=1, base=1}, + setcmdpos={args=1, base=1}, + setenv={args=2, base=2}, setfperm={args=2, base=1}, - setline={args=2}, + setline={args=2, base=2}, setloclist={args={2, 4}}, setmatches={args={1, 2}}, setpos={args=2}, diff --git a/src/nvim/testdir/test_charsearch.vim b/src/nvim/testdir/test_charsearch.vim index 17a49e02be..6f09e85a42 100644 --- a/src/nvim/testdir/test_charsearch.vim +++ b/src/nvim/testdir/test_charsearch.vim @@ -20,7 +20,7 @@ func Test_charsearch() " check that setcharsearch() changes the settings. 3 normal! ylfep - call setcharsearch({'char': 'k'}) + eval {'char': 'k'}->setcharsearch() normal! ;p call setcharsearch({'forward': 0}) normal! $;p diff --git a/src/nvim/testdir/test_clientserver.vim b/src/nvim/testdir/test_clientserver.vim index f3db472b03..922803438f 100644 --- a/src/nvim/testdir/test_clientserver.vim +++ b/src/nvim/testdir/test_clientserver.vim @@ -82,7 +82,7 @@ func Test_client_server() call remote_send(name, ":call server2client(expand(''), 'got it')\", 'g:myserverid') call assert_equal('got it', g:myserverid->remote_read(2)) - call remote_send(name, ":call server2client(expand(''), 'another')\", 'g:myserverid') + call remote_send(name, ":eval expand('')->server2client('another')\", 'g:myserverid') let peek_result = 'nothing' let r = g:myserverid->remote_peek('peek_result') " unpredictable whether the result is already available. diff --git a/src/nvim/testdir/test_cmdline.vim b/src/nvim/testdir/test_cmdline.vim index 75e17b47b8..49a5386337 100644 --- a/src/nvim/testdir/test_cmdline.vim +++ b/src/nvim/testdir/test_cmdline.vim @@ -905,7 +905,7 @@ func Test_setcmdpos() call assert_equal('"12ab', @:) " setcmdpos() returns 1 when not editing the command line. - call assert_equal(1, setcmdpos(3)) + call assert_equal(1, 3->setcmdpos()) endfunc func Test_cmdline_overstrike() diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index 46847e0663..a2482d95c4 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -86,7 +86,7 @@ func Test_screenpos() call assert_equal({'row': winrow, \ 'col': wincol + 13, \ 'curscol': wincol + 13, - \ 'endcol': wincol + 13}, screenpos(winid, 1, 7)) + \ 'endcol': wincol + 13}, winid->screenpos(1, 7)) call assert_equal({'row': winrow + 2, \ 'col': wincol + 1, \ 'curscol': wincol + 1, diff --git a/src/nvim/testdir/test_diffmode.vim b/src/nvim/testdir/test_diffmode.vim index 61da3cbcaa..3a0c615cf6 100644 --- a/src/nvim/testdir/test_diffmode.vim +++ b/src/nvim/testdir/test_diffmode.vim @@ -387,7 +387,7 @@ func Test_diffoff() call setline(1, ['One', '', 'Two', 'Three']) diffthis redraw - call assert_notequal(normattr, screenattr(1, 1)) + call assert_notequal(normattr, 1->screenattr(1)) diffoff! redraw call assert_equal(normattr, screenattr(1, 1)) diff --git a/src/nvim/testdir/test_environ.vim b/src/nvim/testdir/test_environ.vim index cc15b63824..dd34983ee5 100644 --- a/src/nvim/testdir/test_environ.vim +++ b/src/nvim/testdir/test_environ.vim @@ -22,7 +22,7 @@ endfunc func Test_setenv() unlet! $TESTENV - call setenv('TEST ENV', 'foo') + eval 'foo'->setenv('TEST ENV') call assert_equal('foo', getenv('TEST ENV')) call setenv('TEST ENV', v:null) call assert_equal(v:null, getenv('TEST ENV')) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 4a2ade5afa..2fcdd94188 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -346,7 +346,7 @@ func Test_setbufvar_options() wincmd h let wh = winheight(0) let dummy_buf = bufnr('dummy_buf2', v:true) - call setbufvar(dummy_buf, '&buftype', 'nofile') + eval 'nofile'->setbufvar(dummy_buf, '&buftype') execute 'belowright vertical split #' . dummy_buf call assert_equal(wh, winheight(0)) @@ -1330,7 +1330,7 @@ func Test_func_range_with_edit() " is invalid in that buffer. call writefile(['just one line'], 'Xfuncrange2') new - call setline(1, 10->range()) + eval 10->range()->setline(1) write Xfuncrange1 call assert_fails('5,8call EditAnotherFile()', 'E16:') diff --git a/src/nvim/testdir/test_matchadd_conceal_utf8.vim b/src/nvim/testdir/test_matchadd_conceal_utf8.vim index 34c8c49dd5..7bfac13ad8 100644 --- a/src/nvim/testdir/test_matchadd_conceal_utf8.vim +++ b/src/nvim/testdir/test_matchadd_conceal_utf8.vim @@ -6,7 +6,7 @@ endif function! s:screenline(lnum) abort let line = [] for c in range(1, winwidth(0)) - call add(line, nr2char(screenchar(a:lnum, c))) + call add(line, nr2char(a:lnum->screenchar(c))) endfor return s:trim(join(line, '')) endfunction diff --git a/src/nvim/testdir/test_search.vim b/src/nvim/testdir/test_search.vim index 7570049e7c..c796f1f676 100644 --- a/src/nvim/testdir/test_search.vim +++ b/src/nvim/testdir/test_search.vim @@ -1315,7 +1315,7 @@ func Test_search_match_at_curpos() normal gg - call search('foobar', 'c') + eval 'foobar'->search('c') call assert_equal([1, 1], [line('.'), col('.')]) normal j @@ -1354,6 +1354,41 @@ func Test_search_display_pattern() endif endfunc +func Test_searchdecl() + let lines =<< trim END + int global; + + func() + { + int global; + if (cond) { + int local; + } + int local; + // comment + } + END + new + call setline(1, lines) + 10 + call assert_equal(0, searchdecl('local', 0, 0)) + call assert_equal(7, getcurpos()[1]) + + 10 + call assert_equal(0, 'local'->searchdecl(0, 1)) + call assert_equal(9, getcurpos()[1]) + + 10 + call assert_equal(0, searchdecl('global')) + call assert_equal(5, getcurpos()[1]) + + 10 + call assert_equal(0, searchdecl('global', 1)) + call assert_equal(1, getcurpos()[1]) + + bwipe! +endfunc + func Test_search_special() " this was causing illegal memory access and an endless loop set t_PE= diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index da72da087f..1f2cdde5cf 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -69,7 +69,7 @@ func Test_screenchar_utf8() call setline(1, ["ABC\u0308"]) redraw call assert_equal([0x0041], screenchars(1, 1)) - call assert_equal([0x0042], screenchars(1, 2)) + call assert_equal([0x0042], 1->screenchars(2)) call assert_equal([0x0043, 0x0308], screenchars(1, 3)) call assert_equal("A", screenstring(1, 1)) call assert_equal("B", screenstring(1, 2)) diff --git a/test/functional/legacy/searchpos_spec.lua b/test/functional/legacy/searchpos_spec.lua index 60f1edcd3f..fc18341c38 100644 --- a/test/functional/legacy/searchpos_spec.lua +++ b/test/functional/legacy/searchpos_spec.lua @@ -17,7 +17,7 @@ describe('searchpos', function() call('cursor', 1, 1) eq({1, 1, 2}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]])) call('cursor', 1, 2) - eq({2, 1, 1}, eval([[searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW')]])) + eq({2, 1, 1}, eval([['\%(\([a-z]\)\|\_.\)\{-}xyz'->searchpos('pcW')]])) command('set cpo-=c') call('cursor', 1, 2) From aad25ae4fc3fdfdf2c23009406cf3f806a2c272d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 31 Oct 2021 17:31:35 +0000 Subject: [PATCH 03/16] vim-patch:8.1.1995: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make sign functions usable as a method. https://github.com/vim/vim/commit/93476fd6343ef40d088e064289cc279659d03953 Make sign_placelist and sign_unplacelist accept exactly one argument. Before, they erroneously accepted one or more arguments. --- runtime/doc/sign.txt | 27 +++++++++++++++++++++++++-- src/nvim/eval.lua | 18 +++++++++--------- src/nvim/testdir/test_signs.vim | 19 +++++++++---------- 3 files changed, 43 insertions(+), 21 deletions(-) diff --git a/runtime/doc/sign.txt b/runtime/doc/sign.txt index 5079d900c9..9181684945 100644 --- a/runtime/doc/sign.txt +++ b/runtime/doc/sign.txt @@ -404,6 +404,9 @@ sign_define({list}) \ 'text' : '!!'} \ ]) < + Can also be used as a |method|: > + GetSignList()->sign_define() + sign_getdefined([{name}]) *sign_getdefined()* Get a list of defined signs and their attributes. This is similar to the |:sign-list| command. @@ -435,6 +438,9 @@ sign_getdefined([{name}]) *sign_getdefined()* " Get the attribute of the sign named mySign echo sign_getdefined("mySign") < + Can also be used as a |method|: > + GetSignList()->sign_getdefined() + sign_getplaced([{buf} [, {dict}]]) *sign_getplaced()* Return a list of signs placed in a buffer or all the buffers. This is similar to the |:sign-place-list| command. @@ -494,6 +500,9 @@ sign_getplaced([{buf} [, {dict}]]) *sign_getplaced()* " Get a List of all the placed signs echo sign_getplaced() +< + Can also be used as a |method|: > + GetBufname()->sign_getplaced() < *sign_jump()* sign_jump({id}, {group}, {buf}) @@ -510,7 +519,9 @@ sign_jump({id}, {group}, {buf}) " Jump to sign 10 in the current buffer call sign_jump(10, '', '') < - + Can also be used as a |method|: > + GetSignid()->sign_jump() +< *sign_place()* sign_place({id}, {group}, {name}, {buf} [, {dict}]) Place the sign defined as {name} at line {lnum} in file or @@ -560,7 +571,9 @@ sign_place({id}, {group}, {name}, {buf} [, {dict}]) call sign_place(10, 'g3', 'sign4', 'json.c', \ {'lnum' : 40, 'priority' : 90}) < - + Can also be used as a |method|: > + GetSignid()->sign_place(group, name, expr) +< *sign_placelist()* sign_placelist({list}) Place one or more signs. This is similar to the @@ -620,6 +633,8 @@ sign_placelist({list}) \ 'lnum' : 50} \ ]) < + Can also be used as a |method|: > + GetSignlist()->sign_placelist() sign_undefine([{name}]) *sign_undefine()* sign_undefine({list}) @@ -644,6 +659,8 @@ sign_undefine({list}) " Delete all the signs call sign_undefine() < + Can also be used as a |method|: > + GetSignlist()->sign_undefine() sign_unplace({group} [, {dict}]) *sign_unplace()* Remove a previously placed sign in one or more buffers. This @@ -686,6 +703,9 @@ sign_unplace({group} [, {dict}]) *sign_unplace()* " Remove all the placed signs from all the buffers call sign_unplace('*') + +< Can also be used as a |method|: > + GetSigngroup()->sign_unplace() < sign_unplacelist({list}) *sign_unplacelist()* Remove previously placed signs from one or more buffers. This @@ -715,5 +735,8 @@ sign_unplacelist({list}) *sign_unplacelist()* \ {'id' : 20, 'buffer' : 'b.vim'}, \ ]) < + Can also be used as a |method|: > + GetSignlist()->sign_unplacelist() +< vim:tw=78:ts=8:noet:ft=help:norl: diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index d6b285eab0..78c4b1ee4d 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -326,15 +326,15 @@ return { sha256={args=1}, shellescape={args={1, 2}}, shiftwidth={args={0, 1}}, - sign_define={args={1, 2}}, - sign_getdefined={args={0, 1}}, - sign_getplaced={args={0, 2}}, - sign_jump={args={3, 3}}, - sign_place={args={4, 5}}, - sign_placelist={args={1}}, - sign_undefine={args={0, 1}}, - sign_unplace={args={1, 2}}, - sign_unplacelist={args={1}}, + sign_define={args={1, 2}, base=1}, + sign_getdefined={args={0, 1}, base=1}, + sign_getplaced={args={0, 2}, base=1}, + sign_jump={args=3, base=1}, + sign_place={args={4, 5}, base=1}, + sign_placelist={args=1, base=1}, + sign_undefine={args={0, 1}, base=1}, + sign_unplace={args={1, 2}, base=1}, + sign_unplacelist={args=1, base=1}, simplify={args=1}, sin={args=1, base=1, func="float_op_wrapper", data="&sin"}, sinh={args=1, base=1, func="float_op_wrapper", data="&sinh"}, diff --git a/src/nvim/testdir/test_signs.vim b/src/nvim/testdir/test_signs.vim index 9753100375..f287256396 100644 --- a/src/nvim/testdir/test_signs.vim +++ b/src/nvim/testdir/test_signs.vim @@ -393,7 +393,7 @@ func Test_sign_funcs() " Tests for sign_define() let attr = {'text' : '=>', 'linehl' : 'Search', 'texthl' : 'Error'} - call assert_equal(0, sign_define("sign1", attr)) + call assert_equal(0, "sign1"->sign_define(attr)) call assert_equal([{'name' : 'sign1', 'texthl' : 'Error', \ 'linehl' : 'Search', 'text' : '=>'}], sign_getdefined()) @@ -404,13 +404,13 @@ func Test_sign_funcs() call Sign_define_ignore_error("sign2", attr) call assert_equal([{'name' : 'sign2', 'texthl' : 'DiffChange', \ 'linehl' : 'DiffAdd', 'text' : '!!', 'icon' : 'sign2.ico'}], - \ sign_getdefined("sign2")) + \ "sign2"->sign_getdefined()) " Test for a sign name with digits call assert_equal(0, sign_define(0002, {'linehl' : 'StatusLine'})) call assert_equal([{'name' : '2', 'linehl' : 'StatusLine'}], \ sign_getdefined(0002)) - call sign_undefine(0002) + eval 0002->sign_undefine() " Tests for invalid arguments to sign_define() call assert_fails('call sign_define("sign4", {"text" : "===>"})', 'E239:') @@ -434,7 +434,7 @@ func Test_sign_funcs() call assert_equal([{'bufnr' : bufnr(''), 'signs' : \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', \ 'priority' : 10}]}], - \ sign_getplaced('%', {'lnum' : 20})) + \ '%'->sign_getplaced({'lnum' : 20})) call assert_equal([{'bufnr' : bufnr(''), 'signs' : \ [{'id' : 10, 'group' : '', 'lnum' : 20, 'name' : 'sign1', \ 'priority' : 10}]}], @@ -490,10 +490,10 @@ func Test_sign_funcs() \ 'E745:') " Tests for sign_unplace() - call sign_place(20, '', 'sign2', 'Xsign', {"lnum" : 30}) + eval 20->sign_place('', 'sign2', 'Xsign', {"lnum" : 30}) call assert_equal(0, sign_unplace('', \ {'id' : 20, 'buffer' : 'Xsign'})) - call assert_equal(-1, sign_unplace('', + call assert_equal(-1, ''->sign_unplace( \ {'id' : 30, 'buffer' : 'Xsign'})) call sign_place(20, '', 'sign2', 'Xsign', {"lnum" : 30}) call assert_fails("call sign_unplace('', @@ -1693,7 +1693,7 @@ func Test_sign_jump_func() let r = sign_jump(5, '', 'foo') call assert_equal(2, r) call assert_equal(2, line('.')) - let r = sign_jump(6, 'g1', 'foo') + let r = 6->sign_jump('g1', 'foo') call assert_equal(5, r) call assert_equal(5, line('.')) let r = sign_jump(5, '', 'bar') @@ -1921,8 +1921,7 @@ func Test_sign_funcs_multi() \ 'group' : 'g1', 'priority' : 10}], s[0].signs) " Change an existing sign without specifying the group - call assert_equal([5], sign_placelist([ - \ {'id' : 5, 'name' : 'sign1', 'buffer' : 'Xsign'}])) + call assert_equal([5], [{'id' : 5, 'name' : 'sign1', 'buffer' : 'Xsign'}]->sign_placelist()) let s = sign_getplaced('Xsign', {'id' : 5, 'group' : ''}) call assert_equal([{'id' : 5, 'name' : 'sign1', 'lnum' : 11, \ 'group' : '', 'priority' : 10}], s[0].signs) @@ -1955,7 +1954,7 @@ func Test_sign_funcs_multi() \ {'id' : 1, 'group' : 'g1'}, {'id' : 1, 'group' : 'g2'}])) " Invalid arguments - call assert_equal([], sign_unplacelist([])) + call assert_equal([], []->sign_unplacelist()) call assert_fails('call sign_unplacelist({})', "E714:") call assert_fails('call sign_unplacelist([[]])', "E715:") call assert_fails('call sign_unplacelist(["abc"])', "E715:") From 2ee0bc09d9becd71ca864b4d754b63b152d1ce5b Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 31 Oct 2021 18:10:46 +0000 Subject: [PATCH 04/16] feat(eval/method): partially port v8.1.1996 Problem: More functions can be used as methods. Solution: Make various functions usable as a method. https://github.com/vim/vim/commit/aad222c9c9a1e4fe6ae5a1fe95bb084619be0e65 Partial port as this does not include eval.txt change for listener_add. Cherry-pick eval.txt changes for: - bufadd from v8.1.1626: https://github.com/vim/vim/commit/5ca1ac373ae62b37152cb6f85916b402eda520a5 - setloclist and setqflist headers from: https://github.com/vim/vim/commit/b0d45e7f5354375edd02afafde3bd37dac1515ff Correct eval.txt typo for settabwinvar method call (matches latest Vim). --- runtime/doc/eval.txt | 47 ++++++++++++++++++++++--- src/nvim/eval.lua | 24 ++++++------- src/nvim/testdir/test_bufwintabinfo.vim | 2 +- src/nvim/testdir/test_cursor_func.vim | 2 +- src/nvim/testdir/test_expr.vim | 2 +- src/nvim/testdir/test_functions.vim | 2 +- src/nvim/testdir/test_put.vim | 2 +- src/nvim/testdir/test_quickfix.vim | 4 +-- src/nvim/testdir/test_sha256.vim | 10 +++--- src/nvim/testdir/test_tabpage.vim | 4 +-- src/nvim/testdir/test_tagjump.vim | 2 +- src/nvim/testdir/test_vartabs.vim | 2 +- 12 files changed, 71 insertions(+), 32 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 74b0351dbe..bbd3226d4c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -2992,7 +2992,11 @@ bufadd({name}) *bufadd()* number. Otherwise return the buffer number of the newly created buffer. When {name} is an empty string then a new buffer is always created. - The buffer will not have' 'buflisted' set. + The buffer will not have 'buflisted' set and not be loaded + yet. To add some text to the buffer use this: > + let bufnr = bufadd('someName') + call bufload(bufnr) + call setbufline(bufnr, 1, ['some', 'text']) < Can also be used as a |method|: > let bufnr = 'somename'->bufadd() @@ -8704,7 +8708,7 @@ setline({lnum}, {text}) *setline()* Can also be used as a |method|, passing the text as the base: > GetText()->setline(lnum) -setloclist({nr}, {list}[, {action}[, {what}]]) *setloclist()* +setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()* Create or replace or add to the location list for window {nr}. {nr} can be the window number or the |window-ID|. When {nr} is zero the current window is used. @@ -8720,6 +8724,10 @@ setloclist({nr}, {list}[, {action}[, {what}]]) *setloclist()* only the items listed in {what} are set. Refer to |setqflist()| for the list of supported keys in {what}. + Can also be used as a |method|, the base is passed as the + second argument: > + GetLoclist()->setloclist(winnr) + setmatches({list} [, {win}]) *setmatches()* Restores a list of matches saved by |getmatches() for the current window|. Returns 0 if successful, otherwise -1. All @@ -8728,6 +8736,9 @@ setmatches({list} [, {win}]) *setmatches()* 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|: > + GetMatches()->setmatches() +< *setpos()* setpos({expr}, {list}) Set the position for String {expr}. Possible values: @@ -8777,8 +8788,10 @@ setpos({expr}, {list}) also set the preferred column. Also see the "curswant" key in |winrestview()|. + Can also be used as a |method|: > + GetPosition()->setpos('.') -setqflist({list} [, {action}[, {what}]]) *setqflist()* +setqflist({list} [, {action} [, {what}]]) *setqflist()* Create or replace or add to the quickfix list. If the optional {what} dictionary argument is supplied, then @@ -8887,7 +8900,10 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()* independent of the 'errorformat' setting. Use a command like `:cc 1` to jump to the first position. - + Can also be used as a |method|, the base is passed as the + second argument: > + GetErrorlist()->setqflist() +< *setreg()* setreg({regname}, {value} [, {options}]) Set the register {regname} to {value}. @@ -8944,6 +8960,10 @@ setreg({regname}, {value} [, {options}]) nothing: > :call setreg('a', '', 'al') +< Can also be used as a |method|, the base is passed as the + second argument: > + GetText()->setreg('a') + settabvar({tabnr}, {varname}, {val}) *settabvar()* Set tab-local variable {varname} to {val} in tab page {tabnr}. |t:var| @@ -8952,6 +8972,9 @@ settabvar({tabnr}, {varname}, {val}) *settabvar()* Tabs are numbered starting with one. This function is not available in the |sandbox|. + Can also be used as a |method|, the base is used as the value: > + GetValue()->settabvar(tab, name) + settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* Set option or local variable {varname} in window {winnr} to {val}. @@ -8968,6 +8991,9 @@ settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* :call settabwinvar(3, 2, "myvar", "foobar") < This function is not available in the |sandbox|. + Can also be used as a |method|, the base is used as the value: > + GetValue()->settabwinvar(tab, winnr, name) + settagstack({nr}, {dict} [, {action}]) *settagstack()* Modify the tag stack of the window {nr} using {dict}. {nr} can be the window number or the |window-ID|. @@ -9001,6 +9027,8 @@ settagstack({nr}, {dict} [, {action}]) *settagstack()* call settagstack(1003, stack) unlet stack < + Can also be used as a |method|, the base is used as the Dict: > + GetStack()->settagstack(winnr) setwinvar({nr}, {varname}, {val}) *setwinvar()* Like |settabwinvar()| for the current tab page. @@ -9008,10 +9036,16 @@ setwinvar({nr}, {varname}, {val}) *setwinvar()* :call setwinvar(1, "&list", 0) :call setwinvar(2, "myvar", "foobar") +< Can also be used as a |method|, the base is used as the value: > + GetValue()->setwinvar(winnr, name) + sha256({string}) *sha256()* Returns a String with 64 hex characters, which is the SHA256 checksum of {string}. + Can also be used as a |method|: > + GetText()->sha256() + shellescape({string} [, {special}]) *shellescape()* Escape {string} for use as a shell command argument. @@ -9043,6 +9077,8 @@ shellescape({string} [, {special}]) *shellescape()* :call system("chmod +w -- " . shellescape(expand("%"))) < See also |::S|. + Can also be used as a |method|: > + GetCommand()->shellescape() shiftwidth([{col}]) *shiftwidth()* Returns the effective value of 'shiftwidth'. This is the @@ -9065,6 +9101,9 @@ shiftwidth([{col}]) *shiftwidth()* 'vartabstop' feature. If no {col} argument is given, column 1 will be assumed. + Can also be used as a |method|: > + GetColumn()->shiftwidth() + sign_ functions are documented here: |sign-functions-details| simplify({filename}) *simplify()* diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 78c4b1ee4d..6a800e5648 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -314,18 +314,18 @@ return { setenv={args=2, base=2}, setfperm={args=2, base=1}, setline={args=2, base=2}, - setloclist={args={2, 4}}, - setmatches={args={1, 2}}, - setpos={args=2}, - setqflist={args={1, 3}}, - setreg={args={2, 3}}, - settabvar={args=3}, - settabwinvar={args=4}, - settagstack={args={2, 3}}, - setwinvar={args=3}, - sha256={args=1}, - shellescape={args={1, 2}}, - shiftwidth={args={0, 1}}, + setloclist={args={2, 4}, base=2}, + setmatches={args={1, 2}, base=1}, + setpos={args=2, base=2}, + setqflist={args={1, 3}, base=1}, + setreg={args={2, 3}, base=2}, + settabvar={args=3, base=3}, + settabwinvar={args=4, base=4}, + settagstack={args={2, 3}, base=2}, + setwinvar={args=3, base=3}, + sha256={args=1, base=1}, + shellescape={args={1, 2}, base=1}, + shiftwidth={args={0, 1}, base=1}, sign_define={args={1, 2}, base=1}, sign_getdefined={args={0, 1}, base=1}, sign_getplaced={args={0, 2}, base=1}, diff --git a/src/nvim/testdir/test_bufwintabinfo.vim b/src/nvim/testdir/test_bufwintabinfo.vim index c04c8fbf60..d2c99563d9 100644 --- a/src/nvim/testdir/test_bufwintabinfo.vim +++ b/src/nvim/testdir/test_bufwintabinfo.vim @@ -48,7 +48,7 @@ function Test_getbufwintabinfo() tabnew | let w3_id = win_getid() new | let w4_id = win_getid() vert new | let w5_id = win_getid() - call setwinvar(0, 'signal', 'green') + eval 'green'->setwinvar(0, 'signal') tabfirst let winlist = getwininfo() call assert_equal(5, len(winlist)) diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index a2482d95c4..d96a35ef53 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -37,7 +37,7 @@ endfunc " Very short version of what matchparen does. function s:Highlight_Matching_Pair() let save_cursor = getcurpos() - call setpos('.', save_cursor) + eval save_cursor->setpos('.') endfunc func Test_curswant_with_autocommand() diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index 6343c47fde..a8cf6577f6 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -493,7 +493,7 @@ func Test_setmatches() let set[0]['conceal'] = 5 let exp[0]['conceal'] = '5' endif - call setmatches(set) + eval set->setmatches() call assert_equal(exp, getmatches()) endfunc diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 2fcdd94188..ef33cd5dd8 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -1219,7 +1219,7 @@ func Test_shellescape() let save_shell = &shell set shell=bash call assert_equal("'text'", shellescape('text')) - call assert_equal("'te\"xt'", shellescape('te"xt')) + call assert_equal("'te\"xt'", 'te"xt'->shellescape()) call assert_equal("'te'\\''xt'", shellescape("te'xt")) call assert_equal("'te%xt'", shellescape("te%xt")) diff --git a/src/nvim/testdir/test_put.vim b/src/nvim/testdir/test_put.vim index 8d8cc77025..f42b177c50 100644 --- a/src/nvim/testdir/test_put.vim +++ b/src/nvim/testdir/test_put.vim @@ -39,7 +39,7 @@ func Test_put_lines() call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1, '$')) " clean up bw! - call setreg('a', a[0], a[1]) + eval a[0]->setreg('a', a[1]) endfunc func Test_put_expr() diff --git a/src/nvim/testdir/test_quickfix.vim b/src/nvim/testdir/test_quickfix.vim index b38a59e98f..6db679c5f9 100644 --- a/src/nvim/testdir/test_quickfix.vim +++ b/src/nvim/testdir/test_quickfix.vim @@ -811,7 +811,7 @@ func Test_locationlist() " NOTE: problem 1: " intentionally not setting 'lnum' so that the quickfix entries are not " valid - call setloclist(0, qflist, ' ') + eval qflist->setloclist(0, ' ') endfor " Test A @@ -1699,7 +1699,7 @@ endfunc func Test_setqflist_invalid_nr() " The following command used to crash Vim - call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST}) + eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST}) endfunc func Test_setqflist_user_sets_buftype() diff --git a/src/nvim/testdir/test_sha256.vim b/src/nvim/testdir/test_sha256.vim index dd4707977e..76d1306836 100644 --- a/src/nvim/testdir/test_sha256.vim +++ b/src/nvim/testdir/test_sha256.vim @@ -6,17 +6,17 @@ endif function Test_sha256() " test for empty string: - call assert_equal(sha256(""), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855') + call assert_equal('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', sha256("")) "'test for 1 char: - call assert_equal(sha256("a"), 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb') + call assert_equal('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', sha256("a")) " "test for 3 chars: - call assert_equal(sha256("abc"), 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad') + call assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', "abc"->sha256()) " test for contains meta char: - call assert_equal(sha256("foo\nbar"), '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776') + call assert_equal('807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776', sha256("foo\nbar")) " test for contains non-ascii char: - call assert_equal(sha256("\xde\xad\xbe\xef"), '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953') + call assert_equal('5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953', sha256("\xde\xad\xbe\xef")) endfunction diff --git a/src/nvim/testdir/test_tabpage.vim b/src/nvim/testdir/test_tabpage.vim index b261b96c3b..9869dc7590 100644 --- a/src/nvim/testdir/test_tabpage.vim +++ b/src/nvim/testdir/test_tabpage.vim @@ -35,7 +35,7 @@ function Test_tabpage() tabnew tabfirst call settabvar(2, 'val_num', 100) - call settabvar(2, 'val_str', 'SetTabVar test') + eval 'SetTabVar test'->settabvar(2, 'val_str') call settabvar(2, 'val_list', ['red', 'blue', 'green']) " call assert_true(gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green']) @@ -184,7 +184,7 @@ function Test_tabpage_with_autocmd() let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+') call assert_equal(['a', 'a'], s:li) let s:li = [] - C call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)') + C call map(copy(winr), '(v:val*2)->settabwinvar(' .. tabn .. ', v:val, ''a'')') let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+') call assert_equal(['2', '4'], s:li) diff --git a/src/nvim/testdir/test_tagjump.vim b/src/nvim/testdir/test_tagjump.vim index 15182893e9..2aa04df42a 100644 --- a/src/nvim/testdir/test_tagjump.vim +++ b/src/nvim/testdir/test_tagjump.vim @@ -351,7 +351,7 @@ func Test_getsettagstack() " Try to set current index to invalid values call settagstack(1, {'curidx' : -1}) call assert_equal(1, gettagstack().curidx) - call settagstack(1, {'curidx' : 50}) + eval {'curidx' : 50}->settagstack(1) call assert_equal(4, gettagstack().curidx) " Try pushing invalid items onto the stack diff --git a/src/nvim/testdir/test_vartabs.vim b/src/nvim/testdir/test_vartabs.vim index 2fbf130345..46e0d62313 100644 --- a/src/nvim/testdir/test_vartabs.vim +++ b/src/nvim/testdir/test_vartabs.vim @@ -330,7 +330,7 @@ func Test_vartabs_shiftwidth() let lines = ScreenLines([1, 2], winwidth(0)) call s:compare_lines(expect2, lines) call assert_equal(20, shiftwidth(virtcol('.')-2)) - call assert_equal(30, shiftwidth(virtcol('.'))) + call assert_equal(30, virtcol('.')->shiftwidth()) norm! $>> let expect3 = [' ', ' x ', '~ '] let lines = ScreenLines([1, 3], winwidth(0)) From 0f4510cb1a48c4c4d7b23a45f57d087329d4364d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 31 Oct 2021 19:04:28 +0000 Subject: [PATCH 05/16] feat(eval/method): partially port v8.1.2004 Problem: More functions can be used as methods. Solution: Make various functions usable as a method. https://github.com/vim/vim/commit/f6ed61e1489e40eada55a4f1782e1ed82bcad7d9 +sound is needed for sound_* functions. Make swapinfo and swapname take exactly one argument. Previously, they could erroneously take one or more. --- runtime/doc/eval.txt | 59 +++++++++++++++++++++++---- src/nvim/eval.lua | 30 +++++++------- src/nvim/testdir/test_breakindent.vim | 2 +- src/nvim/testdir/test_expr.vim | 4 +- src/nvim/testdir/test_functions.vim | 12 +++--- src/nvim/testdir/test_spell.vim | 6 +-- src/nvim/testdir/test_substitute.vim | 2 +- src/nvim/testdir/test_swap.vim | 4 +- src/nvim/testdir/test_utf8.vim | 2 +- 9 files changed, 82 insertions(+), 39 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index bbd3226d4c..fcaed24b1f 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -9254,6 +9254,9 @@ soundfold({word}) This can be used for making spelling suggestions. Note that the method can be quite slow. + Can also be used as a |method|: > + GetWord()->soundfold() +< *spellbadword()* spellbadword([{sentence}]) Without argument: The result is the badly spelled word under @@ -9279,6 +9282,9 @@ spellbadword([{sentence}]) The spelling information for the current window and the value of 'spelllang' are used. + Can also be used as a |method|: > + GetText()->spellbadword() +< *spellsuggest()* spellsuggest({word} [, {max} [, {capital}]]) Return a |List| with spelling suggestions to replace {word}. @@ -9301,6 +9307,8 @@ spellsuggest({word} [, {max} [, {capital}]]) The spelling information for the current window is used. The values of 'spelllang' and 'spellsuggest' are used. + Can also be used as a |method|: > + GetWord()->spellsuggest() split({string} [, {pattern} [, {keepempty}]]) *split()* Make a |List| out of {string}. When {pattern} is omitted or @@ -9432,6 +9440,20 @@ str2nr({string} [, {base}]) *str2nr()* {base} is 2 a leading "0b" or "0B" is ignored. Text after the number is silently ignored. + Can also be used as a |method|: > + GetText()->str2nr() + +strcharpart({src}, {start} [, {len}]) *strcharpart()* + Like |strpart()| but using character index and length instead + of byte index and length. Composing characters are counted + separately. + When a character index is used where a character does not + exist it is assumed to be one character. For example: > + strcharpart('abc', -1, 2) +< results in 'a'. + + Can also be used as a |method|: > + GetText()->strcharpart(5) strchars({string} [, {skipcc}]) *strchars()* The result is a Number, which is the number of characters @@ -9457,14 +9479,8 @@ strchars({string} [, {skipcc}]) *strchars()* endfunction endif < -strcharpart({src}, {start} [, {len}]) *strcharpart()* - Like |strpart()| but using character index and length instead - of byte index and length. Composing characters are counted - separately. - When a character index is used where a character does not - exist it is assumed to be one character. For example: > - strcharpart('abc', -1, 2) -< results in 'a'. + Can also be used as a |method|: > + GetText()->strchars() strdisplaywidth({string} [, {col}]) *strdisplaywidth()* The result is a Number, which is the number of display cells @@ -9479,6 +9495,9 @@ strdisplaywidth({string} [, {col}]) *strdisplaywidth()* Ambiguous, this function's return value depends on 'ambiwidth'. Also see |strlen()|, |strwidth()| and |strchars()|. + Can also be used as a |method|: > + GetText()->strdisplaywidth() + strftime({format} [, {time}]) *strftime()* The result is a String, which is a formatted date and time, as specified by the {format} string. The given {time} is used, @@ -9496,12 +9515,18 @@ strftime({format} [, {time}]) *strftime()* :echo strftime("%c", getftime("file.c")) Show mod time of file.c. +< Can also be used as a |method|: > + GetFormat()->strftime() + strgetchar({str}, {index}) *strgetchar()* Get character {index} from {str}. This uses a character index, not a byte index. Composing characters are considered separate characters here. Also see |strcharpart()| and |strchars()|. + Can also be used as a |method|: > + GetText()->strgetchar(5) + stridx({haystack}, {needle} [, {start}]) *stridx()* The result is a Number, which gives the byte index in {haystack} of the first occurrence of the String {needle}. @@ -9521,6 +9546,9 @@ stridx({haystack}, {needle} [, {start}]) *stridx()* stridx() works similar to the C function strstr(). When used with a single character it works similar to strchr(). + Can also be used as a |method|: > + GetHaystack()->stridx(needle) + *string()* string({expr}) Return {expr} converted to a String. If {expr} is a Number, Float, String, Blob or a composition of them, then the result @@ -9583,6 +9611,9 @@ strpart({src}, {start} [, {len} [, {chars}]]) *strpart()* example, to get the character under the cursor: > strpart(getline("."), col(".") - 1, 1, v:true) < + Can also be used as a |method|: > + GetText()->strpart(5) + strptime({format}, {timestring}) *strptime()* The result is a Number, which is a unix timestamp representing the date and time in {timestring}, which is expected to match @@ -9626,6 +9657,9 @@ strridx({haystack}, {needle} [, {start}]) *strridx()* When used with a single character it works similar to the C function strrchr(). + Can also be used as a |method|: > + GetHaystack()->strridx(needle) + strtrans({string}) *strtrans()* The result is a String, which is {string} with all unprintable characters translated into printable characters |'isprint'|. @@ -9674,6 +9708,9 @@ submatch({nr} [, {list}]) *submatch()* *E935* < This finds the first number in the line and adds one to it. A line break is included as a newline character. + Can also be used as a |method|: > + GetNr()->submatch() + substitute({string}, {pat}, {sub}, {flags}) *substitute()* The result is a String, which is a copy of {string}, in which the first match of {pat} is replaced with {sub}. @@ -9736,6 +9773,9 @@ swapinfo({fname}) *swapinfo()* Not a swap file: does not contain correct block ID Magic number mismatch: Info in first block is invalid + Can also be used as a |method|: > + GetFilename()->swapinfo() + swapname({buf}) *swapname()* The result is the swap file path of the buffer {buf}. For the use of {buf}, see |bufname()| above. @@ -9743,6 +9783,9 @@ swapname({buf}) *swapname()* |:swapname| (unless there is no swap file). If buffer {buf} has no swap file, returns an empty string. + Can also be used as a |method|: > + GetBufname()->swapname() + synID({lnum}, {col}, {trans}) *synID()* The result is a Number, which is the syntax ID at the position {lnum} and {col} in the current window. diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 6a800e5648..2a12a4d119 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -340,33 +340,33 @@ return { sinh={args=1, base=1, func="float_op_wrapper", data="&sinh"}, sockconnect={args={2,3}}, sort={args={1, 3}, base=1}, - soundfold={args=1}, + soundfold={args=1, base=1}, stdioopen={args=1}, - spellbadword={args={0, 1}}, - spellsuggest={args={1, 3}}, + spellbadword={args={0, 1}, base=1}, + spellsuggest={args={1, 3}, base=1}, split={args={1, 3}, base=1}, sqrt={args=1, base=1, func="float_op_wrapper", data="&sqrt"}, stdpath={args=1}, str2float={args=1, base=1}, str2list={args={1, 2}, base=1}, - str2nr={args={1, 3}}, - strcharpart={args={2, 3}}, - strchars={args={1,2}}, - strdisplaywidth={args={1, 2}}, - strftime={args={1, 2}}, - strgetchar={args={2, 2}}, - stridx={args={2, 3}}, + str2nr={args={1, 3}, base=1}, + strcharpart={args={2, 3}, base=1}, + strchars={args={1, 2}, base=1}, + strdisplaywidth={args={1, 2}, base=1}, + strftime={args={1, 2}, base=1}, + strgetchar={args=2, base=1}, + stridx={args={2, 3}, base=1}, string={args=1, base=1}, strlen={args=1, base=1}, - strpart={args={2, 4}}, + strpart={args={2, 4}, base=1}, strptime={args=2}, - strridx={args={2, 3}}, + strridx={args={2, 3}, base=1}, strtrans={args=1, base=1}, strwidth={args=1, base=1}, - submatch={args={1, 2}}, + submatch={args={1, 2}, base=1}, substitute={args=4, base=1}, - swapinfo={args={1}}, - swapname={args={1}}, + swapinfo={args=1, base=1}, + swapname={args=1, base=1}, synID={args=3}, synIDattr={args={2, 3}, base=1}, synIDtrans={args=1, base=1}, diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim index 277050876e..8d592f21ea 100644 --- a/src/nvim/testdir/test_breakindent.vim +++ b/src/nvim/testdir/test_breakindent.vim @@ -432,7 +432,7 @@ func Test_breakindent11_vartabs() call s:test_windows('setl cpo-=n sbr=>> nu nuw=4 nolist briopt= ts=4 vts=4') let text = getline(2) let width = strlen(text[1:]) + 2->indent() + strlen(&sbr) * 3 " text wraps 3 times - call assert_equal(width, strdisplaywidth(text)) + call assert_equal(width, text->strdisplaywidth()) call s:close_windows('set sbr= vts&') endfunc diff --git a/src/nvim/testdir/test_expr.vim b/src/nvim/testdir/test_expr.vim index a8cf6577f6..1d7fd3e385 100644 --- a/src/nvim/testdir/test_expr.vim +++ b/src/nvim/testdir/test_expr.vim @@ -56,7 +56,7 @@ endfunc func Test_strgetchar() call assert_equal(char2nr('a'), strgetchar('axb', 0)) - call assert_equal(char2nr('x'), strgetchar('axb', 1)) + call assert_equal(char2nr('x'), 'axb'->strgetchar(1)) call assert_equal(char2nr('b'), strgetchar('axb', 2)) call assert_equal(-1, strgetchar('axb', -1)) @@ -66,7 +66,7 @@ endfunc func Test_strcharpart() call assert_equal('a', strcharpart('axb', 0, 1)) - call assert_equal('x', strcharpart('axb', 1, 1)) + call assert_equal('x', 'axb'->strcharpart(1, 1)) call assert_equal('b', strcharpart('axb', 2, 1)) call assert_equal('xb', strcharpart('axb', 1)) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index ef33cd5dd8..472cb46525 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -143,7 +143,7 @@ func Test_str2nr() call assert_equal(-123456789, str2nr('-123456789')) call assert_equal(5, str2nr('101', 2)) - call assert_equal(5, str2nr('0b101', 2)) + call assert_equal(5, '0b101'->str2nr(2)) call assert_equal(5, str2nr('0B101', 2)) call assert_equal(-5, str2nr('-101', 2)) call assert_equal(-5, str2nr('-0b101', 2)) @@ -200,7 +200,7 @@ func Test_strftime() " of strftime() can be 17 or 18, depending on timezone. call assert_match('^2017-01-1[78]$', strftime('%Y-%m-%d', 1484695512)) " - call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', strftime('%Y-%m-%d %H:%M:%S')) + call assert_match('^\d\d\d\d-\(0\d\|1[012]\)-\([012]\d\|3[01]\) \([01]\d\|2[0-3]\):[0-5]\d:\([0-5]\d\|60\)$', '%Y-%m-%d %H:%M:%S'->strftime()) call assert_fails('call strftime([])', 'E730:') call assert_fails('call strftime("%Y", [])', 'E745:') @@ -375,7 +375,7 @@ endfunc func Test_strpart() call assert_equal('de', strpart('abcdefg', 3, 2)) call assert_equal('ab', strpart('abcdefg', -2, 4)) - call assert_equal('abcdefg', strpart('abcdefg', -2)) + call assert_equal('abcdefg', 'abcdefg'->strpart(-2)) call assert_equal('fg', strpart('abcdefg', 5, 4)) call assert_equal('defg', strpart('abcdefg', 3)) @@ -809,11 +809,11 @@ endfunc func Test_stridx() call assert_equal(-1, stridx('', 'l')) call assert_equal(0, stridx('', '')) - call assert_equal(0, stridx('hello', '')) + call assert_equal(0, 'hello'->stridx('')) call assert_equal(-1, stridx('hello', 'L')) call assert_equal(2, stridx('hello', 'l', -1)) call assert_equal(2, stridx('hello', 'l', 0)) - call assert_equal(2, stridx('hello', 'l', 1)) + call assert_equal(2, 'hello'->stridx('l', 1)) call assert_equal(3, stridx('hello', 'l', 3)) call assert_equal(-1, stridx('hello', 'l', 4)) call assert_equal(-1, stridx('hello', 'l', 10)) @@ -826,7 +826,7 @@ func Test_strridx() call assert_equal(0, strridx('', '')) call assert_equal(5, strridx('hello', '')) call assert_equal(-1, strridx('hello', 'L')) - call assert_equal(3, strridx('hello', 'l')) + call assert_equal(3, 'hello'->strridx('l')) call assert_equal(3, strridx('hello', 'l', 10)) call assert_equal(3, strridx('hello', 'l', 3)) call assert_equal(2, strridx('hello', 'l', 2)) diff --git a/src/nvim/testdir/test_spell.vim b/src/nvim/testdir/test_spell.vim index e525d06ea2..cf0faeee31 100644 --- a/src/nvim/testdir/test_spell.vim +++ b/src/nvim/testdir/test_spell.vim @@ -77,7 +77,7 @@ func Test_spellbadword() set spell call assert_equal(['bycycle', 'bad'], spellbadword('My bycycle.')) - call assert_equal(['another', 'caps'], spellbadword('A sentence. another sentence')) + call assert_equal(['another', 'caps'], 'A sentence. another sentence'->spellbadword()) call assert_equal(['TheCamelWord', 'bad'], spellbadword('TheCamelWord asdf')) set spelloptions=camel @@ -407,7 +407,7 @@ func Test_zz_basic() \ ) call assert_equal("gebletegek", soundfold('goobledygoook')) - call assert_equal("kepereneven", soundfold('kóopërÿnôven')) + call assert_equal("kepereneven", 'kóopërÿnôven'->soundfold()) call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale')) endfunc @@ -711,7 +711,7 @@ func TestGoodBadBase() break endif let prevbad = bad - let lst = spellsuggest(bad, 3) + let lst = bad->spellsuggest(3) normal mm call add(result, [bad, lst]) diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index e7f9bb76f2..f06705a84c 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -547,7 +547,7 @@ func Test_sub_replace_5() \ substitute('A123456789', \ 'A\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)\(.\)', \ '\=string([submatch(0, 1), submatch(9, 1), ' . - \ 'submatch(8, 1), submatch(7, 1), submatch(6, 1), ' . + \ 'submatch(8, 1), 7->submatch(1), submatch(6, 1), ' . \ 'submatch(5, 1), submatch(4, 1), submatch(3, 1), ' . \ 'submatch(2, 1), submatch(1, 1)])', \ '')) diff --git a/src/nvim/testdir/test_swap.vim b/src/nvim/testdir/test_swap.vim index e3101d4e44..b3018b2b0d 100644 --- a/src/nvim/testdir/test_swap.vim +++ b/src/nvim/testdir/test_swap.vim @@ -113,7 +113,7 @@ func Test_swapinfo() w let fname = s:swapname() call assert_match('Xswapinfo', fname) - let info = swapinfo(fname) + let info = fname->swapinfo() let ver = printf('VIM %d.%d', v:version / 100, v:version % 100) call assert_equal(ver, info.version) @@ -155,7 +155,7 @@ func Test_swapname() let buf = bufnr('%') let expected = s:swapname() wincmd p - call assert_equal(expected, swapname(buf)) + call assert_equal(expected, buf->swapname()) new Xtest3 setlocal noswapfile diff --git a/src/nvim/testdir/test_utf8.vim b/src/nvim/testdir/test_utf8.vim index 1f2cdde5cf..0818c2e4b0 100644 --- a/src/nvim/testdir/test_utf8.vim +++ b/src/nvim/testdir/test_utf8.vim @@ -17,7 +17,7 @@ func Test_strchars() let exp = [[1, 1, 1], [3, 3, 3], [2, 2, 1], [3, 3, 1], [1, 1, 1]] for i in range(len(inp)) call assert_equal(exp[i][0], strchars(inp[i])) - call assert_equal(exp[i][1], strchars(inp[i], 0)) + call assert_equal(exp[i][1], inp[i]->strchars(0)) call assert_equal(exp[i][2], strchars(inp[i], 1)) endfor endfunc From 39776d1a6513e33a33addb69deae72ab2ecafef4 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 00:28:00 +0000 Subject: [PATCH 06/16] vim-patch:8.1.2011: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make various functions usable as a method. Make the window command test faster. https://github.com/vim/vim/commit/ce90e36f5969e733a0a919f1736453332c33aad6 test_* functions in the patch are N/A as they modify internal state. Include test changes for test_ignore_error and test_feedinput (though they aren't run). Other changed tests were excluded from previous patches, except test_termcodes.vim, which hasn't been ported yet. --- runtime/doc/eval.txt | 8 ++++++++ src/nvim/eval.lua | 6 +++--- src/nvim/testdir/test_messages.vim | 2 +- src/nvim/testdir/test_taglist.vim | 2 +- src/nvim/testdir/test_timers.vim | 2 +- src/nvim/testdir/test_window_cmd.vim | 11 +++++++---- 6 files changed, 21 insertions(+), 10 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index fcaed24b1f..758c93231d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -9982,6 +9982,8 @@ tabpagebuflist([{arg}]) *tabpagebuflist()* endfor < Note that a buffer may appear in more than one window. + Can also be used as a |method|: > + GetTabpage()->tabpagebuflist() tabpagenr([{arg}]) *tabpagenr()* The result is a Number, which is the number of the current @@ -10008,6 +10010,9 @@ tabpagewinnr({tabarg} [, {arg}]) *tabpagewinnr()* tabpagewinnr(4, '$') " number of windows in tab page 4 < When {tabarg} is invalid zero is returned. + Can also be used as a |method|: > + GetTabpage()->tabpagewinnr() +< *tagfiles()* tagfiles() Returns a |List| with the file names used to search for tags for the current buffer. This is the 'tags' option expanded. @@ -10056,6 +10061,9 @@ taglist({expr} [, {filename}]) *taglist()* located by Vim. Refer to |tags-file-format| for the format of the tags file generated by the different ctags tools. + Can also be used as a |method|: > + GetTagpattern()->taglist() + tempname() *tempname()* *temp-file-name* The result is a String, which is the name of a file that doesn't exist. It can be used for a temporary file. Example: > diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 2a12a4d119..d685387995 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -374,11 +374,11 @@ return { synstack={args=2}, system={args={1, 2}, base=1}, systemlist={args={1, 3}, base=1}, - tabpagebuflist={args={0, 1}}, + tabpagebuflist={args={0, 1}, base=1}, tabpagenr={args={0, 1}}, - tabpagewinnr={args={1, 2}}, + tabpagewinnr={args={1, 2}, base=1}, tagfiles={}, - taglist={args={1, 2}}, + taglist={args={1, 2}, base=1}, tan={args=1, base=1, func="float_op_wrapper", data="&tan"}, tanh={args=1, base=1, func="float_op_wrapper", data="&tanh"}, tempname={}, diff --git a/src/nvim/testdir/test_messages.vim b/src/nvim/testdir/test_messages.vim index 08586dffe1..2140fe21ea 100644 --- a/src/nvim/testdir/test_messages.vim +++ b/src/nvim/testdir/test_messages.vim @@ -87,7 +87,7 @@ func Test_echoerr() if has('float') call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) endif - call test_ignore_error('') + eval ''->test_ignore_error() call assert_match("function('\\d*')", execute(':echoerr {-> 1234}')) call test_ignore_error('RESET') endfunc diff --git a/src/nvim/testdir/test_taglist.vim b/src/nvim/testdir/test_taglist.vim index e830813081..e11815ff33 100644 --- a/src/nvim/testdir/test_taglist.vim +++ b/src/nvim/testdir/test_taglist.vim @@ -14,7 +14,7 @@ func Test_taglist() split Xtext call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name})) - call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name})) + call assert_equal(['FFoo', 'BFoo'], map("Foo"->taglist("Xtext"), {i, v -> v.name})) call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name})) call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name})) diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index ceaa5de92b..e41a691467 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -239,7 +239,7 @@ func FeedAndPeek(timer) endfunc func Interrupt(timer) - " call test_feedinput("\") + " eval "\"->test_feedinput() call nvim_input("\") endfunc diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 039de0c623..588ff5a103 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -452,7 +452,7 @@ func Test_window_newtab() wincmd T call assert_equal(2, tabpagenr('$')) call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) - call assert_equal(['Xc' ], map(tabpagebuflist(2), 'bufname(v:val)')) + call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) %bw! endfunc @@ -577,8 +577,11 @@ endfunc function! Fun_RenewFile() " Need to wait a bit for the timestamp to be older. - sleep 2 - silent execute '!echo "1" > tmp.txt' + let old_ftime = getftime("tmp.txt") + while getftime("tmp.txt") == old_ftime + sleep 100m + silent execute '!echo "1" > tmp.txt' + endwhile sp wincmd p edit! tmp.txt @@ -814,7 +817,7 @@ func Test_winnr() tabnew call assert_equal(8, tabpagewinnr(1, 'j')) - call assert_equal(2, tabpagewinnr(1, 'k')) + call assert_equal(2, 1->tabpagewinnr('k')) call assert_equal(4, tabpagewinnr(1, 'h')) call assert_equal(6, tabpagewinnr(1, 'l')) From 38a831e54a7261fda06555bc7464546ecfcbf897 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 16:21:16 +0000 Subject: [PATCH 07/16] vim-patch:7.4.1777 Problem: Newly added features can escape the sandbox. Solution: Add checks for restricted and secure. (Yasuhiro Matsumoto) https://github.com/vim/vim/commit/3849992b16011e36a5cb5be4b127f843389b96fd timer_start is missing check_secure. The timer callback can, for example, call a function defined from outside the sandbox that does stuff that would be disallowed from inside the sandbox. This is usually not allowed. Cherry-pick eval.txt change from: https://github.com/vim/vim/commit/68e6560b84f196c82e27a72669684d5506a3a837 Required for v8.1.2013. --- runtime/doc/eval.txt | 2 ++ src/nvim/eval/funcs.c | 3 +++ test/functional/vimscript/timer_spec.lua | 10 ++++++++++ 3 files changed, 15 insertions(+) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 758c93231d..234879218e 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -10171,6 +10171,8 @@ timer_start({time}, {callback} [, {options}]) \ {'repeat': 3}) < This invokes MyHandler() three times at 500 msec intervals. + Not available in the |sandbox|. + timer_stop({timer}) *timer_stop()* Stop a timer. The timer callback will no longer be invoked. {timer} is an ID returned by timer_start(), thus it must be a diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index dfadd28ebe..33ca4016cf 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -11551,6 +11551,9 @@ static void f_timer_start(typval_T *argvars, typval_T *rettv, FunPtr fptr) dict_T *dict; rettv->vval.v_number = -1; + if (check_secure()) { + return; + } if (argvars[2].v_type != VAR_UNKNOWN) { if (argvars[2].v_type != VAR_DICT diff --git a/test/functional/vimscript/timer_spec.lua b/test/functional/vimscript/timer_spec.lua index 9ee0735e40..e45b64422f 100644 --- a/test/functional/vimscript/timer_spec.lua +++ b/test/functional/vimscript/timer_spec.lua @@ -3,6 +3,7 @@ local Screen = require('test.functional.ui.screen') local feed, eq, eval, ok = helpers.feed, helpers.eq, helpers.eval, helpers.ok local source, nvim_async, run = helpers.source, helpers.nvim_async, helpers.run local clear, command, funcs = helpers.clear, helpers.command, helpers.funcs +local exc_exec = helpers.exc_exec local curbufmeths = helpers.curbufmeths local load_adjust = helpers.load_adjust local retry = helpers.retry @@ -262,4 +263,13 @@ describe('timers', function() eq(2, eval('g:val')) end) + + it("timer_start can't be used in the sandbox", function() + source [[ + function! Scary(timer) abort + call execute('echo ''execute() should be disallowed''', '') + endfunction + ]] + eq("Vim(call):E48: Not allowed in sandbox", exc_exec("sandbox call timer_start(0, 'Scary')")) + end) end) From 2ad92e947650cc502952b3ec23a23f9862f3a76d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 16:26:19 +0000 Subject: [PATCH 08/16] vim-patch:8.1.2013: 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/f92e58cadb03156879e9bdbf6341bf662d9c87cc Cherry-pick s:normalize_fname for tolower test from v8.1.0894 and v8.1.1417 (even though it is unused for now). Fix header for win_id2tabwin in eval.txt. --- runtime/doc/eval.txt | 75 ++++++++++++++++++++++++-- src/nvim/eval.lua | 46 ++++++++-------- src/nvim/testdir/test_cursor_func.vim | 2 +- src/nvim/testdir/test_execute_func.vim | 2 +- src/nvim/testdir/test_functions.vim | 17 ++++-- src/nvim/testdir/test_listchars.vim | 2 +- src/nvim/testdir/test_timers.vim | 8 +-- src/nvim/testdir/test_undo.vim | 2 +- src/nvim/testdir/test_window_cmd.vim | 18 +++++-- src/nvim/testdir/test_window_id.vim | 17 ++++-- 10 files changed, 143 insertions(+), 46 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 234879218e..632329a65e 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -10131,6 +10131,9 @@ timer_info([{id}]) -1 means forever "callback" the callback + Can also be used as a |method|: > + GetTimer()->timer_info() +< timer_pause({timer}, {paused}) *timer_pause()* Pause or unpause a timer. A paused timer does not invoke its callback when its time expires. Unpausing a timer may cause @@ -10144,6 +10147,9 @@ timer_pause({timer}, {paused}) *timer_pause()* String, then the timer is paused, otherwise it is unpaused. See |non-zero-arg|. + Can also be used as a |method|: > + GetTimer()->timer_pause(1) +< *timer_start()* *timer* *timers* timer_start({time}, {callback} [, {options}]) Create a timer and return the timer ID. @@ -10171,13 +10177,19 @@ timer_start({time}, {callback} [, {options}]) \ {'repeat': 3}) < This invokes MyHandler() three times at 500 msec intervals. - Not available in the |sandbox|. + Can also be used as a |method|: > + GetMsec()->timer_start(callback) + +< Not available in the |sandbox|. timer_stop({timer}) *timer_stop()* Stop a timer. The timer callback will no longer be invoked. {timer} is an ID returned by timer_start(), thus it must be a Number. If {timer} does not exist there is no error. + Can also be used as a |method|: > + GetTimer()->timer_stop() +< timer_stopall() *timer_stopall()* Stop all timers. The timer callbacks will no longer be invoked. Useful if some timers is misbehaving. If there are @@ -10188,11 +10200,17 @@ tolower({expr}) *tolower()* characters turned into lowercase (just like applying |gu| to the string). + Can also be used as a |method|: > + GetText()->tolower() + toupper({expr}) *toupper()* The result is a copy of the String given, with all lowercase characters turned into uppercase (just like applying |gU| to the string). + Can also be used as a |method|: > + GetText()->toupper() + tr({src}, {fromstr}, {tostr}) *tr()* The result is a copy of the {src} string with all characters which appear in {fromstr} replaced by the character in that @@ -10207,6 +10225,9 @@ tr({src}, {fromstr}, {tostr}) *tr()* echo tr("", "<>", "{}") < returns "{blob}" + Can also be used as a |method|: > + GetText()->tr(from, to) + trim({text} [, {mask} [, {dir}]]) *trim()* Return {text} as a String where any character in {mask} is removed from the beginning and/or end of {text}. @@ -10230,6 +10251,9 @@ trim({text} [, {mask} [, {dir}]]) *trim()* echo trim(" vim ", " ", 2) < returns " vim" + Can also be used as a |method|: > + GetText()->trim() + trunc({expr}) *trunc()* Return the largest integral value with magnitude less than or equal to {expr} as a |Float| (truncate towards zero). @@ -10286,6 +10310,9 @@ undofile({name}) *undofile()* buffer without a file name will not write an undo file. Useful in combination with |:wundo| and |:rundo|. + Can also be used as a |method|: > + GetFilename()->undofile() + undotree() *undotree()* Return the current state of the undo tree in a dictionary with the following items: @@ -10384,8 +10411,10 @@ virtcol({expr}) *virtcol()* all lines: > echo max(map(range(1, line('$')), "virtcol([v:val, '$'])")) +< Can also be used as a |method|: > + GetPos()->virtcol() -visualmode([expr]) *visualmode()* +visualmode([{expr}]) *visualmode()* The result is a String, which describes the last Visual mode used in the current buffer. Initially it returns an empty string, but once Visual mode has been used, it returns "v", @@ -10399,7 +10428,7 @@ visualmode([expr]) *visualmode()* Visual mode that was used. If Visual mode is active, use |mode()| to get the Visual mode (e.g., in a |:vmap|). - If [expr] is supplied and it evaluates to a non-zero Number or + If {expr} is supplied and it evaluates to a non-zero Number or a non-empty String, then the Visual mode will be cleared and the old value is returned. See |non-zero-arg|. @@ -10438,11 +10467,18 @@ win_execute({id}, {command} [, {silent}]) *win_execute()* have unexpected side effects. Use |:noautocmd| if needed. Example: > call win_execute(winid, 'syntax enable') +< + Can also be used as a |method|, the base is used for the + command: > + GetCommand()->win_execute(winid) win_findbuf({bufnr}) *win_findbuf()* Returns a |List| with |window-ID|s for windows that contain buffer {bufnr}. When there is none the list is empty. + Can also be used as a |method|: > + GetBufnr()->win_findbuf() + win_getid([{win} [, {tab}]]) *win_getid()* Get the |window-ID| for the specified window. When {win} is missing use the current window. @@ -10452,6 +10488,9 @@ win_getid([{win} [, {tab}]]) *win_getid()* number {tab}. The first tab has number one. Return zero if the window cannot be found. + Can also be used as a |method|: > + GetWinnr()->win_getid() + win_gettype([{nr}]) *win_gettype()* Return the type of the window: "autocmd" autocommand window. Temporary window @@ -10477,15 +10516,24 @@ win_gotoid({expr}) *win_gotoid()* tabpage. Return TRUE if successful, FALSE if the window cannot be found. -win_id2tabwin({expr} *win_id2tabwin()* + Can also be used as a |method|: > + GetWinid()->win_gotoid() + +win_id2tabwin({expr}) *win_id2tabwin()* Return a list with the tab number and window number of window with ID {expr}: [tabnr, winnr]. Return [0, 0] if the window cannot be found. + Can also be used as a |method|: > + GetWinid()->win_id2tabwin() + win_id2win({expr}) *win_id2win()* Return the window number of window with ID {expr}. Return 0 if the window cannot be found in the current tabpage. + Can also be used as a |method|: > + GetWinid()->win_id2win() + win_screenpos({nr}) *win_screenpos()* Return the screen position of window {nr} as a list with two numbers: [row, col]. The first window always has position @@ -10495,6 +10543,9 @@ win_screenpos({nr}) *win_screenpos()* Returns [0, 0] if the window cannot be found in the current tabpage. + Can also be used as a |method|: > + GetWinid()->win_screenpos() +< win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* Move the window {nr} to a new split of the window {target}. This is similar to moving to {target}, creating a new window @@ -10549,6 +10600,9 @@ winheight({nr}) *winheight()* This excludes any window toolbar line. Examples: > :echo "The current window has " . winheight(0) . " lines." + +< Can also be used as a |method|: > + GetWinid()->winheight() < winlayout([{tabnr}]) *winlayout()* The result is a nested List containing the layout of windows @@ -10579,6 +10633,9 @@ winlayout([{tabnr}]) *winlayout()* :echo winlayout(2) ['col', [['leaf', 1002], ['row', [['leaf', 1003], ['leaf', 1001]]], ['leaf', 1000]]] +< + Can also be used as a |method|: > + GetTabnr()->winlayout() < *winline()* winline() The result is a Number, which is the screen line of the cursor @@ -10614,6 +10671,9 @@ winnr([{arg}]) The result is a Number, which is the number of the current let window_count = winnr('$') let prev_window = winnr('#') let wnum = winnr('3k') + +< Can also be used as a |method|: > + GetWinval()->winnr() < *winrestcmd()* winrestcmd() Returns a sequence of |:resize| commands that should restore @@ -10642,6 +10702,9 @@ winrestview({dict}) If you have changed the values the result is unpredictable. If the window size changed the result won't be the same. + Can also be used as a |method|: > + GetView()->winrestview() +< *winsaveview()* winsaveview() Returns a |Dictionary| that contains information to restore the view of the current window. Use |winrestview()| to @@ -10680,6 +10743,8 @@ winwidth({nr}) *winwidth()* < For getting the terminal or screen size, see the 'columns' option. + Can also be used as a |method|: > + GetWinid()->winwidth() wordcount() *wordcount()* The result is a dictionary of byte/chars/word statistics for @@ -10738,6 +10803,8 @@ writefile({object}, {fname} [, {flags}]) :let fl = readfile("foo", "b") :call writefile(fl, "foocopy", "b") +< Can also be used as a |method|: > + GetText()->writefile("thefile") xor({expr}, {expr}) *xor()* Bitwise XOR on the two arguments. The arguments are converted diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index d685387995..fdbf93b9c5 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -385,47 +385,47 @@ return { termopen={args={1, 2}}, test_garbagecollect_now={}, test_write_list_log={args=1}, - timer_info={args={0,1}}, - timer_pause={args=2}, - timer_start={args={2,3}}, - timer_stop={args=1}, + timer_info={args={0, 1}, base=1}, + timer_pause={args=2, base=1}, + timer_start={args={2, 3}, base=1}, + timer_stop={args=1, base=1}, timer_stopall={args=0}, - tolower={args=1}, - toupper={args=1}, - tr={args=3}, - trim={args={1,3}}, + tolower={args=1, base=1}, + toupper={args=1, base=1}, + tr={args=3, base=1}, + trim={args={1, 3}, base=1}, trunc={args=1, base=1, func="float_op_wrapper", data="&trunc"}, type={args=1, base=1}, - undofile={args=1}, + undofile={args=1, base=1}, undotree={}, uniq={args={1, 3}, base=1}, values={args=1, base=1}, - virtcol={args=1}, + virtcol={args=1, base=1}, visualmode={args={0, 1}}, wait={args={2,3}}, wildmenumode={}, - win_execute={args={2, 3}}, - win_findbuf={args=1}, - win_getid={args={0,2}}, + win_execute={args={2, 3}, base=2}, + win_findbuf={args=1, base=1}, + win_getid={args={0, 2}, base=1}, win_gettype={args={0,1}}, - win_gotoid={args=1}, - win_id2tabwin={args=1}, - win_id2win={args=1}, - win_screenpos={args=1}, + win_gotoid={args=1, base=1}, + win_id2tabwin={args=1, base=1}, + win_id2win={args=1, base=1}, + win_screenpos={args=1, base=1}, win_splitmove={args={2, 3}}, winbufnr={args=1, base=1}, wincol={}, windowsversion={}, - winheight={args=1}, - winlayout={args={0, 1}}, + winheight={args=1, base=1}, + winlayout={args={0, 1}, base=1}, winline={}, - winnr={args={0, 1}}, + winnr={args={0, 1}, base=1}, winrestcmd={}, - winrestview={args=1}, + winrestview={args=1, base=1}, winsaveview={}, - winwidth={args=1}, + winwidth={args=1, base=1}, wordcount={}, - writefile={args={2, 3}}, + writefile={args={2, 3}, base=1}, xor={args=2, base=1}, }, } diff --git a/src/nvim/testdir/test_cursor_func.vim b/src/nvim/testdir/test_cursor_func.vim index d96a35ef53..e8c4a952ee 100644 --- a/src/nvim/testdir/test_cursor_func.vim +++ b/src/nvim/testdir/test_cursor_func.vim @@ -82,7 +82,7 @@ func Test_screenpos() call assert_equal({'row': winrow, \ 'col': wincol + 0, \ 'curscol': wincol + 7, - \ 'endcol': wincol + 7}, screenpos(winid, 1, 1)) + \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) call assert_equal({'row': winrow, \ 'col': wincol + 13, \ 'curscol': wincol + 13, diff --git a/src/nvim/testdir/test_execute_func.vim b/src/nvim/testdir/test_execute_func.vim index f2c7da0aa9..2cb6d73407 100644 --- a/src/nvim/testdir/test_execute_func.vim +++ b/src/nvim/testdir/test_execute_func.vim @@ -99,7 +99,7 @@ func Test_win_execute() if has('textprop') let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) redraw - let line = win_execute(popupwin, 'echo getline(1)') + let line = 'echo getline(1)'->win_execute(popupwin) call assert_match('the popup win', line) call popup_close(popupwin) diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 472cb46525..c450ac50d4 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -307,6 +307,12 @@ func Test_resolve_unix() call assert_equal('/', resolve('/')) endfunc +func s:normalize_fname(fname) + let ret = substitute(a:fname, '\', '/', 'g') + let ret = substitute(ret, '//', '/', 'g') + return ret->tolower() +endfunc + func Test_simplify() call assert_equal('', simplify('')) call assert_equal('/', simplify('/')) @@ -469,7 +475,7 @@ func Test_toupper() \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) " Test with a few lowercase diacritics. - call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả")) + call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper()) call assert_equal("BḂḆ", toupper("bḃḇ")) call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) @@ -532,6 +538,11 @@ func Test_toupper() call toupper("123\xC0\x80\xC0") endfunc +func Test_tr() + call assert_equal('foo', tr('bar', 'bar', 'foo')) + call assert_equal('zxy', 'cab'->tr('abc', 'xyz')) +endfunc + " Tests for the mode() function let current_modes = '' func Save_mode() @@ -1293,7 +1304,7 @@ endfunc func Test_trim() call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) - call assert_equal("Testing", trim(" \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B")) + call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim()) call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) @@ -1560,7 +1571,7 @@ func Test_bufadd_bufload() call assert_equal([''], getbufline(buf, 1, '$')) let curbuf = bufnr('') - call writefile(['some', 'text'], 'XotherName') + eval ['some', 'text']->writefile('XotherName') let buf = 'XotherName'->bufadd() call assert_notequal(0, buf) eval 'XotherName'->bufexists()->assert_equal(1) diff --git a/src/nvim/testdir/test_listchars.vim b/src/nvim/testdir/test_listchars.vim index 9906b00222..f4ee539803 100644 --- a/src/nvim/testdir/test_listchars.vim +++ b/src/nvim/testdir/test_listchars.vim @@ -25,7 +25,7 @@ func Test_listchars() redraw! for i in range(1, 5) call cursor(i, 1) - call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol())) endfor set listchars-=trail:< diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index e41a691467..5cc0da2586 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -77,7 +77,7 @@ endfunc func Test_info() let id = timer_start(1000, 'MyHandler') - let info = timer_info(id) + let info = id->timer_info() call assert_equal(id, info[0]['id']) call assert_equal(1000, info[0]['time']) call assert_equal("function('MyHandler')", string(info[0]['callback'])) @@ -113,7 +113,7 @@ func Test_paused() let info = timer_info(id) call assert_equal(0, info[0]['paused']) - call timer_pause(id, 1) + eval id->timer_pause(1) let info = timer_info(id) call assert_equal(1, info[0]['paused']) sleep 200m @@ -148,7 +148,7 @@ func Test_delete_myself() endfunc func StopTimer1(timer) - let g:timer2 = timer_start(10, 'StopTimer2') + let g:timer2 = 10->timer_start('StopTimer2') " avoid maxfuncdepth error call timer_pause(g:timer1, 1) sleep 40m @@ -251,7 +251,7 @@ func Test_peek_and_get_char() let intr = timer_start(100, 'Interrupt') let c = getchar() call assert_equal(char2nr('a'), c) - call timer_stop(intr) + eval intr->timer_stop() endfunc func Test_getchar_zero() diff --git a/src/nvim/testdir/test_undo.vim b/src/nvim/testdir/test_undo.vim index c7dcaa0f36..30e00e7ad4 100644 --- a/src/nvim/testdir/test_undo.vim +++ b/src/nvim/testdir/test_undo.vim @@ -490,7 +490,7 @@ funct Test_undofile() call delete('Xundodir', 'd') " Test undofile() with 'undodir' set to a non-existing directory. - " call assert_equal('', undofile('Xundofoo')) + " call assert_equal('', 'Xundofoo'->undofile()) if isdirectory('/tmp') set undodir=/tmp diff --git a/src/nvim/testdir/test_window_cmd.vim b/src/nvim/testdir/test_window_cmd.vim index 588ff5a103..a200bf7d42 100644 --- a/src/nvim/testdir/test_window_cmd.vim +++ b/src/nvim/testdir/test_window_cmd.vim @@ -72,7 +72,7 @@ endfunc func Test_window_quit() e Xa split Xb - call assert_equal(2, winnr('$')) + call assert_equal(2, '$'->winnr()) call assert_equal('Xb', bufname(winbufnr(1))) call assert_equal('Xa', bufname(winbufnr(2))) @@ -88,7 +88,7 @@ func Test_window_horizontal_split() 3wincmd s call assert_equal(2, winnr('$')) call assert_equal(3, winheight(0)) - call assert_equal(winwidth(1), winwidth(2)) + call assert_equal(winwidth(1), 2->winwidth()) call assert_fails('botright topleft wincmd s', 'E442:') bw @@ -267,7 +267,7 @@ func Test_window_height() wincmd + call assert_equal(wh1, winheight(1)) - call assert_equal(wh2, winheight(2)) + call assert_equal(wh2, 2->winheight()) 2wincmd _ call assert_equal(2, winheight(1)) @@ -824,6 +824,18 @@ func Test_winnr() only | tabonly endfunc +func Test_winrestview() + split runtest.vim + normal 50% + let view = winsaveview() + close + split runtest.vim + eval view->winrestview() + call assert_equal(view, winsaveview()) + + bwipe! +endfunc + func Test_win_splitmove() edit a leftabove split b diff --git a/src/nvim/testdir/test_window_id.vim b/src/nvim/testdir/test_window_id.vim index d10d831650..8bf4ede350 100644 --- a/src/nvim/testdir/test_window_id.vim +++ b/src/nvim/testdir/test_window_id.vim @@ -67,7 +67,7 @@ func Test_win_getid() call win_gotoid(id2) call assert_equal("two", expand("%")) - call win_gotoid(id4) + eval id4->win_gotoid() call assert_equal("four", expand("%")) call win_gotoid(id1) call assert_equal("one", expand("%")) @@ -75,17 +75,17 @@ func Test_win_getid() call assert_equal("five", expand("%")) call assert_equal(0, win_id2win(9999)) - call assert_equal(nr5, win_id2win(id5)) + call assert_equal(nr5, id5->win_id2win()) call assert_equal(0, win_id2win(id1)) tabnext call assert_equal(nr1, win_id2win(id1)) call assert_equal([0, 0], win_id2tabwin(9999)) - call assert_equal([1, nr2], win_id2tabwin(id2)) + call assert_equal([1, nr2], id2->win_id2tabwin()) call assert_equal([2, nr4], win_id2tabwin(id4)) call assert_equal([], win_findbuf(9999)) - call assert_equal([id2], win_findbuf(bufnr2)) + call assert_equal([id2], bufnr2->win_findbuf()) call win_gotoid(id5) split call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5))) @@ -98,7 +98,7 @@ func Test_win_getid_curtab() tabfirst copen only - call assert_equal(win_getid(1), win_getid(1, 1)) + call assert_equal(win_getid(1), 1->win_getid( 1)) tabclose! endfunc @@ -120,4 +120,11 @@ func Test_winlayout() call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout()) only! + + let w1 = win_getid() + call assert_equal(['leaf', w1], winlayout(1)) + tabnew + let w2 = win_getid() + call assert_equal(['leaf', w2], 2->winlayout()) + tabclose endfunc From f37f08314dd1dfbf5f6526c70802763ce86202ef Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 17:45:21 +0000 Subject: [PATCH 09/16] vim-patch:8.1.2166: rubyeval() not tested as a method Problem: Rubyeval() not tested as a method. Solution: Change a test case. https://github.com/vim/vim/commit/4a4981b7cd57b0b2289ed4f9d621ef4d90d767f0 --- src/nvim/testdir/test_ruby.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nvim/testdir/test_ruby.vim b/src/nvim/testdir/test_ruby.vim index 1a274d1fec..1fbf3392d9 100644 --- a/src/nvim/testdir/test_ruby.vim +++ b/src/nvim/testdir/test_ruby.vim @@ -60,7 +60,7 @@ func Test_ruby_set_cursor() " Check that movement after setting cursor position keeps current column. normal j call assert_equal([2, 6], [line('.'), col('.')]) - call assert_equal([2, 5], rubyeval('$curwin.cursor')) + call assert_equal([2, 5], '$curwin.cursor'->rubyeval()) " call assert_fails('ruby $curwin.cursor = [1]', " \ 'ArgumentError: array length must be 2') From 60f0e1858870849fa5d6ed56ea40dc0183fab77d Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 17:48:19 +0000 Subject: [PATCH 10/16] vim-patch:8.2.0532: cannot use simplify() as a method Problem: Cannot use simplify() as a method. Solution: Add FEARG_1. (closes vim/vim#5996) https://github.com/vim/vim/commit/7035fd9d909c49cf5105a53753c1772c193d05b8 --- runtime/doc/eval.txt | 2 ++ src/nvim/eval.lua | 2 +- src/nvim/testdir/test_functions.vim | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 632329a65e..385ecb3dc2 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -9123,6 +9123,8 @@ simplify({filename}) *simplify()* directory. In order to resolve all the involved symbolic links before simplifying the path name, use |resolve()|. + Can also be used as a |method|: > + GetName()->simplify() sin({expr}) *sin()* Return the sine of {expr}, measured in radians, as a |Float|. diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index fdbf93b9c5..161c0a4695 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -335,7 +335,7 @@ return { sign_undefine={args={0, 1}, base=1}, sign_unplace={args={1, 2}, base=1}, sign_unplacelist={args=1, base=1}, - simplify={args=1}, + simplify={args=1, base=1}, sin={args=1, base=1, func="float_op_wrapper", data="&sin"}, sinh={args=1, base=1, func="float_op_wrapper", data="&sinh"}, sockconnect={args={2,3}}, diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index c450ac50d4..0edbeb420a 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -319,7 +319,7 @@ func Test_simplify() call assert_equal('/', simplify('/.')) call assert_equal('/', simplify('/..')) call assert_equal('/...', simplify('/...')) - call assert_equal('./dir/file', simplify('./dir/file')) + call assert_equal('./dir/file', './dir/file'->simplify()) call assert_equal('./dir/file', simplify('.///dir//file')) call assert_equal('./dir/file', simplify('./dir/./file')) call assert_equal('./file', simplify('./dir/../file')) From 6bc9af43ceaf10992982369c74ac073072562068 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 17:49:43 +0000 Subject: [PATCH 11/16] vim-patch:8.2.0871: cannot use getmarklist() as a method Problem: Cannot use getmarklist() as a method. Solution: Make getmarklist() work as a method. Add one to the column number to match getpos(). (Yegappan Lakshmanan, closes vim/vim#6176) https://github.com/vim/vim/commit/f17e7ea67a798d0aa45ce24ea80c9e21d5164326 The rest of this patch was ported in: https://github.com/neovim/neovim/commit/a1ed941a7881122fda2fd48e71e890ed55e4d08e --- runtime/doc/eval.txt | 3 +++ src/nvim/eval.lua | 2 +- src/nvim/testdir/test_marks.vim | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 385ecb3dc2..d71381347d 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -5203,6 +5203,9 @@ getmarklist([{buf}]) *getmarklist()* Refer to |getpos()| for getting information about a specific mark. + Can also be used as a |method|: > + GetBufnr()->getmarklist() + getmatches([{win}]) *getmatches()* Returns a |List| with all matches previously defined for the current window by |matchadd()| and the |:match| commands. diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 161c0a4695..add1445f45 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -161,7 +161,7 @@ return { getjumplist={args={0, 2}, base=1}, getline={args={1, 2}, base=1}, getloclist={args={1, 2}}, - getmarklist={args={0, 1}}, + getmarklist={args={0, 1}, base=1}, getmatches={args={0, 1}}, getmousepos={}, getpid={}, diff --git a/src/nvim/testdir/test_marks.vim b/src/nvim/testdir/test_marks.vim index 2fd82a4b6d..b3035d73ce 100644 --- a/src/nvim/testdir/test_marks.vim +++ b/src/nvim/testdir/test_marks.vim @@ -227,7 +227,7 @@ func Test_getmarklist() call cursor(2, 2) normal mr call assert_equal({'mark' : "'r", 'pos' : [bufnr(), 2, 2, 0]}, - \ getmarklist(bufnr())[0]) - call assert_equal([], getmarklist({})) + \ bufnr()->getmarklist()[0]) + call assert_equal([], {}->getmarklist()) close! endfunc From 2c185a18cdc7c77aa67e44ba854f8ddd9b3f2de9 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 18:12:08 +0000 Subject: [PATCH 12/16] vim-patch:8.2.1168: wrong method argument for appendbufline() Problem: Wrong method argument for appendbufline(). Solution: Use FEARG_3. https://github.com/vim/vim/commit/92053ce59ecf93838f4d6e3019eef1bc47be4184 Cherry-pick base change for append (and appendbufline) from v8.2.1167. These changes have no visible impact, but helps us sync with Vim. Like Vim, BASE_LAST is now unused after this commit. Keep it anyway in case it sees use in the future. Comment-out LAST definition in eval.lua to appease linter. --- src/nvim/eval.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index add1445f45..bbbe84f2a2 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -17,7 +17,7 @@ end -- Usable with the base key: use the last function argument as the method base. -- Value is from funcs.h file. "BASE_" prefix is omitted. -local LAST = "BASE_LAST" +-- local LAST = "BASE_LAST" (currently unused after port of v8.2.1168) return { funcs={ @@ -26,8 +26,8 @@ return { add={args=2, base=1}, ['and']={args=2, base=1}, api_info={}, - append={args=2, base=LAST}, - appendbufline={args=3, base=LAST}, + append={args=2, base=2}, + appendbufline={args=3, base=3}, argc={args={0, 1}}, argidx={}, arglistid={args={0, 2}}, From a0c7fff2840d0fc322e049fd06bf1e8e5bd0f38c Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 18:18:02 +0000 Subject: [PATCH 13/16] vim-patch:8.2.1241: cannot use getbufinfo() as a method Problem: Cannot use getbufinfo() as a method. Solution: Support using getbufinfo() as a method. (closes vim/vim#6458) https://github.com/vim/vim/commit/6434fc574dfbde11461e70e5a62712370edf38e6 --- runtime/doc/eval.txt | 4 +++- src/nvim/eval.lua | 2 +- src/nvim/testdir/test_bufwintabinfo.vim | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index d71381347d..8e6864889c 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -4701,7 +4701,9 @@ getbufinfo([{dict}]) < To get buffer-local options use: > getbufvar({bufnr}, '&option_name') - +< + Can also be used as a |method|: > + GetBufnr()->getbufinfo() < *getbufline()* getbufline({buf}, {lnum} [, {end}]) diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index bbbe84f2a2..75e28df98f 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -137,7 +137,7 @@ return { ['function']={args={1, 3}, base=1}, garbagecollect={args={0, 1}}, get={args={2, 3}, base=1}, - getbufinfo={args={0, 1}}, + getbufinfo={args={0, 1}, base=1}, getbufline={args={2, 3}, base=1}, getbufvar={args={2, 3}, base=1}, getchangelist={args={0, 1}, base=1}, diff --git a/src/nvim/testdir/test_bufwintabinfo.vim b/src/nvim/testdir/test_bufwintabinfo.vim index d2c99563d9..a6eb93b4be 100644 --- a/src/nvim/testdir/test_bufwintabinfo.vim +++ b/src/nvim/testdir/test_bufwintabinfo.vim @@ -20,6 +20,9 @@ function Test_getbufwintabinfo() call assert_equal('vim', l[0].variables.editor) call assert_notequal(-1, index(l[0].windows, '%'->bufwinid())) + let l = '%'->getbufinfo() + call assert_equal(bufnr('%'), l[0].bufnr) + " Test for getbufinfo() with 'bufmodified' call assert_equal(0, len(getbufinfo({'bufmodified' : 1}))) call setbufline('Xtestfile1', 1, ["Line1"]) From 7e1a2301fffa32d60ecb7c15891a106d717100db Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sun, 31 Oct 2021 17:15:17 +0000 Subject: [PATCH 14/16] docs(eval): cherry-pick runtime update 2e693a88b2 https://github.com/vim/vim/commit/2e693a88b24dc6b12883fad78ff2cb9cd4469c98 Mainly to keep the method call docs up-to-date. Much of this RT update has already been ported. --- runtime/doc/eval.txt | 58 +++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 8e6864889c..4b49cb6b6e 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3397,8 +3397,8 @@ 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: > + Can also be used as a |method|, the base is passed as the + second argument: > GetMatches()->complete(col('.')) complete_add({expr}) *complete_add()* @@ -3535,7 +3535,7 @@ confirm({msg} [, {choices} [, {default} [, {type}]]]) 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. @@ -3746,7 +3746,7 @@ deletebufline({buf}, {first}[, {last}]) *deletebufline()* 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: @@ -3941,7 +3941,7 @@ exepath({expr}) *exepath()* Can also be used as a |method|: > GetCommand()->exepath() - +< *exists()* exists({expr}) The result is a Number, which is |TRUE| if {expr} is defined, zero otherwise. @@ -4487,7 +4487,7 @@ foldlevel({lnum}) *foldlevel()* Can also be used as a |method|: > GetLnum()->foldlevel() - +< *foldtext()* foldtext() Returns a String, to be displayed for a closed fold. This is the default function used for the 'foldtext' option and should @@ -5861,7 +5861,7 @@ histadd({history}, {item}) *histadd()* :let date=input("Enter date: ") < This function is not available in the |sandbox|. - Can also be used as a |method|, the base is used for the + Can also be used as a |method|, the base is passed as the second argument: > GetHistory()->histadd('search') @@ -6508,8 +6508,8 @@ libcall({libname}, {funcname}, {argument}) Examples: > :echo libcall("libc.so", "getenv", "HOME") -< Can also be used as a |method|, where the base is passed as - the argument to the called function: > +< Can also be used as a |method|, the base is passed as the + third argument: > GetValue()->libcall("libc.so", "getenv") < *libcallnr()* @@ -6521,8 +6521,8 @@ libcallnr({libname}, {funcname}, {argument}) :call libcallnr("libc.so", "printf", "Hello World!\n") :call libcallnr("libc.so", "sleep", 10) < - Can also be used as a |method|, where the base is passed as - the argument to the called function: > + Can also be used as a |method|, the base is passed as the + third argument: > GetValue()->libcallnr("libc.so", "printf") < line({expr} [, {winid}]) *line()* @@ -7046,7 +7046,7 @@ matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()* Can also be used as a |method|: > GetText()->matchstrpos('word') - +< *max()* max({expr}) Return the maximum value of all items in {expr}. {expr} can be a |List| or a |Dictionary|. For a Dictionary, @@ -8594,7 +8594,8 @@ setbufline({buf}, {lnum}, {text}) *setbufline()* If {buf} is not a valid buffer or {lnum} is not valid, an error message is given. - Can also be used as a |method|: > + Can also be used as a |method|, the base is passed as the + third argument: > GetText()->setbufline(buf, lnum) setbufvar({buf}, {varname}, {val}) *setbufvar()* @@ -8611,7 +8612,8 @@ setbufvar({buf}, {varname}, {val}) *setbufvar()* :call setbufvar("todo", "myvar", "foobar") < This function is not available in the |sandbox|. - Can also be used as a |method|: > + Can also be used as a |method|, the base is passed as the + third argument: > GetValue()->setbufvar(buf, varname) setcharsearch({dict}) *setcharsearch()* @@ -8662,7 +8664,8 @@ setenv({name}, {val}) *setenv()* < When {val} is |v:null| the environment variable is deleted. See also |expr-env|. - Can also be used as a |method|, passing the value as the base: > + Can also be used as a |method|, the base is passed as the + second argument: > GetPath()->setenv('PATH') setfperm({fname}, {mode}) *setfperm()* *chmod* @@ -8710,7 +8713,8 @@ setline({lnum}, {text}) *setline()* < Note: The '[ and '] marks are not set. - Can also be used as a |method|, passing the text as the base: > + Can also be used as a |method|, the base is passed as the + second argument: > GetText()->setline(lnum) setloclist({nr}, {list} [, {action} [, {what}]]) *setloclist()* @@ -8977,7 +8981,8 @@ settabvar({tabnr}, {varname}, {val}) *settabvar()* Tabs are numbered starting with one. This function is not available in the |sandbox|. - Can also be used as a |method|, the base is used as the value: > + Can also be used as a |method|, the base is passed as the + third argument: > GetValue()->settabvar(tab, name) settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* @@ -8996,7 +9001,8 @@ settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()* :call settabwinvar(3, 2, "myvar", "foobar") < This function is not available in the |sandbox|. - Can also be used as a |method|, the base is used as the value: > + Can also be used as a |method|, the base is passed as the + fourth argument: > GetValue()->settabwinvar(tab, winnr, name) settagstack({nr}, {dict} [, {action}]) *settagstack()* @@ -9032,7 +9038,8 @@ settagstack({nr}, {dict} [, {action}]) *settagstack()* call settagstack(1003, stack) unlet stack < - Can also be used as a |method|, the base is used as the Dict: > + Can also be used as a |method|, the base is passed as the + second argument: > GetStack()->settagstack(winnr) setwinvar({nr}, {varname}, {val}) *setwinvar()* @@ -9041,7 +9048,8 @@ setwinvar({nr}, {varname}, {val}) *setwinvar()* :call setwinvar(1, "&list", 0) :call setwinvar(2, "myvar", "foobar") -< Can also be used as a |method|, the base is used as the value: > +< Can also be used as a |method|, the base is passed as the + third argument: > GetValue()->setwinvar(winnr, name) sha256({string}) *sha256()* @@ -9439,7 +9447,7 @@ str2nr({string} [, {base}]) *str2nr()* 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. Example: > - let nr = str2nr('123') + let nr = str2nr('0123') < When {base} is 16 a leading "0x" or "0X" is ignored. With a different base the result will be zero. Similarly, when @@ -10475,8 +10483,8 @@ win_execute({id}, {command} [, {silent}]) *win_execute()* Example: > call win_execute(winid, 'syntax enable') < - Can also be used as a |method|, the base is used for the - command: > + Can also be used as a |method|, the base is passed as the + second argument: > GetCommand()->win_execute(winid) win_findbuf({bufnr}) *win_findbuf()* @@ -10818,11 +10826,11 @@ 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|: > +< + Can also be used as a |method|: > :let bits = bits->xor(0x80) < - *string-match* Matching a pattern in a String From 752ca2cb9f61b4dc523552d4123729b9b26a3409 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 22:15:53 +0000 Subject: [PATCH 15/16] fix(eval/method): add missing method support for existing built-ins These functions were ported with the vim-patch token, but didn't actually port the method call support that was in their patches (method call syntax wasn't ported yet). Add the missing method call support and latest docs for: - assert_nobeep: https://github.com/vim/vim/commit/5b8cabfef7c3707f3e53e13844d90e5a217e1e84 - buffer_name, buffer_number: (obsolete) https://github.com/vim/vim/commit/a8eee21e75324d199acb1663cb5009e03014a13a - charidx: https://github.com/vim/vim/commit/17793ef23aae0bc94539390ccfe5e63b0ad39ff2 - flatten: https://github.com/vim/vim/commit/077a1e670ad69ef4cefc22103ca6635bd269e764 - prompt_getprompt: https://github.com/vim/vim/commit/077cc7aa0e0c431e97795612374fe17fe7c88803 - searchcount: https://github.com/vim/vim/commit/e8f5ec0d30b629d7166f0ad03434065d8bc822df - strptime: https://github.com/vim/vim/commit/10455d43fef041309ce0613fa792c635dd71e3a8 - win_gettype: https://github.com/vim/vim/commit/00f3b4e007af07870168bf044cecc9d544483953 - win_splitmove: https://github.com/vim/vim/commit/d20dcb3d011da6111153109f6e46fbd5c7fe9fb6 Also fix assert_beeps, assert_nobeep and getenv to accept exactly one argument. Previously, they could erroneously accept one or more. --- runtime/doc/eval.txt | 25 ++++++++++++++++++++++--- runtime/doc/testing.txt | 3 +++ src/nvim/eval.lua | 24 ++++++++++++------------ src/nvim/testdir/test_prompt_buffer.vim | 4 +--- 4 files changed, 38 insertions(+), 18 deletions(-) diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt index 4b49cb6b6e..d1af4c4d72 100644 --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -3262,7 +3262,7 @@ char2nr({string} [, {utf8}]) *char2nr()* 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}. @@ -3285,6 +3285,9 @@ charidx({string}, {idx} [, {countcc}]) echo charidx('áb́ć', 3) returns 1 echo charidx('áb́ć', 6, 1) returns 4 echo charidx('áb́ć', 16) returns -1 +< + Can also be used as a |method|: > + GetName()->charidx(idx) chdir({dir}) *chdir()* Change the current working directory to {dir}. The scope of @@ -4364,6 +4367,9 @@ flatten({list} [, {maxdepth}]) *flatten()* :echo flatten([1, [2, [3, 4]], 5], 1) < [1, 2, [3, 4], 5] + Can also be used as a |method|: > + mylist->flatten() +< float2nr({expr}) *float2nr()* Convert {expr} to a Number by omitting the part after the decimal point. @@ -7596,6 +7602,9 @@ prompt_getprompt({buf}) *prompt_getprompt()* If the buffer doesn't exist or isn't a prompt buffer, an empty string is returned. + Can also be used as a |method|: > + GetBuffer()->prompt_getprompt() + prompt_setcallback({buf}, {expr}) *prompt_setcallback()* Set prompt callback for buffer {buf} to {expr}. When {expr} is an empty string the callback is removed. This has only @@ -8376,7 +8385,9 @@ searchcount([{options}]) *searchcount()* value. see |cursor()|, |getpos() (default: cursor's position) - + Can also be used as a |method|: > + GetSearchOpts()->searchcount() +< searchdecl({name} [, {global} [, {thisblock}]]) *searchdecl()* Search for the declaration of {name}. @@ -9653,7 +9664,9 @@ strptime({format}, {timestring}) *strptime()* :echo strftime("%c", strptime("%Y%m%d%H%M%S", "19970427115355") + 3600) < Sun Apr 27 12:53:55 1997 - + Can also be used as a |method|: > + GetFormat()->strptime(timestring) +< strridx({haystack}, {needle} [, {start}]) *strridx()* The result is a Number, which gives the byte index in {haystack} of the last occurrence of the String {needle}. @@ -10526,6 +10539,9 @@ win_gettype([{nr}]) *win_gettype()* popup window then 'buftype' is "terminal" and win_gettype() returns "popup". + Can also be used as a |method|: > + GetWinid()->win_gettype() +< win_gotoid({expr}) *win_gotoid()* Go to window with ID {expr}. This may also change the current tabpage. @@ -10581,6 +10597,9 @@ win_splitmove({nr}, {target} [, {options}]) *win_splitmove()* present, the values of 'splitbelow' and 'splitright' are used. + Can also be used as a |method|: > + GetWinid()->win_splitmove(target) +< *winbufnr()* winbufnr({nr}) The result is a Number, which is the number of the buffer associated with window {nr}. {nr} can be the window number or diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt index f0bda5aaf8..8ec66d26a4 100644 --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -157,6 +157,9 @@ assert_nobeep({cmd}) *assert_nobeep()* produces a beep or visual bell. Also see |assert_beeps()|. + Can also be used as a |method|: > + GetCmd()->assert_nobeep() +< *assert_notequal()* assert_notequal({expected}, {actual} [, {msg}]) The opposite of `assert_equal()`: add an error message to diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 75e28df98f..9a76b67de6 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -33,7 +33,7 @@ return { arglistid={args={0, 2}}, argv={args={0, 2}}, asin={args=1, base=1, func="float_op_wrapper", data="&asin"}, -- WJMc - assert_beeps={args={1}, base=1}, + assert_beeps={args=1, base=1}, assert_equal={args={2, 3}, base=2}, assert_equalfile={args={2, 3}, base=1}, assert_exception={args={1, 2}}, @@ -41,7 +41,7 @@ return { assert_false={args={1, 2}, base=1}, assert_inrange={args={3, 4}, base=3}, assert_match={args={2, 3}, base=2}, - assert_nobeep={args={1}}, + assert_nobeep={args=1, base=1}, assert_notequal={args={2, 3}, base=2}, assert_notmatch={args={2, 3}, base=2}, assert_report={args=1, base=1}, @@ -53,8 +53,8 @@ return { bufadd={args=1, base=1}, bufexists={args=1, base=1}, buffer_exists={args=1, base=1, func='f_bufexists'}, -- obsolete - buffer_name={args={0, 1}, func='f_bufname'}, -- obsolete - buffer_number={args={0, 1}, func='f_bufnr'}, -- obsolete + buffer_name={args={0, 1}, base=1, func='f_bufname'}, -- obsolete + buffer_number={args={0, 1}, base=1, func='f_bufnr'}, -- obsolete buflisted={args=1, base=1}, bufload={args=1, base=1}, bufloaded={args=1, base=1}, @@ -71,7 +71,7 @@ return { chanclose={args={1, 2}}, chansend={args=2}, char2nr={args={1, 2}, base=1}, - charidx={args={2, 3}}, + charidx={args={2, 3}, base=1}, chdir={args=1, base=1}, cindent={args=1, base=1}, clearmatches={args={0, 1}, base=1}, @@ -121,7 +121,7 @@ return { filter={args=2, base=1}, finddir={args={1, 3}, base=1}, findfile={args={1, 3}, base=1}, - flatten={args={1, 2}}, + flatten={args={1, 2}, base=1}, float2nr={args=1, base=1}, floor={args=1, base=1, func="float_op_wrapper", data="&floor"}, fmod={args=2, base=1}, @@ -152,7 +152,7 @@ return { getcompletion={args={2, 3}, base=1}, getcurpos={}, getcwd={args={0, 2}, base=1}, - getenv={args={1}, base=1}, + getenv={args=1, base=1}, getfontname={args={0, 1}}, getfperm={args=1, base=1}, getfsize={args=1, base=1}, @@ -262,7 +262,7 @@ return { pow={args=2, base=1}, prevnonblank={args=1, base=1}, printf={args=varargs(1), base=2}, - prompt_getprompt={args=1}, + prompt_getprompt={args=1, base=1}, prompt_setcallback={args={2, 2}, base=1}, prompt_setinterrupt={args={2, 2}, base=1}, prompt_setprompt={args={2, 2}, base=1}, @@ -299,7 +299,7 @@ return { screenrow={}, screenstring={args=2, base=1}, search={args={1, 4}, base=1}, - searchcount={args={0,1}}, + searchcount={args={0, 1}, base=1}, searchdecl={args={1, 3}, base=1}, searchpair={args={3, 7}}, searchpairpos={args={3, 7}}, @@ -359,7 +359,7 @@ return { string={args=1, base=1}, strlen={args=1, base=1}, strpart={args={2, 4}, base=1}, - strptime={args=2}, + strptime={args=2, base=1}, strridx={args={2, 3}, base=1}, strtrans={args=1, base=1}, strwidth={args=1, base=1}, @@ -407,12 +407,12 @@ return { win_execute={args={2, 3}, base=2}, win_findbuf={args=1, base=1}, win_getid={args={0, 2}, base=1}, - win_gettype={args={0,1}}, + win_gettype={args={0, 1}, base=1}, win_gotoid={args=1, base=1}, win_id2tabwin={args=1, base=1}, win_id2win={args=1, base=1}, win_screenpos={args=1, base=1}, - win_splitmove={args={2, 3}}, + win_splitmove={args={2, 3}, base=1}, winbufnr={args=1, base=1}, wincol={}, windowsversion={}, diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim index 3da46eb1a6..c59a00afcc 100644 --- a/src/nvim/testdir/test_prompt_buffer.vim +++ b/src/nvim/testdir/test_prompt_buffer.vim @@ -165,9 +165,7 @@ func Test_prompt_buffer_getbufinfo() call assert_equal('This is a test: ', prompt_getprompt('%')) call prompt_setprompt( bufnr( '%' ), '' ) - " Nvim doesn't support method call syntax yet. - " call assert_equal('', '%'->prompt_getprompt()) - call assert_equal('', prompt_getprompt('%')) + call assert_equal('', '%'->prompt_getprompt()) call prompt_setprompt( bufnr( '%' ), 'Another: ' ) call assert_equal('Another: ', prompt_getprompt('%')) From 6e3e8c51c0919df4d407b323d0e9237c278e2c23 Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Mon, 1 Nov 2021 23:24:49 +0000 Subject: [PATCH 16/16] test(oldtest): uncomment method call syntax uses We should now be equal with Vim in regards to method call support of already ported built-ins. Enable all relevant commented-out uses of the syntax in tests that I could grep. --- src/nvim/testdir/test_autocmd.vim | 3 +-- src/nvim/testdir/test_compiler.vim | 10 ++++------ src/nvim/testdir/test_fold.vim | 3 +-- src/nvim/testdir/test_mksession.vim | 3 +-- src/nvim/testdir/test_options.vim | 3 +-- src/nvim/testdir/test_spell_utf8.vim | 6 ++---- src/nvim/testdir/test_startup.vim | 6 ++---- src/nvim/testdir/test_substitute.vim | 3 +-- src/nvim/testdir/test_syntax.vim | 20 +++++++------------- src/nvim/testdir/test_system.vim | 3 +-- 10 files changed, 21 insertions(+), 39 deletions(-) diff --git a/src/nvim/testdir/test_autocmd.vim b/src/nvim/testdir/test_autocmd.vim index 0c8b8a45d9..27b3eedfa1 100644 --- a/src/nvim/testdir/test_autocmd.vim +++ b/src/nvim/testdir/test_autocmd.vim @@ -526,8 +526,7 @@ func Test_autocmd_blast_badd() call writefile(content, 'XblastBall') call system(GetVimCommand() .. ' --clean -S XblastBall') - " call assert_match('OK', readfile('Xerrors')->join()) - call assert_match('OK', join(readfile('Xerrors'))) + call assert_match('OK', readfile('Xerrors')->join()) call delete('XblastBall') call delete('Xerrors') diff --git a/src/nvim/testdir/test_compiler.vim b/src/nvim/testdir/test_compiler.vim index c3de7d0050..aaa2301bca 100644 --- a/src/nvim/testdir/test_compiler.vim +++ b/src/nvim/testdir/test_compiler.vim @@ -38,10 +38,9 @@ func Test_compiler() endfunc func GetCompilerNames() - " return glob('$VIMRUNTIME/compiler/*.vim', 0, 1) - " \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')}) - " \ ->sort() - return sort(map(glob('$VIMRUNTIME/compiler/*.vim', 0, 1), {i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')})) + return glob('$VIMRUNTIME/compiler/*.vim', 0, 1) + \ ->map({i, v -> substitute(v, '.*[\\/]\([a-zA-Z0-9_\-]*\).vim', '\1', '')}) + \ ->sort() endfunc func Test_compiler_without_arg() @@ -54,8 +53,7 @@ func Test_compiler_without_arg() endfunc func Test_compiler_completion() - " let clist = GetCompilerNames()->join(' ') - let clist = join(GetCompilerNames(), ' ') + let clist = GetCompilerNames()->join(' ') call feedkeys(":compiler \\\"\", 'tx') call assert_match('^"compiler ' .. clist .. '$', @:) diff --git a/src/nvim/testdir/test_fold.vim b/src/nvim/testdir/test_fold.vim index 5586fe2151..6da1b3d4a0 100644 --- a/src/nvim/testdir/test_fold.vim +++ b/src/nvim/testdir/test_fold.vim @@ -809,8 +809,7 @@ func Test_undo_fold_deletion() g/"/d undo redo - " eval getline(1, '$')->assert_equal(['']) - eval assert_equal(getline(1, '$'), ['']) + eval getline(1, '$')->assert_equal(['']) set fdm&vim bwipe! diff --git a/src/nvim/testdir/test_mksession.vim b/src/nvim/testdir/test_mksession.vim index c96c6a9678..057895047d 100644 --- a/src/nvim/testdir/test_mksession.vim +++ b/src/nvim/testdir/test_mksession.vim @@ -156,8 +156,7 @@ func Test_mksession_zero_winheight() wincmd _ mksession! Xtest_mks_zero set winminheight& - " let text = readfile('Xtest_mks_zero')->join() - let text = join(readfile('Xtest_mks_zero')) + let text = readfile('Xtest_mks_zero')->join() call delete('Xtest_mks_zero') close " check there is no divide by zero diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index 41c689849b..7d9cada074 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -235,8 +235,7 @@ func Test_set_completion() call feedkeys(":set filetype=sshdconfi\\\"\", 'xt') call assert_equal('"set filetype=sshdconfig', @:) call feedkeys(":set filetype=a\\\"\", 'xt') - " call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:) - call assert_equal('"set filetype=' .. join(getcompletion('a*', 'filetype')), @:) + call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:) endfunc func Test_set_errors() diff --git a/src/nvim/testdir/test_spell_utf8.vim b/src/nvim/testdir/test_spell_utf8.vim index cafdb97f28..3d159f3352 100644 --- a/src/nvim/testdir/test_spell_utf8.vim +++ b/src/nvim/testdir/test_spell_utf8.vim @@ -512,8 +512,7 @@ func TestGoodBadBase() break endif let prevbad = bad - " let lst = bad->spellsuggest(3) - let lst = spellsuggest(bad, 3) + let lst = bad->spellsuggest(3) normal mm call add(result, [bad, lst]) @@ -552,8 +551,7 @@ func Test_spell_basic() \ ) call assert_equal("gebletegek", soundfold('goobledygoook')) - " call assert_equal("kepereneven", 'kóopërÿnôven'->soundfold()) - call assert_equal("kepereneven", soundfold('kóopërÿnôven')) + call assert_equal("kepereneven", 'kóopërÿnôven'->soundfold()) call assert_equal("everles gesvets etele", soundfold('oeverloos gezwets edale')) endfunc diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index b140077111..d830f5216d 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -905,15 +905,13 @@ func Test_not_a_term() " This will take 2 seconds because of the missing --not-a-term let cmd = GetVimProg() .. ' --cmd quit ' .. redir exe "silent !" . cmd - " call assert_match("\", readfile('Xvimout')->join()) - call assert_match("\", join(readfile('Xvimout'))) + call assert_match("\", readfile('Xvimout')->join()) call delete('Xvimout') " With --not-a-term there are no escape sequences. let cmd = GetVimProg() .. ' --not-a-term --cmd quit ' .. redir exe "silent !" . cmd - " call assert_notmatch("\", readfile('Xvimout')->join()) - call assert_notmatch("\", join(readfile('Xvimout'))) + call assert_notmatch("\", readfile('Xvimout')->join()) call delete('Xvimout') endfunc diff --git a/src/nvim/testdir/test_substitute.vim b/src/nvim/testdir/test_substitute.vim index f06705a84c..113c85acef 100644 --- a/src/nvim/testdir/test_substitute.vim +++ b/src/nvim/testdir/test_substitute.vim @@ -752,8 +752,7 @@ endfunc func Test_submatch_list_concatenate() let pat = 'A\(.\)' let Rep = {-> string([submatch(0, 1)] + [[submatch(1)]])} - " call substitute('A1', pat, Rep, '')->assert_equal("[['A1'], ['1']]") - call assert_equal(substitute('A1', pat, Rep, ''), "[['A1'], ['1']]") + call substitute('A1', pat, Rep, '')->assert_equal("[['A1'], ['1']]") endfunc func Test_substitute_skipped_range() diff --git a/src/nvim/testdir/test_syntax.vim b/src/nvim/testdir/test_syntax.vim index 914d9c2782..757866f5dc 100644 --- a/src/nvim/testdir/test_syntax.vim +++ b/src/nvim/testdir/test_syntax.vim @@ -30,23 +30,17 @@ func AssertHighlightGroups(lnum, startcol, expected, trans = 1, msg = "") " If groups are provided as a string, each character is assumed to be a " group and spaces represent no group, useful for visually describing tests. let l:expectedGroups = type(a:expected) == v:t_string - "\ ? a:expected->split('\zs')->map({_, v -> trim(v)}) - \ ? map(split(a:expected, '\zs'), {_, v -> trim(v)}) + \ ? a:expected->split('\zs')->map({_, v -> trim(v)}) \ : a:expected let l:errors = 0 - " let l:msg = (a:msg->empty() ? "" : a:msg .. ": ") - let l:msg = (empty(a:msg) ? "" : a:msg .. ": ") + let l:msg = (a:msg->empty() ? "" : a:msg .. ": ") \ .. "Wrong highlight group at " .. a:lnum .. "," - " for l:i in range(a:startcol, a:startcol + l:expectedGroups->len() - 1) - " let l:errors += synID(a:lnum, l:i, a:trans) - " \ ->synIDattr("name") - " \ ->assert_equal(l:expectedGroups[l:i - 1], - for l:i in range(a:startcol, a:startcol + len(l:expectedGroups) - 1) - let l:errors += - \ assert_equal(synIDattr(synID(a:lnum, l:i, a:trans), "name"), - \ l:expectedGroups[l:i - 1], - \ l:msg .. l:i) + for l:i in range(a:startcol, a:startcol + l:expectedGroups->len() - 1) + let l:errors += synID(a:lnum, l:i, a:trans) + \ ->synIDattr("name") + \ ->assert_equal(l:expectedGroups[l:i - 1], + \ l:msg .. l:i) endfor endfunc diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index 7b8ee778cc..1858b48807 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -121,8 +121,7 @@ func Test_system_with_shell_quote() let msg = printf('shell=%s shellxquote=%s', &shell, &shellxquote) try - " let out = 'echo 123'->system() - let out = system('echo 123') + let out = 'echo 123'->system() catch call assert_report(printf('%s: %s', msg, v:exception)) continue