aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-09-01 12:28:16 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-10-03 20:12:20 +0100
commitc5583df3c081e485b521570891dbdd16cd952a85 (patch)
treeaa6267bea0e5a4b20daf263228f7e60af9351223
parentd23d37b212d7b47ae1f729de5e0ea46b456ad2e5 (diff)
downloadrneovim-c5583df3c081e485b521570891dbdd16cd952a85.tar.gz
rneovim-c5583df3c081e485b521570891dbdd16cd952a85.tar.bz2
rneovim-c5583df3c081e485b521570891dbdd16cd952a85.zip
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. https://github.com/vim/vim/commit/3f4f3d8e7e6fc0494d00cfb75669a554c8e67c8b test_prompt_buffer.vim already had all the changes, except Test_prompt_garbage_collect().
-rw-r--r--runtime/doc/eval.txt32
-rw-r--r--src/nvim/eval.lua22
-rw-r--r--src/nvim/testdir/test_functions.vim14
-rw-r--r--src/nvim/testdir/test_perl.vim2
-rw-r--r--src/nvim/testdir/test_prompt_buffer.vim7
-rw-r--r--src/nvim/testdir/test_python2.vim2
-rw-r--r--src/nvim/testdir/test_python3.vim2
-rw-r--r--src/nvim/testdir/test_pyx2.vim2
8 files changed, 56 insertions, 27 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 3253fc649f..1878913311 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -7246,6 +7246,9 @@ nextnonblank({lnum}) *nextnonblank()*
{lnum} is used like with |getline()|.
See also |prevnonblank()|.
+ Can also be used as a |method|: >
+ GetLnum()->nextnonblank()
+
nr2char({expr} [, {utf8}]) *nr2char()*
Return a string with a single character, which has the number
value {expr}. Examples: >
@@ -7260,6 +7263,9 @@ nr2char({expr} [, {utf8}]) *nr2char()*
characters. nr2char(0) is a real NUL and terminates the
string, thus results in an empty string.
+ Can also be used as a |method|: >
+ GetNumber()->nr2char()
+
nvim_...({...}) *E5555* *nvim_...()* *eval-api*
Call nvim |api| functions. The type checking of arguments will
be stricter than for most other builtins. For instance,
@@ -7288,6 +7294,9 @@ pathshorten({path}) *pathshorten()*
< ~/.c/n/a/file1.vim ~
It doesn't matter if the path exists or not.
+ Can also be used as a |method|: >
+ GetDirectories()->pathshorten()
+
perleval({expr}) *perleval()*
Evaluate |perl| expression {expr} and return its result
converted to Vim data structures.
@@ -7303,6 +7312,9 @@ perleval({expr}) *perleval()*
:echo perleval('[1 .. 4]')
< [1, 2, 3, 4]
+ Can also be used as a |method|: >
+ GetExpr()->perleval()
+
pow({x}, {y}) *pow()*
Return the power of {x} to the exponent {y} as a |Float|.
{x} and {y} must evaluate to a |Float| or a |Number|.
@@ -7326,6 +7338,8 @@ prevnonblank({lnum}) *prevnonblank()*
{lnum} is used like with |getline()|.
Also see |nextnonblank()|.
+ Can also be used as a |method|: >
+ GetLnum()->prevnonblank()
printf({fmt}, {expr1} ...) *printf()*
Return a String with {fmt}, where "%" items are replaced by
@@ -7558,6 +7572,9 @@ prompt_setcallback({buf}, {expr}) *prompt_setcallback()*
endif
endfunc
+< Can also be used as a |method|: >
+ GetBuffer()->prompt_setcallback(callback)
+
prompt_setinterrupt({buf}, {expr}) *prompt_setinterrupt()*
Set a callback for buffer {buf} to {expr}. When {expr} is an
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,
as in any buffer.
+ Can also be used as a |method|: >
+ GetBuffer()->prompt_setinterrupt(callback)
+
prompt_setprompt({buf}, {text}) *prompt_setprompt()*
Set prompt for buffer {buf} to {text}. You most likely want
{text} to end in a space.
The result is only visible if {buf} has 'buftype' set to
"prompt". Example: >
call prompt_setprompt(bufnr(''), 'command: ')
+<
+ Can also be used as a |method|: >
+ GetBuffer()->prompt_setprompt('command: ')
pum_getpos() *pum_getpos()*
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
keys converted to strings.
+ Can also be used as a |method|: >
+ GetExpr()->py3eval()
+<
*E858* *E859*
pyeval({expr}) *pyeval()*
Evaluate Python expression {expr} and return its result
@@ -7613,12 +7639,18 @@ pyeval({expr}) *pyeval()*
Dictionaries are represented as Vim |Dictionary| type,
non-string keys result in error.
+ Can also be used as a |method|: >
+ GetExpr()->pyeval()
+
pyxeval({expr}) *pyxeval()*
Evaluate Python expression {expr} and return its result
converted to Vim data structures.
Uses Python 2 or 3, see |python_x| and 'pyxversion'.
See also: |pyeval()|, |py3eval()|
+ Can also be used as a |method|: >
+ GetExpr()->pyxeval()
+<
*E726* *E727*
range({expr} [, {max} [, {stride}]]) *range()*
Returns a |List| with Numbers:
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 854bfd5f61..741b8547fe 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -254,23 +254,23 @@ return {
mode={args={0, 1}, base=1},
msgpackdump={args={1, 2}},
msgpackparse={args=1},
- nextnonblank={args=1},
- nr2char={args={1, 2}},
+ nextnonblank={args=1, base=1},
+ nr2char={args={1, 2}, base=1},
['or']={args=2, base=1},
- pathshorten={args=1},
+ pathshorten={args=1, base=1},
pow={args=2, base=1},
- prevnonblank={args=1},
+ prevnonblank={args=1, base=1},
printf={args=varargs(1), base=2},
prompt_getprompt={args=1},
- prompt_setcallback={args={2, 2}},
- prompt_setinterrupt={args={2, 2}},
- prompt_setprompt={args={2, 2}},
+ prompt_setcallback={args={2, 2}, base=1},
+ prompt_setinterrupt={args={2, 2}, base=1},
+ prompt_setprompt={args={2, 2}, base=1},
pum_getpos={},
pumvisible={},
- py3eval={args=1},
- pyeval={args=1},
- pyxeval={args=1},
- perleval={args=1},
+ py3eval={args=1, base=1},
+ 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}},
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim
index d4da8dde40..c08b43736b 100644
--- a/src/nvim/testdir/test_functions.vim
+++ b/src/nvim/testdir/test_functions.vim
@@ -360,10 +360,10 @@ endfunc
func Test_pathshorten()
call assert_equal('', pathshorten(''))
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/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/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(0))
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(4))
call assert_equal(6, nextnonblank(5))
call assert_equal(6, nextnonblank(6))
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(0))
- call assert_equal(1, prevnonblank(1))
+ call assert_equal(1, 1->prevnonblank())
call assert_equal(1, prevnonblank(2))
call assert_equal(1, prevnonblank(3))
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(7, prevnonblank(7))
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 ", " ", 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))
endfunc
diff --git a/src/nvim/testdir/test_perl.vim b/src/nvim/testdir/test_perl.vim
index 872194a804..b911a982f9 100644
--- a/src/nvim/testdir/test_perl.vim
+++ b/src/nvim/testdir/test_perl.vim
@@ -32,7 +32,7 @@ endfunc
funct Test_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('0z8081FEFF', perleval('VIM::Blob("\x80\x81\xfe\xff")'))
endfunc
diff --git a/src/nvim/testdir/test_prompt_buffer.vim b/src/nvim/testdir/test_prompt_buffer.vim
index 6fc5850be3..3da46eb1a6 100644
--- a/src/nvim/testdir/test_prompt_buffer.vim
+++ b/src/nvim/testdir/test_prompt_buffer.vim
@@ -110,11 +110,8 @@ func Test_prompt_garbage_collect()
new
set buftype=prompt
- " Nvim doesn't support method call syntax yet.
- " eval bufnr('')->prompt_setcallback(function('MyPromptCallback', [{}]))
- " eval bufnr('')->prompt_setinterrupt(function('MyPromptInterrupt', [{}]))
- eval prompt_setcallback(bufnr(''), function('MyPromptCallback', [{}]))
- eval prompt_setinterrupt(bufnr(''), function('MyPromptInterrupt', [{}]))
+ eval bufnr('')->prompt_setcallback(function('MyPromptCallback', [{}]))
+ eval bufnr('')->prompt_setinterrupt(function('MyPromptInterrupt', [{}]))
call test_garbagecollect_now()
" Must not crash
call feedkeys("\<CR>\<C-C>", 'xt')
diff --git a/src/nvim/testdir/test_python2.vim b/src/nvim/testdir/test_python2.vim
index 5895ac85a8..ae8bc57c7f 100644
--- a/src/nvim/testdir/test_python2.vim
+++ b/src/nvim/testdir/test_python2.vim
@@ -59,7 +59,7 @@ func Test_vim_function()
try
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
call assert_false(v:exception)
endtry
diff --git a/src/nvim/testdir/test_python3.vim b/src/nvim/testdir/test_python3.vim
index 637648817c..54da3d2eba 100644
--- a/src/nvim/testdir/test_python3.vim
+++ b/src/nvim/testdir/test_python3.vim
@@ -59,7 +59,7 @@ func Test_vim_function()
try
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
call assert_false(v:exception)
endtry
diff --git a/src/nvim/testdir/test_pyx2.vim b/src/nvim/testdir/test_pyx2.vim
index 10ff3b6e58..b6ed80f842 100644
--- a/src/nvim/testdir/test_pyx2.vim
+++ b/src/nvim/testdir/test_pyx2.vim
@@ -35,7 +35,7 @@ endfunc
func Test_pyxeval()
pyx import sys
- call assert_match(s:py2pattern, split(pyxeval('sys.version'))[0])
+ call assert_match(s:py2pattern, split('sys.version'->pyxeval())[0])
endfunc