feat(eval): partially port v8.1.1915

Cannot be fully ported as chdir() hasn't been ported yet.
This commit is contained in:
Sean Dewar
2021-08-07 22:39:23 +01:00
parent 56b56a76e8
commit 5d88349817
9 changed files with 72 additions and 25 deletions

View File

@@ -3074,6 +3074,9 @@ char2nr({expr} [, {utf8}]) *char2nr()*
A combining character is a separate character. A combining character is a separate character.
|nr2char()| does the opposite. |nr2char()| does the opposite.
Can also be used as a |method|: >
GetChar()->char2nr()
*charidx()* *charidx()*
charidx({string}, {idx} [, {countcc}]) charidx({string}, {idx} [, {countcc}])
Return the character index of the byte at {idx} in {string}. Return the character index of the byte at {idx} in {string}.
@@ -3105,12 +3108,18 @@ cindent({lnum}) *cindent()*
When {lnum} is invalid -1 is returned. When {lnum} is invalid -1 is returned.
See |C-indenting|. See |C-indenting|.
Can also be used as a |method|: >
GetLnum()->cindent()
clearmatches([{win}]) *clearmatches()* clearmatches([{win}]) *clearmatches()*
Clears all matches previously defined for the current window Clears all matches previously defined for the current window
by |matchadd()| and the |:match| commands. by |matchadd()| and the |:match| commands.
If {win} is specified, use the window with this number or If {win} is specified, use the window with this number or
window ID instead of the current window. window ID instead of the current window.
Can also be used as a |method|: >
GetWin()->clearmatches()
<
*col()* *col()*
col({expr}) The result is a Number, which is the byte index of the column col({expr}) The result is a Number, which is the byte index of the column
position given with {expr}. The accepted positions are: position given with {expr}. The accepted positions are:
@@ -3146,6 +3155,9 @@ col({expr}) The result is a Number, which is the byte index of the column
\<C-O>:set ve=all<CR> \<C-O>:set ve=all<CR>
\<C-O>:echo col(".") . "\n" <Bar> \<C-O>:echo col(".") . "\n" <Bar>
\let &ve = save_ve<CR> \let &ve = save_ve<CR>
< Can also be used as a |method|: >
GetPos()->col()
< <
complete({startcol}, {matches}) *complete()* *E785* complete({startcol}, {matches}) *complete()* *E785*
@@ -3177,6 +3189,10 @@ complete({startcol}, {matches}) *complete()* *E785*
< This isn't very useful, but it shows how it works. Note that < This isn't very useful, but it shows how it works. Note that
an empty string is returned to avoid a zero being inserted. an empty string is returned to avoid a zero being inserted.
Can also be used as a |method|, the second argument is passed
in: >
GetMatches()->complete(col('.'))
complete_add({expr}) *complete_add()* complete_add({expr}) *complete_add()*
Add {expr} to the list of matches. Only to be used by the Add {expr} to the list of matches. Only to be used by the
function specified with the 'completefunc' option. function specified with the 'completefunc' option.
@@ -3186,6 +3202,9 @@ complete_add({expr}) *complete_add()*
See |complete-functions| for an explanation of {expr}. It is See |complete-functions| for an explanation of {expr}. It is
the same as one item in the list that 'omnifunc' would return. the same as one item in the list that 'omnifunc' would return.
Can also be used as a |method|: >
GetMoreMatches()->complete_add()
complete_check() *complete_check()* complete_check() *complete_check()*
Check for a key typed while looking for completion matches. Check for a key typed while looking for completion matches.
This is to be used when looking for matches takes some time. This is to be used when looking for matches takes some time.
@@ -3246,6 +3265,9 @@ complete_info([{what}])
call complete_info(['mode']) call complete_info(['mode'])
" Get only 'mode' and 'pum_visible' " Get only 'mode' and 'pum_visible'
call complete_info(['mode', 'pum_visible']) call complete_info(['mode', 'pum_visible'])
< Can also be used as a |method|: >
GetItems()->complete_info()
< <
*confirm()* *confirm()*
confirm({msg} [, {choices} [, {default} [, {type}]]]) confirm({msg} [, {choices} [, {default} [, {type}]]])
@@ -3299,6 +3321,9 @@ confirm({msg} [, {choices} [, {default} [, {type}]]])
don't fit, a vertical layout is used anyway. For some systems don't fit, a vertical layout is used anyway. For some systems
the horizontal layout is always used. the horizontal layout is always used.
Can also be used as a |method|in: >
BuildMessage()->confirm("&Yes\n&No")
*copy()* *copy()*
copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
different from using {expr} directly. different from using {expr} directly.
@@ -3447,6 +3472,8 @@ cursor({list})
position within a <Tab> or after the last character. position within a <Tab> or after the last character.
Returns 0 when the position could be set, -1 otherwise. Returns 0 when the position could be set, -1 otherwise.
Can also be used as a |method|: >
GetCursorPos()->cursor()
deepcopy({expr}[, {noref}]) *deepcopy()* *E698* deepcopy({expr}[, {noref}]) *deepcopy()* *E698*
Make a copy of {expr}. For Numbers and Strings this isn't Make a copy of {expr}. For Numbers and Strings this isn't
@@ -3468,6 +3495,9 @@ deepcopy({expr}[, {noref}]) *deepcopy()* *E698*
{noref} set to 1 will fail. {noref} set to 1 will fail.
Also see |copy()|. Also see |copy()|.
Can also be used as a |method|: >
GetObject()->deepcopy()
delete({fname} [, {flags}]) *delete()* delete({fname} [, {flags}]) *delete()*
Without {flags} or with {flags} empty: Deletes the file by the Without {flags} or with {flags} empty: Deletes the file by the
name {fname}. This also works when {fname} is a symbolic link. name {fname}. This also works when {fname} is a symbolic link.
@@ -3485,6 +3515,9 @@ delete({fname} [, {flags}]) *delete()*
operation was successful and -1/true when the deletion failed operation was successful and -1/true when the deletion failed
or partly failed. or partly failed.
Can also be used as a |method|: >
GetName()->delete()
deletebufline({expr}, {first}[, {last}]) *deletebufline()* deletebufline({expr}, {first}[, {last}]) *deletebufline()*
Delete lines {first} to {last} (inclusive) from buffer {expr}. Delete lines {first} to {last} (inclusive) from buffer {expr}.
If {last} is omitted then delete line {first} only. If {last} is omitted then delete line {first} only.
@@ -3499,6 +3532,9 @@ deletebufline({expr}, {first}[, {last}]) *deletebufline()*
when using |line()| this refers to the current buffer. Use "$" when using |line()| this refers to the current buffer. Use "$"
to refer to the last line in buffer {expr}. to refer to the last line in buffer {expr}.
Can also be used as a |method|: >
GetBuffer()->deletebufline(1)
dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()* dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()*
Adds a watcher to a dictionary. A dictionary watcher is Adds a watcher to a dictionary. A dictionary watcher is
identified by three components: identified by three components:
@@ -3565,6 +3601,9 @@ diff_filler({lnum}) *diff_filler()*
line, "'m" mark m, etc. line, "'m" mark m, etc.
Returns 0 if the current window is not in diff mode. Returns 0 if the current window is not in diff mode.
Can also be used as a |method|: >
GetLnum()->diff_filler()
diff_hlID({lnum}, {col}) *diff_hlID()* diff_hlID({lnum}, {col}) *diff_hlID()*
Returns the highlight ID for diff mode at line {lnum} column Returns the highlight ID for diff mode at line {lnum} column
{col} (byte index). When the current line does not have a {col} (byte index). When the current line does not have a
@@ -3576,6 +3615,9 @@ diff_hlID({lnum}, {col}) *diff_hlID()*
The highlight ID can be used with |synIDattr()| to obtain The highlight ID can be used with |synIDattr()| to obtain
syntax information about the highlighting. syntax information about the highlighting.
Can also be used as a |method|: >
GetLnum()->diff_hlID(col)
empty({expr}) *empty()* empty({expr}) *empty()*
Return the Number 1 if {expr} is empty, zero otherwise. Return the Number 1 if {expr} is empty, zero otherwise.
A |List| or |Dictionary| is empty when it does not have any A |List| or |Dictionary| is empty when it does not have any
@@ -3776,6 +3818,9 @@ debugbreak({pid}) *debugbreak()*
processes is undefined. See |terminal-debugger|. processes is undefined. See |terminal-debugger|.
{Sends a SIGINT to a process {pid} other than MS-Windows} {Sends a SIGINT to a process {pid} other than MS-Windows}
Can also be used as a |method|: >
GetPid()->debugbreak()
expand({expr} [, {nosuf} [, {list}]]) *expand()* expand({expr} [, {nosuf} [, {list}]]) *expand()*
Expand wildcards and the following special keywords in {expr}. Expand wildcards and the following special keywords in {expr}.
'wildignorecase' applies. 'wildignorecase' applies.

View File

@@ -70,16 +70,16 @@ return {
changenr={}, changenr={},
chanclose={args={1, 2}}, chanclose={args={1, 2}},
chansend={args=2}, chansend={args=2},
char2nr={args={1, 2}}, char2nr={args={1, 2}, base=1},
charidx={args={2, 3}}, charidx={args={2, 3}},
cindent={args=1}, cindent={args=1, base=1},
clearmatches={args={0, 1}}, clearmatches={args={0, 1}, base=1},
col={args=1}, col={args=1, base=1},
complete={args=2}, complete={args=2, base=2},
complete_add={args=1}, complete_add={args=1, base=1},
complete_check={}, complete_check={},
complete_info={args={0, 1}}, complete_info={args={0, 1}, base=1},
confirm={args={1, 4}}, confirm={args={1, 4}, base=1},
copy={args=1, base=1}, copy={args=1, base=1},
cos={args=1, base=1, func="float_op_wrapper", data="&cos"}, cos={args=1, base=1, func="float_op_wrapper", data="&cos"},
cosh={args=1, base=1, func="float_op_wrapper", data="&cosh"}, cosh={args=1, base=1, func="float_op_wrapper", data="&cosh"},
@@ -90,16 +90,16 @@ return {
ctxpush={args={0, 1}}, ctxpush={args={0, 1}},
ctxset={args={1, 2}}, ctxset={args={1, 2}},
ctxsize={}, ctxsize={},
cursor={args={1, 3}}, cursor={args={1, 3}, base=1},
debugbreak={args={1, 1}}, debugbreak={args={1, 1}, base=1},
deepcopy={args={1, 2}}, deepcopy={args={1, 2}, base=1},
delete={args={1,2}}, delete={args={1,2}, base=1},
deletebufline={args={2,3}}, deletebufline={args={2,3}, base=1},
dictwatcheradd={args=3}, dictwatcheradd={args=3},
dictwatcherdel={args=3}, dictwatcherdel={args=3},
did_filetype={}, did_filetype={},
diff_filler={args=1}, diff_filler={args=1, base=1},
diff_hlID={args=2}, diff_hlID={args=2, base=1},
empty={args=1, base=1}, empty={args=1, base=1},
environ={}, environ={},
escape={args=2}, escape={args=2},

View File

@@ -102,7 +102,7 @@ func Test_deletebufline()
call assert_equal(0, deletebufline(b, 2, 8)) call assert_equal(0, deletebufline(b, 2, 8))
call assert_equal(['aaa'], getbufline(b, 1, 2)) call assert_equal(['aaa'], getbufline(b, 1, 2))
exe "bd!" b exe "bd!" b
call assert_equal(1, deletebufline(b, 1)) call assert_equal(1, b->deletebufline(1))
split Xtest split Xtest
call setline(1, ['a', 'b', 'c']) call setline(1, ['a', 'b', 'c'])

View File

@@ -122,9 +122,9 @@ func Test_cindent_func()
new new
setlocal cindent setlocal cindent
call setline(1, ['int main(void)', '{', 'return 0;', '}']) call setline(1, ['int main(void)', '{', 'return 0;', '}'])
call assert_equal(cindent(0), -1) call assert_equal(-1, cindent(0))
call assert_equal(cindent(3), &sw) call assert_equal(&sw, 3->cindent())
call assert_equal(cindent(line('$')+1), -1) call assert_equal(-1, cindent(line('$')+1))
bwipe! bwipe!
endfunc endfunc

View File

@@ -725,7 +725,7 @@ func Test_diff_filler()
diffthis diffthis
redraw redraw
call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)')) call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'v:val->diff_filler()'))
wincmd w wincmd w
call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)'))

View File

@@ -1093,7 +1093,7 @@ func Test_col()
call assert_equal(7, col('$')) call assert_equal(7, col('$'))
call assert_equal(4, col("'x")) call assert_equal(4, col("'x"))
call assert_equal(6, col("'Y")) call assert_equal(6, col("'Y"))
call assert_equal(2, col([1, 2])) call assert_equal(2, [1, 2]->col())
call assert_equal(7, col([1, '$'])) call assert_equal(7, col([1, '$']))
call assert_equal(0, col('')) call assert_equal(0, col(''))

View File

@@ -239,7 +239,7 @@ func Test_matchaddpos_otherwin()
\] \]
call assert_equal(expect, savematches) call assert_equal(expect, savematches)
call clearmatches(winid) eval winid->clearmatches()
call assert_equal([], getmatches(winid)) call assert_equal([], getmatches(winid))
call setmatches(savematches, winid) call setmatches(savematches, winid)

View File

@@ -8,6 +8,7 @@ func Test_list_method()
eval l->assert_notequal([3, 2, 1]) eval l->assert_notequal([3, 2, 1])
eval l->assert_notequal([3, 2, 1], 'wrong') eval l->assert_notequal([3, 2, 1], 'wrong')
call assert_equal(l, l->copy()) call assert_equal(l, l->copy())
call assert_equal(l, l->deepcopy())
call assert_equal(1, l->count(2)) call assert_equal(1, l->count(2))
call assert_false(l->empty()) call assert_false(l->empty())
call assert_true([]->empty()) call assert_true([]->empty())
@@ -38,6 +39,7 @@ func Test_dict_method()
let d = #{one: 1, two: 2, three: 3} let d = #{one: 1, two: 2, three: 3}
call assert_equal(d, d->copy()) call assert_equal(d, d->copy())
call assert_equal(d, d->deepcopy())
call assert_equal(1, d->count(2)) call assert_equal(1, d->count(2))
call assert_false(d->empty()) call assert_false(d->empty())
call assert_true({}->empty()) call assert_true({}->empty())

View File

@@ -250,7 +250,7 @@ endfunc
func Test_noinsert_complete() func Test_noinsert_complete()
func! s:complTest1() abort func! s:complTest1() abort
call complete(1, ['source', 'soundfold']) eval ['source', 'soundfold']->complete(1)
return '' return ''
endfunc endfunc
@@ -403,7 +403,7 @@ func DummyCompleteFour(findstart, base)
return 0 return 0
else else
call complete_add('four1') call complete_add('four1')
call complete_add('four2') eval 'four2'->complete_add()
call complete_check() call complete_check()
call complete_add('four3') call complete_add('four3')
call complete_add('four4') call complete_add('four4')
@@ -989,7 +989,7 @@ func GetCompleteInfo()
if empty(g:compl_what) if empty(g:compl_what)
let g:compl_info = complete_info() let g:compl_info = complete_info()
else else
let g:compl_info = complete_info(g:compl_what) let g:compl_info = g:compl_what->complete_info()
endif endif
return '' return ''
endfunc endfunc