mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
feat(eval/method): partially port v8.1.1987
Cannot be fully ported as the remote_*() functions from +clientserver are not yet ported. Include the test changes anyway. line()'s optional winid argument was already ported. (Wasn't added in this patch; this just adds documentation)
This commit is contained in:
parent
c5583df3c0
commit
a8504638cd
@ -2505,7 +2505,7 @@ keys({dict}) List keys in {dict}
|
||||
len({expr}) Number the length of {expr}
|
||||
libcall({lib}, {func}, {arg}) String call {func} in library {lib} with {arg}
|
||||
libcallnr({lib}, {func}, {arg}) Number idem, but return a Number
|
||||
line({expr}) Number line nr of cursor, last line or mark
|
||||
line({expr} [, {winid}]) Number line nr of cursor, last line or mark
|
||||
line2byte({lnum}) Number byte count of line {lnum}
|
||||
lispindent({lnum}) Number Lisp indent for line {lnum}
|
||||
list2str({list} [, {utf8}]) String turn numbers in {list} into a String
|
||||
@ -5780,7 +5780,9 @@ hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
|
||||
If no matching mapping is found FALSE is returned.
|
||||
The following characters are recognized in {mode}:
|
||||
n Normal mode
|
||||
v Visual mode
|
||||
v Visual and Select mode
|
||||
x Visual mode
|
||||
s Select mode
|
||||
o Operator-pending mode
|
||||
i Insert mode
|
||||
l Language-Argument ("r", "f", "t", etc.)
|
||||
@ -6483,8 +6485,8 @@ libcallnr({libname}, {funcname}, {argument})
|
||||
the argument to the called function: >
|
||||
GetValue()->libcallnr("libc.so", "printf")
|
||||
<
|
||||
*line()*
|
||||
line({expr}) The result is a Number, which is the line number of the file
|
||||
line({expr} [, {winid}]) *line()*
|
||||
The result is a Number, which is the line number of the file
|
||||
position given with {expr}. The {expr} argument is a string.
|
||||
The accepted positions are:
|
||||
. the cursor position
|
||||
@ -6503,8 +6505,11 @@ line({expr}) The result is a Number, which is the line number of the file
|
||||
then applies to another buffer.
|
||||
To get the column number use |col()|. To get both use
|
||||
|getpos()|.
|
||||
With the optional {winid} argument the values are obtained for
|
||||
that window instead of the current window.
|
||||
Examples: >
|
||||
line(".") line number of the cursor
|
||||
line(".", winid) idem, in window "winid"
|
||||
line("'t") line number of mark t
|
||||
line("'" . marker) line number of mark marker
|
||||
<
|
||||
@ -7669,6 +7674,9 @@ range({expr} [, {max} [, {stride}]]) *range()*
|
||||
range(2, -2, -1) " [2, 1, 0, -1, -2]
|
||||
range(0) " []
|
||||
range(2, 0) " error!
|
||||
<
|
||||
Can also be used as a |method|: >
|
||||
GetExpr()->range()
|
||||
<
|
||||
*readdir()*
|
||||
readdir({directory} [, {expr}])
|
||||
@ -7696,6 +7704,9 @@ readdir({directory} [, {expr}])
|
||||
\ {x : s:tree(a:dir . '/' . x)} : x})}
|
||||
endfunction
|
||||
echo s:tree(".")
|
||||
<
|
||||
Can also be used as a |method|: >
|
||||
GetDirName()->readdir()
|
||||
<
|
||||
*readfile()*
|
||||
readfile({fname} [, {type} [, {max}]])
|
||||
@ -7730,6 +7741,9 @@ readfile({fname} [, {type} [, {max}]])
|
||||
the result is an empty list.
|
||||
Also see |writefile()|.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetFileName()->readfile()
|
||||
|
||||
reg_executing() *reg_executing()*
|
||||
Returns the single letter name of the register being executed.
|
||||
Returns an empty string when no register is being executed.
|
||||
@ -7757,6 +7771,9 @@ reltime([{start} [, {end}]]) *reltime()*
|
||||
The {start} and {end} arguments must be values returned by
|
||||
reltime().
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetStart()->reltime()
|
||||
<
|
||||
Note: |localtime()| returns the current (non-relative) time.
|
||||
|
||||
reltimefloat({time}) *reltimefloat()*
|
||||
@ -7770,6 +7787,9 @@ reltimefloat({time}) *reltimefloat()*
|
||||
Also see |profiling|.
|
||||
If there is an error an empty string is returned
|
||||
|
||||
Can also be used as a |method|: >
|
||||
reltime(start)->reltimefloat()
|
||||
|
||||
reltimestr({time}) *reltimestr()*
|
||||
Return a String that represents the time value of {time}.
|
||||
This is the number of seconds, a dot and the number of
|
||||
@ -7784,6 +7804,9 @@ reltimestr({time}) *reltimestr()*
|
||||
< Also see |profiling|.
|
||||
If there is an error an empty string is returned
|
||||
|
||||
Can also be used as a |method|: >
|
||||
reltime(start)->reltimestr()
|
||||
<
|
||||
*remote_expr()* *E449*
|
||||
remote_expr({server}, {string} [, {idvar} [, {timeout}]])
|
||||
Send the {string} to {server}. The string is sent as an
|
||||
@ -7916,6 +7939,9 @@ rename({from}, {to}) *rename()*
|
||||
NOTE: If {to} exists it is overwritten without warning.
|
||||
This function is not available in the |sandbox|.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetOldName()->rename(newname)
|
||||
|
||||
repeat({expr}, {count}) *repeat()*
|
||||
Repeat {expr} {count} times and return the concatenated
|
||||
result. Example: >
|
||||
@ -7942,6 +7968,9 @@ resolve({filename}) *resolve()* *E655*
|
||||
current directory (provided the result is still a relative
|
||||
path name) and also keeps a trailing path separator.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetName()->resolve()
|
||||
<
|
||||
*reverse()*
|
||||
reverse({object})
|
||||
Reverse the order of items in {object} in-place.
|
||||
@ -7996,6 +8025,9 @@ rubyeval({expr}) *rubyeval()*
|
||||
Other objects are represented as strings resulted from their
|
||||
"Object#to_s" method.
|
||||
|
||||
Can also be used as a |method|: >
|
||||
GetRubyExpr()->rubyeval()
|
||||
|
||||
screenattr({row}, {col}) *screenattr()*
|
||||
Like |screenchar()|, but return the attribute. This is a rather
|
||||
arbitrary number that can only be used to compare to the
|
||||
|
@ -271,25 +271,25 @@ return {
|
||||
pyeval={args=1, base=1},
|
||||
pyxeval={args=1, base=1},
|
||||
perleval={args=1, base=1},
|
||||
range={args={1, 3}},
|
||||
readdir={args={1, 2}},
|
||||
readfile={args={1, 3}},
|
||||
range={args={1, 3}, base=1},
|
||||
readdir={args={1, 2}, base=1},
|
||||
readfile={args={1, 3}, base=1},
|
||||
reg_executing={},
|
||||
reg_recording={},
|
||||
reltime={args={0, 2}},
|
||||
reltimefloat={args=1},
|
||||
reltimestr={args=1},
|
||||
reltime={args={0, 2}, base=1},
|
||||
reltimefloat={args=1, base=1},
|
||||
reltimestr={args=1, base=1},
|
||||
remove={args={2, 3}, base=1},
|
||||
rename={args=2},
|
||||
rename={args=2, base=1},
|
||||
['repeat']={args=2, base=1},
|
||||
resolve={args=1},
|
||||
resolve={args=1, base=1},
|
||||
reverse={args=1, base=1},
|
||||
round={args=1, base=1, func="float_op_wrapper", data="&round"},
|
||||
rpcnotify={args=varargs(2)},
|
||||
rpcrequest={args=varargs(2)},
|
||||
rpcstart={args={1, 2}},
|
||||
rpcstop={args=1},
|
||||
rubyeval={args=1},
|
||||
rubyeval={args=1, base=1},
|
||||
screenattr={args=2},
|
||||
screenchar={args=2},
|
||||
screenchars={args=2},
|
||||
|
@ -34,7 +34,7 @@ func Test_client_server()
|
||||
" When using valgrind it takes much longer.
|
||||
call WaitForAssert({-> assert_match(name, serverlist())})
|
||||
|
||||
call remote_foreground(name)
|
||||
eval name->remote_foreground()
|
||||
|
||||
call remote_send(name, ":let testvar = 'yes'\<CR>")
|
||||
call WaitFor('remote_expr("' . name . '", "exists(\"testvar\") ? testvar : \"\"", "", 1) == "yes"')
|
||||
@ -53,7 +53,7 @@ func Test_client_server()
|
||||
endif
|
||||
" Wait for the server to be up and answering requests.
|
||||
sleep 100m
|
||||
call WaitForAssert({-> assert_true(remote_expr(name, "v:version", "", 1) != "")})
|
||||
call WaitForAssert({-> assert_true(name->remote_expr("v:version", "", 1) != "")})
|
||||
|
||||
call remote_send(name, ":let testvar = 'maybe'\<CR>")
|
||||
call WaitForAssert({-> assert_equal('maybe', remote_expr(name, "testvar", "", 2))})
|
||||
@ -72,7 +72,7 @@ func Test_client_server()
|
||||
|
||||
" Expression evaluated locally.
|
||||
if v:servername == ''
|
||||
call remote_startserver('MYSELF')
|
||||
eval 'MYSELF'->remote_startserver()
|
||||
" May get MYSELF1 when running the test again.
|
||||
call assert_match('MYSELF', v:servername)
|
||||
endif
|
||||
@ -80,11 +80,11 @@ func Test_client_server()
|
||||
call assert_equal('myself', remote_expr(v:servername, 'testvar'))
|
||||
|
||||
call remote_send(name, ":call server2client(expand('<client>'), 'got it')\<CR>", 'g:myserverid')
|
||||
call assert_equal('got it', remote_read(g:myserverid, 2))
|
||||
call assert_equal('got it', g:myserverid->remote_read(2))
|
||||
|
||||
call remote_send(name, ":call server2client(expand('<client>'), 'another')\<CR>", 'g:myserverid')
|
||||
let peek_result = 'nothing'
|
||||
let r = remote_peek(g:myserverid, 'peek_result')
|
||||
let r = g:myserverid->remote_peek('peek_result')
|
||||
" unpredictable whether the result is already available.
|
||||
if r > 0
|
||||
call assert_equal('another', peek_result)
|
||||
@ -98,7 +98,7 @@ func Test_client_server()
|
||||
call assert_equal('another', g:peek_result)
|
||||
call assert_equal('another', remote_read(g:myserverid, 2))
|
||||
|
||||
call remote_send(name, ":qa!\<CR>")
|
||||
eval name->remote_send(":qa!\<CR>")
|
||||
try
|
||||
call WaitForAssert({-> assert_equal("dead", job_status(job))})
|
||||
finally
|
||||
|
@ -295,7 +295,7 @@ func Test_resolve_unix()
|
||||
call delete('Xlink')
|
||||
|
||||
silent !ln -s -f Xlink2/ Xlink1
|
||||
call assert_equal('Xlink2', resolve('Xlink1'))
|
||||
call assert_equal('Xlink2', 'Xlink1'->resolve())
|
||||
call assert_equal('Xlink2/', resolve('Xlink1/'))
|
||||
call delete('Xlink1')
|
||||
|
||||
@ -1306,7 +1306,7 @@ func Test_func_range_with_edit()
|
||||
" is invalid in that buffer.
|
||||
call writefile(['just one line'], 'Xfuncrange2')
|
||||
new
|
||||
call setline(1, range(10))
|
||||
call setline(1, 10->range())
|
||||
write Xfuncrange1
|
||||
call assert_fails('5,8call EditAnotherFile()', 'E16:')
|
||||
|
||||
@ -1578,7 +1578,7 @@ func Test_readdir()
|
||||
call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files))
|
||||
|
||||
" Only results containing "f"
|
||||
let files = readdir('Xdir', { x -> stridx(x, 'f') !=- 1 })
|
||||
let files = 'Xdir'->readdir({ x -> stridx(x, 'f') !=- 1 })
|
||||
call assert_equal(['foo.txt'], sort(files))
|
||||
|
||||
" Only .txt files
|
||||
|
@ -8,11 +8,11 @@ func Test_reltime()
|
||||
let now = reltime()
|
||||
sleep 10m
|
||||
let later = reltime()
|
||||
let elapsed = reltime(now)
|
||||
let elapsed = now->reltime()
|
||||
call assert_true(reltimestr(elapsed) =~ '0\.0')
|
||||
call assert_true(reltimestr(elapsed) != '0.0')
|
||||
call assert_true(elapsed->reltimestr() != '0.0')
|
||||
call assert_true(reltimefloat(elapsed) < 0.1)
|
||||
call assert_true(reltimefloat(elapsed) > 0.0)
|
||||
call assert_true(elapsed->reltimefloat() > 0.0)
|
||||
|
||||
let same = reltime(now, now)
|
||||
call assert_equal('0.000', split(reltimestr(same))[0][:4])
|
||||
|
@ -25,7 +25,7 @@ func Test_rename_file_ignore_case()
|
||||
set fileignorecase
|
||||
call writefile(['foo'], 'Xrename')
|
||||
|
||||
call assert_equal(0, rename('Xrename', 'XRENAME'))
|
||||
call assert_equal(0, 'Xrename'->rename('XRENAME'))
|
||||
|
||||
call assert_equal(['foo'], readfile('XRENAME'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user