mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
feat(eval/method): partially port v8.1.1996
Problem: More functions can be used as methods. Solution: Make various functions usable as a method.aad222c9c9
Partial port as this does not include eval.txt change for listener_add. Cherry-pick eval.txt changes for: - bufadd from v8.1.1626:5ca1ac373a
- setloclist and setqflist headers from:b0d45e7f53
Correct eval.txt typo for settabwinvar method call (matches latest Vim).
This commit is contained in:
@@ -2992,7 +2992,11 @@ bufadd({name}) *bufadd()*
|
|||||||
number. Otherwise return the buffer number of the newly
|
number. Otherwise return the buffer number of the newly
|
||||||
created buffer. When {name} is an empty string then a new
|
created buffer. When {name} is an empty string then a new
|
||||||
buffer is always created.
|
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|: >
|
< Can also be used as a |method|: >
|
||||||
let bufnr = 'somename'->bufadd()
|
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: >
|
Can also be used as a |method|, passing the text as the base: >
|
||||||
GetText()->setline(lnum)
|
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}.
|
Create or replace or add to the location list for window {nr}.
|
||||||
{nr} can be the window number or the |window-ID|.
|
{nr} can be the window number or the |window-ID|.
|
||||||
When {nr} is zero the current window is used.
|
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()|
|
only the items listed in {what} are set. Refer to |setqflist()|
|
||||||
for the list of supported keys in {what}.
|
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()*
|
setmatches({list} [, {win}]) *setmatches()*
|
||||||
Restores a list of matches saved by |getmatches() for the
|
Restores a list of matches saved by |getmatches() for the
|
||||||
current window|. Returns 0 if successful, otherwise -1. All
|
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
|
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|: >
|
||||||
|
GetMatches()->setmatches()
|
||||||
|
<
|
||||||
*setpos()*
|
*setpos()*
|
||||||
setpos({expr}, {list})
|
setpos({expr}, {list})
|
||||||
Set the position for String {expr}. Possible values:
|
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
|
also set the preferred column. Also see the "curswant" key in
|
||||||
|winrestview()|.
|
|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.
|
Create or replace or add to the quickfix list.
|
||||||
|
|
||||||
If the optional {what} dictionary argument is supplied, then
|
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
|
independent of the 'errorformat' setting. Use a command like
|
||||||
`:cc 1` to jump to the first position.
|
`: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()*
|
||||||
setreg({regname}, {value} [, {options}])
|
setreg({regname}, {value} [, {options}])
|
||||||
Set the register {regname} to {value}.
|
Set the register {regname} to {value}.
|
||||||
@@ -8944,6 +8960,10 @@ setreg({regname}, {value} [, {options}])
|
|||||||
nothing: >
|
nothing: >
|
||||||
:call setreg('a', '', 'al')
|
: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()*
|
settabvar({tabnr}, {varname}, {val}) *settabvar()*
|
||||||
Set tab-local variable {varname} to {val} in tab page {tabnr}.
|
Set tab-local variable {varname} to {val} in tab page {tabnr}.
|
||||||
|t:var|
|
|t:var|
|
||||||
@@ -8952,6 +8972,9 @@ settabvar({tabnr}, {varname}, {val}) *settabvar()*
|
|||||||
Tabs are numbered starting with one.
|
Tabs are numbered starting with one.
|
||||||
This function is not available in the |sandbox|.
|
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()*
|
settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
|
||||||
Set option or local variable {varname} in window {winnr} to
|
Set option or local variable {varname} in window {winnr} to
|
||||||
{val}.
|
{val}.
|
||||||
@@ -8968,6 +8991,9 @@ settabwinvar({tabnr}, {winnr}, {varname}, {val}) *settabwinvar()*
|
|||||||
:call settabwinvar(3, 2, "myvar", "foobar")
|
:call settabwinvar(3, 2, "myvar", "foobar")
|
||||||
< This function is not available in the |sandbox|.
|
< 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()*
|
settagstack({nr}, {dict} [, {action}]) *settagstack()*
|
||||||
Modify the tag stack of the window {nr} using {dict}.
|
Modify the tag stack of the window {nr} using {dict}.
|
||||||
{nr} can be the window number or the |window-ID|.
|
{nr} can be the window number or the |window-ID|.
|
||||||
@@ -9001,6 +9027,8 @@ settagstack({nr}, {dict} [, {action}]) *settagstack()*
|
|||||||
call settagstack(1003, stack)
|
call settagstack(1003, stack)
|
||||||
unlet 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()*
|
setwinvar({nr}, {varname}, {val}) *setwinvar()*
|
||||||
Like |settabwinvar()| for the current tab page.
|
Like |settabwinvar()| for the current tab page.
|
||||||
@@ -9008,10 +9036,16 @@ setwinvar({nr}, {varname}, {val}) *setwinvar()*
|
|||||||
:call setwinvar(1, "&list", 0)
|
:call setwinvar(1, "&list", 0)
|
||||||
:call setwinvar(2, "myvar", "foobar")
|
: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()*
|
sha256({string}) *sha256()*
|
||||||
Returns a String with 64 hex characters, which is the SHA256
|
Returns a String with 64 hex characters, which is the SHA256
|
||||||
checksum of {string}.
|
checksum of {string}.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetText()->sha256()
|
||||||
|
|
||||||
shellescape({string} [, {special}]) *shellescape()*
|
shellescape({string} [, {special}]) *shellescape()*
|
||||||
Escape {string} for use as a shell command argument.
|
Escape {string} for use as a shell command argument.
|
||||||
|
|
||||||
@@ -9043,6 +9077,8 @@ shellescape({string} [, {special}]) *shellescape()*
|
|||||||
:call system("chmod +w -- " . shellescape(expand("%")))
|
:call system("chmod +w -- " . shellescape(expand("%")))
|
||||||
< See also |::S|.
|
< See also |::S|.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetCommand()->shellescape()
|
||||||
|
|
||||||
shiftwidth([{col}]) *shiftwidth()*
|
shiftwidth([{col}]) *shiftwidth()*
|
||||||
Returns the effective value of 'shiftwidth'. This is the
|
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
|
'vartabstop' feature. If no {col} argument is given, column 1
|
||||||
will be assumed.
|
will be assumed.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetColumn()->shiftwidth()
|
||||||
|
|
||||||
sign_ functions are documented here: |sign-functions-details|
|
sign_ functions are documented here: |sign-functions-details|
|
||||||
|
|
||||||
simplify({filename}) *simplify()*
|
simplify({filename}) *simplify()*
|
||||||
|
@@ -314,18 +314,18 @@ return {
|
|||||||
setenv={args=2, base=2},
|
setenv={args=2, base=2},
|
||||||
setfperm={args=2, base=1},
|
setfperm={args=2, base=1},
|
||||||
setline={args=2, base=2},
|
setline={args=2, base=2},
|
||||||
setloclist={args={2, 4}},
|
setloclist={args={2, 4}, base=2},
|
||||||
setmatches={args={1, 2}},
|
setmatches={args={1, 2}, base=1},
|
||||||
setpos={args=2},
|
setpos={args=2, base=2},
|
||||||
setqflist={args={1, 3}},
|
setqflist={args={1, 3}, base=1},
|
||||||
setreg={args={2, 3}},
|
setreg={args={2, 3}, base=2},
|
||||||
settabvar={args=3},
|
settabvar={args=3, base=3},
|
||||||
settabwinvar={args=4},
|
settabwinvar={args=4, base=4},
|
||||||
settagstack={args={2, 3}},
|
settagstack={args={2, 3}, base=2},
|
||||||
setwinvar={args=3},
|
setwinvar={args=3, base=3},
|
||||||
sha256={args=1},
|
sha256={args=1, base=1},
|
||||||
shellescape={args={1, 2}},
|
shellescape={args={1, 2}, base=1},
|
||||||
shiftwidth={args={0, 1}},
|
shiftwidth={args={0, 1}, base=1},
|
||||||
sign_define={args={1, 2}, base=1},
|
sign_define={args={1, 2}, base=1},
|
||||||
sign_getdefined={args={0, 1}, base=1},
|
sign_getdefined={args={0, 1}, base=1},
|
||||||
sign_getplaced={args={0, 2}, base=1},
|
sign_getplaced={args={0, 2}, base=1},
|
||||||
|
@@ -48,7 +48,7 @@ function Test_getbufwintabinfo()
|
|||||||
tabnew | let w3_id = win_getid()
|
tabnew | let w3_id = win_getid()
|
||||||
new | let w4_id = win_getid()
|
new | let w4_id = win_getid()
|
||||||
vert new | let w5_id = win_getid()
|
vert new | let w5_id = win_getid()
|
||||||
call setwinvar(0, 'signal', 'green')
|
eval 'green'->setwinvar(0, 'signal')
|
||||||
tabfirst
|
tabfirst
|
||||||
let winlist = getwininfo()
|
let winlist = getwininfo()
|
||||||
call assert_equal(5, len(winlist))
|
call assert_equal(5, len(winlist))
|
||||||
|
@@ -37,7 +37,7 @@ endfunc
|
|||||||
" Very short version of what matchparen does.
|
" Very short version of what matchparen does.
|
||||||
function s:Highlight_Matching_Pair()
|
function s:Highlight_Matching_Pair()
|
||||||
let save_cursor = getcurpos()
|
let save_cursor = getcurpos()
|
||||||
call setpos('.', save_cursor)
|
eval save_cursor->setpos('.')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_curswant_with_autocommand()
|
func Test_curswant_with_autocommand()
|
||||||
|
@@ -493,7 +493,7 @@ func Test_setmatches()
|
|||||||
let set[0]['conceal'] = 5
|
let set[0]['conceal'] = 5
|
||||||
let exp[0]['conceal'] = '5'
|
let exp[0]['conceal'] = '5'
|
||||||
endif
|
endif
|
||||||
call setmatches(set)
|
eval set->setmatches()
|
||||||
call assert_equal(exp, getmatches())
|
call assert_equal(exp, getmatches())
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -1219,7 +1219,7 @@ func Test_shellescape()
|
|||||||
let save_shell = &shell
|
let save_shell = &shell
|
||||||
set shell=bash
|
set shell=bash
|
||||||
call assert_equal("'text'", shellescape('text'))
|
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"))
|
||||||
|
|
||||||
call assert_equal("'te%xt'", shellescape("te%xt"))
|
call assert_equal("'te%xt'", shellescape("te%xt"))
|
||||||
|
@@ -39,7 +39,7 @@ func Test_put_lines()
|
|||||||
call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1, '$'))
|
call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1, '$'))
|
||||||
" clean up
|
" clean up
|
||||||
bw!
|
bw!
|
||||||
call setreg('a', a[0], a[1])
|
eval a[0]->setreg('a', a[1])
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_put_expr()
|
func Test_put_expr()
|
||||||
|
@@ -811,7 +811,7 @@ func Test_locationlist()
|
|||||||
" NOTE: problem 1:
|
" NOTE: problem 1:
|
||||||
" intentionally not setting 'lnum' so that the quickfix entries are not
|
" intentionally not setting 'lnum' so that the quickfix entries are not
|
||||||
" valid
|
" valid
|
||||||
call setloclist(0, qflist, ' ')
|
eval qflist->setloclist(0, ' ')
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Test A
|
" Test A
|
||||||
@@ -1699,7 +1699,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_setqflist_invalid_nr()
|
func Test_setqflist_invalid_nr()
|
||||||
" The following command used to crash Vim
|
" The following command used to crash Vim
|
||||||
call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST})
|
eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_setqflist_user_sets_buftype()
|
func Test_setqflist_user_sets_buftype()
|
||||||
|
@@ -6,17 +6,17 @@ endif
|
|||||||
|
|
||||||
function Test_sha256()
|
function Test_sha256()
|
||||||
" test for empty string:
|
" test for empty string:
|
||||||
call assert_equal(sha256(""), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
|
call assert_equal('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', sha256(""))
|
||||||
|
|
||||||
"'test for 1 char:
|
"'test for 1 char:
|
||||||
call assert_equal(sha256("a"), 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb')
|
call assert_equal('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', sha256("a"))
|
||||||
"
|
"
|
||||||
"test for 3 chars:
|
"test for 3 chars:
|
||||||
call assert_equal(sha256("abc"), 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')
|
call assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', "abc"->sha256())
|
||||||
|
|
||||||
" test for contains meta char:
|
" 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:
|
" 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
|
endfunction
|
||||||
|
@@ -35,7 +35,7 @@ function Test_tabpage()
|
|||||||
tabnew
|
tabnew
|
||||||
tabfirst
|
tabfirst
|
||||||
call settabvar(2, 'val_num', 100)
|
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 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'])
|
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\+')
|
let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
|
||||||
call assert_equal(['a', 'a'], s:li)
|
call assert_equal(['a', 'a'], s:li)
|
||||||
let 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\+')
|
let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
|
||||||
call assert_equal(['2', '4'], s:li)
|
call assert_equal(['2', '4'], s:li)
|
||||||
|
|
||||||
|
@@ -351,7 +351,7 @@ func Test_getsettagstack()
|
|||||||
" Try to set current index to invalid values
|
" Try to set current index to invalid values
|
||||||
call settagstack(1, {'curidx' : -1})
|
call settagstack(1, {'curidx' : -1})
|
||||||
call assert_equal(1, gettagstack().curidx)
|
call assert_equal(1, gettagstack().curidx)
|
||||||
call settagstack(1, {'curidx' : 50})
|
eval {'curidx' : 50}->settagstack(1)
|
||||||
call assert_equal(4, gettagstack().curidx)
|
call assert_equal(4, gettagstack().curidx)
|
||||||
|
|
||||||
" Try pushing invalid items onto the stack
|
" Try pushing invalid items onto the stack
|
||||||
|
@@ -330,7 +330,7 @@ func Test_vartabs_shiftwidth()
|
|||||||
let lines = ScreenLines([1, 2], winwidth(0))
|
let lines = ScreenLines([1, 2], winwidth(0))
|
||||||
call s:compare_lines(expect2, lines)
|
call s:compare_lines(expect2, lines)
|
||||||
call assert_equal(20, shiftwidth(virtcol('.')-2))
|
call assert_equal(20, shiftwidth(virtcol('.')-2))
|
||||||
call assert_equal(30, shiftwidth(virtcol('.')))
|
call assert_equal(30, virtcol('.')->shiftwidth())
|
||||||
norm! $>>
|
norm! $>>
|
||||||
let expect3 = [' ', ' x ', '~ ']
|
let expect3 = [' ', ' x ', '~ ']
|
||||||
let lines = ScreenLines([1, 3], winwidth(0))
|
let lines = ScreenLines([1, 3], winwidth(0))
|
||||||
|
Reference in New Issue
Block a user