mirror of
https://github.com/neovim/neovim.git
synced 2025-09-17 00:38:17 +00:00
vim-patch:8.1.1984: more functions can be used as methods
Problem: More functions can be used as methods.
Solution: Make various functions usable as a method.
3f4f3d8e7e
test_prompt_buffer.vim already had all the changes, except
Test_prompt_garbage_collect().
This commit is contained in:
@@ -7246,6 +7246,9 @@ nextnonblank({lnum}) *nextnonblank()*
|
|||||||
{lnum} is used like with |getline()|.
|
{lnum} is used like with |getline()|.
|
||||||
See also |prevnonblank()|.
|
See also |prevnonblank()|.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetLnum()->nextnonblank()
|
||||||
|
|
||||||
nr2char({expr} [, {utf8}]) *nr2char()*
|
nr2char({expr} [, {utf8}]) *nr2char()*
|
||||||
Return a string with a single character, which has the number
|
Return a string with a single character, which has the number
|
||||||
value {expr}. Examples: >
|
value {expr}. Examples: >
|
||||||
@@ -7260,6 +7263,9 @@ nr2char({expr} [, {utf8}]) *nr2char()*
|
|||||||
characters. nr2char(0) is a real NUL and terminates the
|
characters. nr2char(0) is a real NUL and terminates the
|
||||||
string, thus results in an empty string.
|
string, thus results in an empty string.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetNumber()->nr2char()
|
||||||
|
|
||||||
nvim_...({...}) *E5555* *nvim_...()* *eval-api*
|
nvim_...({...}) *E5555* *nvim_...()* *eval-api*
|
||||||
Call nvim |api| functions. The type checking of arguments will
|
Call nvim |api| functions. The type checking of arguments will
|
||||||
be stricter than for most other builtins. For instance,
|
be stricter than for most other builtins. For instance,
|
||||||
@@ -7288,6 +7294,9 @@ pathshorten({path}) *pathshorten()*
|
|||||||
< ~/.c/n/a/file1.vim ~
|
< ~/.c/n/a/file1.vim ~
|
||||||
It doesn't matter if the path exists or not.
|
It doesn't matter if the path exists or not.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetDirectories()->pathshorten()
|
||||||
|
|
||||||
perleval({expr}) *perleval()*
|
perleval({expr}) *perleval()*
|
||||||
Evaluate |perl| expression {expr} and return its result
|
Evaluate |perl| expression {expr} and return its result
|
||||||
converted to Vim data structures.
|
converted to Vim data structures.
|
||||||
@@ -7303,6 +7312,9 @@ perleval({expr}) *perleval()*
|
|||||||
:echo perleval('[1 .. 4]')
|
:echo perleval('[1 .. 4]')
|
||||||
< [1, 2, 3, 4]
|
< [1, 2, 3, 4]
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetExpr()->perleval()
|
||||||
|
|
||||||
pow({x}, {y}) *pow()*
|
pow({x}, {y}) *pow()*
|
||||||
Return the power of {x} to the exponent {y} as a |Float|.
|
Return the power of {x} to the exponent {y} as a |Float|.
|
||||||
{x} and {y} must evaluate to a |Float| or a |Number|.
|
{x} and {y} must evaluate to a |Float| or a |Number|.
|
||||||
@@ -7326,6 +7338,8 @@ prevnonblank({lnum}) *prevnonblank()*
|
|||||||
{lnum} is used like with |getline()|.
|
{lnum} is used like with |getline()|.
|
||||||
Also see |nextnonblank()|.
|
Also see |nextnonblank()|.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetLnum()->prevnonblank()
|
||||||
|
|
||||||
printf({fmt}, {expr1} ...) *printf()*
|
printf({fmt}, {expr1} ...) *printf()*
|
||||||
Return a String with {fmt}, where "%" items are replaced by
|
Return a String with {fmt}, where "%" items are replaced by
|
||||||
@@ -7558,6 +7572,9 @@ prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
< Can also be used as a |method|: >
|
||||||
|
GetBuffer()->prompt_setcallback(callback)
|
||||||
|
|
||||||
prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
|
prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
|
||||||
Set a callback for buffer {buf} to {expr}. When {expr} is an
|
Set a callback for buffer {buf} to {expr}. When {expr} is an
|
||||||
empty string the callback is removed. This has only effect if
|
empty string the callback is removed. This has only effect if
|
||||||
@@ -7567,12 +7584,18 @@ prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
|
|||||||
mode. Without setting a callback Vim will exit Insert mode,
|
mode. Without setting a callback Vim will exit Insert mode,
|
||||||
as in any buffer.
|
as in any buffer.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetBuffer()->prompt_setinterrupt(callback)
|
||||||
|
|
||||||
prompt_setprompt({buf}, {text}) *prompt_setprompt()*
|
prompt_setprompt({buf}, {text}) *prompt_setprompt()*
|
||||||
Set prompt for buffer {buf} to {text}. You most likely want
|
Set prompt for buffer {buf} to {text}. You most likely want
|
||||||
{text} to end in a space.
|
{text} to end in a space.
|
||||||
The result is only visible if {buf} has 'buftype' set to
|
The result is only visible if {buf} has 'buftype' set to
|
||||||
"prompt". Example: >
|
"prompt". Example: >
|
||||||
call prompt_setprompt(bufnr(''), 'command: ')
|
call prompt_setprompt(bufnr(''), 'command: ')
|
||||||
|
<
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetBuffer()->prompt_setprompt('command: ')
|
||||||
|
|
||||||
pum_getpos() *pum_getpos()*
|
pum_getpos() *pum_getpos()*
|
||||||
If the popup menu (see |ins-completion-menu|) is not visible,
|
If the popup menu (see |ins-completion-menu|) is not visible,
|
||||||
@@ -7603,6 +7626,9 @@ py3eval({expr}) *py3eval()*
|
|||||||
Dictionaries are represented as Vim |Dictionary| type with
|
Dictionaries are represented as Vim |Dictionary| type with
|
||||||
keys converted to strings.
|
keys converted to strings.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetExpr()->py3eval()
|
||||||
|
<
|
||||||
*E858* *E859*
|
*E858* *E859*
|
||||||
pyeval({expr}) *pyeval()*
|
pyeval({expr}) *pyeval()*
|
||||||
Evaluate Python expression {expr} and return its result
|
Evaluate Python expression {expr} and return its result
|
||||||
@@ -7613,12 +7639,18 @@ pyeval({expr}) *pyeval()*
|
|||||||
Dictionaries are represented as Vim |Dictionary| type,
|
Dictionaries are represented as Vim |Dictionary| type,
|
||||||
non-string keys result in error.
|
non-string keys result in error.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetExpr()->pyeval()
|
||||||
|
|
||||||
pyxeval({expr}) *pyxeval()*
|
pyxeval({expr}) *pyxeval()*
|
||||||
Evaluate Python expression {expr} and return its result
|
Evaluate Python expression {expr} and return its result
|
||||||
converted to Vim data structures.
|
converted to Vim data structures.
|
||||||
Uses Python 2 or 3, see |python_x| and 'pyxversion'.
|
Uses Python 2 or 3, see |python_x| and 'pyxversion'.
|
||||||
See also: |pyeval()|, |py3eval()|
|
See also: |pyeval()|, |py3eval()|
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetExpr()->pyxeval()
|
||||||
|
<
|
||||||
*E726* *E727*
|
*E726* *E727*
|
||||||
range({expr} [, {max} [, {stride}]]) *range()*
|
range({expr} [, {max} [, {stride}]]) *range()*
|
||||||
Returns a |List| with Numbers:
|
Returns a |List| with Numbers:
|
||||||
|
@@ -254,23 +254,23 @@ return {
|
|||||||
mode={args={0, 1}, base=1},
|
mode={args={0, 1}, base=1},
|
||||||
msgpackdump={args={1, 2}},
|
msgpackdump={args={1, 2}},
|
||||||
msgpackparse={args=1},
|
msgpackparse={args=1},
|
||||||
nextnonblank={args=1},
|
nextnonblank={args=1, base=1},
|
||||||
nr2char={args={1, 2}},
|
nr2char={args={1, 2}, base=1},
|
||||||
['or']={args=2, base=1},
|
['or']={args=2, base=1},
|
||||||
pathshorten={args=1},
|
pathshorten={args=1, base=1},
|
||||||
pow={args=2, base=1},
|
pow={args=2, base=1},
|
||||||
prevnonblank={args=1},
|
prevnonblank={args=1, base=1},
|
||||||
printf={args=varargs(1), base=2},
|
printf={args=varargs(1), base=2},
|
||||||
prompt_getprompt={args=1},
|
prompt_getprompt={args=1},
|
||||||
prompt_setcallback={args={2, 2}},
|
prompt_setcallback={args={2, 2}, base=1},
|
||||||
prompt_setinterrupt={args={2, 2}},
|
prompt_setinterrupt={args={2, 2}, base=1},
|
||||||
prompt_setprompt={args={2, 2}},
|
prompt_setprompt={args={2, 2}, base=1},
|
||||||
pum_getpos={},
|
pum_getpos={},
|
||||||
pumvisible={},
|
pumvisible={},
|
||||||
py3eval={args=1},
|
py3eval={args=1, base=1},
|
||||||
pyeval={args=1},
|
pyeval={args=1, base=1},
|
||||||
pyxeval={args=1},
|
pyxeval={args=1, base=1},
|
||||||
perleval={args=1},
|
perleval={args=1, base=1},
|
||||||
range={args={1, 3}},
|
range={args={1, 3}},
|
||||||
readdir={args={1, 2}},
|
readdir={args={1, 2}},
|
||||||
readfile={args={1, 3}},
|
readfile={args={1, 3}},
|
||||||
|
@@ -360,10 +360,10 @@ endfunc
|
|||||||
func Test_pathshorten()
|
func Test_pathshorten()
|
||||||
call assert_equal('', pathshorten(''))
|
call assert_equal('', pathshorten(''))
|
||||||
call assert_equal('foo', pathshorten('foo'))
|
call assert_equal('foo', pathshorten('foo'))
|
||||||
call assert_equal('/foo', pathshorten('/foo'))
|
call assert_equal('/foo', '/foo'->pathshorten())
|
||||||
call assert_equal('f/', pathshorten('foo/'))
|
call assert_equal('f/', pathshorten('foo/'))
|
||||||
call assert_equal('f/bar', pathshorten('foo/bar'))
|
call assert_equal('f/bar', pathshorten('foo/bar'))
|
||||||
call assert_equal('f/b/foobar', pathshorten('foo/bar/foobar'))
|
call assert_equal('f/b/foobar', 'foo/bar/foobar'->pathshorten())
|
||||||
call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar'))
|
call assert_equal('/f/b/foobar', pathshorten('/foo/bar/foobar'))
|
||||||
call assert_equal('.f/bar', pathshorten('.foo/bar'))
|
call assert_equal('.f/bar', pathshorten('.foo/bar'))
|
||||||
call assert_equal('~f/bar', pathshorten('~foo/bar'))
|
call assert_equal('~f/bar', pathshorten('~foo/bar'))
|
||||||
@@ -869,21 +869,21 @@ Test
|
|||||||
call assert_equal(0, nextnonblank(-1))
|
call assert_equal(0, nextnonblank(-1))
|
||||||
call assert_equal(0, nextnonblank(0))
|
call assert_equal(0, nextnonblank(0))
|
||||||
call assert_equal(1, nextnonblank(1))
|
call assert_equal(1, nextnonblank(1))
|
||||||
call assert_equal(4, nextnonblank(2))
|
call assert_equal(4, 2->nextnonblank())
|
||||||
call assert_equal(4, nextnonblank(3))
|
call assert_equal(4, nextnonblank(3))
|
||||||
call assert_equal(4, nextnonblank(4))
|
call assert_equal(4, nextnonblank(4))
|
||||||
call assert_equal(6, nextnonblank(5))
|
call assert_equal(6, nextnonblank(5))
|
||||||
call assert_equal(6, nextnonblank(6))
|
call assert_equal(6, nextnonblank(6))
|
||||||
call assert_equal(7, nextnonblank(7))
|
call assert_equal(7, nextnonblank(7))
|
||||||
call assert_equal(0, nextnonblank(8))
|
call assert_equal(0, 8->nextnonblank())
|
||||||
|
|
||||||
call assert_equal(0, prevnonblank(-1))
|
call assert_equal(0, prevnonblank(-1))
|
||||||
call assert_equal(0, prevnonblank(0))
|
call assert_equal(0, prevnonblank(0))
|
||||||
call assert_equal(1, prevnonblank(1))
|
call assert_equal(1, 1->prevnonblank())
|
||||||
call assert_equal(1, prevnonblank(2))
|
call assert_equal(1, prevnonblank(2))
|
||||||
call assert_equal(1, prevnonblank(3))
|
call assert_equal(1, prevnonblank(3))
|
||||||
call assert_equal(4, prevnonblank(4))
|
call assert_equal(4, prevnonblank(4))
|
||||||
call assert_equal(4, prevnonblank(5))
|
call assert_equal(4, 5->prevnonblank())
|
||||||
call assert_equal(6, prevnonblank(6))
|
call assert_equal(6, prevnonblank(6))
|
||||||
call assert_equal(7, prevnonblank(7))
|
call assert_equal(7, prevnonblank(7))
|
||||||
call assert_equal(0, prevnonblank(8))
|
call assert_equal(0, prevnonblank(8))
|
||||||
@@ -1292,7 +1292,7 @@ func Test_trim()
|
|||||||
call assert_fails('call trim(" vim ", " ", -1)', 'E475:')
|
call assert_fails('call trim(" vim ", " ", -1)', 'E475:')
|
||||||
call assert_fails('call trim(" vim ", " ", 3)', 'E475:')
|
call assert_fails('call trim(" vim ", " ", 3)', 'E475:')
|
||||||
|
|
||||||
let chars = join(map(range(1, 0x20) + [0xa0], {n -> nr2char(n)}), '')
|
let chars = join(map(range(1, 0x20) + [0xa0], {n -> n->nr2char()}), '')
|
||||||
call assert_equal("x", trim(chars . "x" . chars))
|
call assert_equal("x", trim(chars . "x" . chars))
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -32,7 +32,7 @@ endfunc
|
|||||||
|
|
||||||
funct Test_VIM_Blob()
|
funct Test_VIM_Blob()
|
||||||
call assert_equal('0z', perleval('VIM::Blob("")'))
|
call assert_equal('0z', perleval('VIM::Blob("")'))
|
||||||
call assert_equal('0z31326162', perleval('VIM::Blob("12ab")'))
|
call assert_equal('0z31326162', 'VIM::Blob("12ab")'->perleval())
|
||||||
call assert_equal('0z00010203', perleval('VIM::Blob("\x00\x01\x02\x03")'))
|
call assert_equal('0z00010203', perleval('VIM::Blob("\x00\x01\x02\x03")'))
|
||||||
call assert_equal('0z8081FEFF', perleval('VIM::Blob("\x80\x81\xfe\xff")'))
|
call assert_equal('0z8081FEFF', perleval('VIM::Blob("\x80\x81\xfe\xff")'))
|
||||||
endfunc
|
endfunc
|
||||||
|
@@ -110,11 +110,8 @@ func Test_prompt_garbage_collect()
|
|||||||
|
|
||||||
new
|
new
|
||||||
set buftype=prompt
|
set buftype=prompt
|
||||||
" Nvim doesn't support method call syntax yet.
|
eval bufnr('')->prompt_setcallback(function('MyPromptCallback', [{}]))
|
||||||
" eval bufnr('')->prompt_setcallback(function('MyPromptCallback', [{}]))
|
eval bufnr('')->prompt_setinterrupt(function('MyPromptInterrupt', [{}]))
|
||||||
" eval bufnr('')->prompt_setinterrupt(function('MyPromptInterrupt', [{}]))
|
|
||||||
eval prompt_setcallback(bufnr(''), function('MyPromptCallback', [{}]))
|
|
||||||
eval prompt_setinterrupt(bufnr(''), function('MyPromptInterrupt', [{}]))
|
|
||||||
call test_garbagecollect_now()
|
call test_garbagecollect_now()
|
||||||
" Must not crash
|
" Must not crash
|
||||||
call feedkeys("\<CR>\<C-C>", 'xt')
|
call feedkeys("\<CR>\<C-C>", 'xt')
|
||||||
|
@@ -59,7 +59,7 @@ func Test_vim_function()
|
|||||||
|
|
||||||
try
|
try
|
||||||
py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()'))
|
py f = vim.Function('\x80\xfdR' + vim.eval('s:foo()'))
|
||||||
call assert_equal(name, pyeval('f.name'))
|
call assert_equal(name, 'f.name'->pyeval())
|
||||||
catch
|
catch
|
||||||
call assert_false(v:exception)
|
call assert_false(v:exception)
|
||||||
endtry
|
endtry
|
||||||
|
@@ -59,7 +59,7 @@ func Test_vim_function()
|
|||||||
|
|
||||||
try
|
try
|
||||||
py3 f = vim.Function(b'\x80\xfdR' + vim.eval('s:foo()').encode())
|
py3 f = vim.Function(b'\x80\xfdR' + vim.eval('s:foo()').encode())
|
||||||
call assert_equal(name, py3eval('f.name'))
|
call assert_equal(name, 'f.name'->py3eval())
|
||||||
catch
|
catch
|
||||||
call assert_false(v:exception)
|
call assert_false(v:exception)
|
||||||
endtry
|
endtry
|
||||||
|
@@ -35,7 +35,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_pyxeval()
|
func Test_pyxeval()
|
||||||
pyx import sys
|
pyx import sys
|
||||||
call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0])
|
call assert_match(s:py2pattern, split('sys.version'->pyxeval())[0])
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user