aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Dewar <seandewar@users.noreply.github.com>2021-08-07 17:06:08 +0100
committerSean Dewar <seandewar@users.noreply.github.com>2021-08-12 22:35:24 +0100
commit5fbc1a49c719c0c93fa73277ac30d17f797d096d (patch)
treec23089dd05097a388cad40e42d284ffdb78fcd90
parent41dbd3a2e05f5f4d59e076f8b8c82ad974d2bbd5 (diff)
downloadrneovim-5fbc1a49c719c0c93fa73277ac30d17f797d096d.tar.gz
rneovim-5fbc1a49c719c0c93fa73277ac30d17f797d096d.tar.bz2
rneovim-5fbc1a49c719c0c93fa73277ac30d17f797d096d.zip
vim-patch:8.1.1888: 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/073e4b92e613d22ce7b16e0fbf5c0e40cb5f9b2c test_popup.vim already has the changes from this patch (they're N/A anyway).
-rw-r--r--runtime/doc/eval.txt35
-rw-r--r--src/nvim/eval.lua24
-rw-r--r--src/nvim/testdir/test_arglist.vim4
-rw-r--r--src/nvim/testdir/test_functions.vim6
-rw-r--r--src/nvim/testdir/test_hide.vim2
-rw-r--r--src/nvim/testdir/test_vimscript.vim4
6 files changed, 53 insertions, 22 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 814931ff2b..511d072366 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2650,6 +2650,8 @@ and({expr}, {expr}) *and()*
to a number. A List, Dict or Float argument causes an error.
Example: >
:let flag = and(bits, 0x80)
+< Can also be used as a |method|: >
+ :let flag = bits->and(0x80)
api_info() *api_info()*
Returns Dictionary of |api-metadata|.
@@ -2788,8 +2790,8 @@ browse({save}, {title}, {initdir}, {default})
{title} title for the requester
{initdir} directory to start browsing in
{default} default file name
- When the "Cancel" button is hit, something went wrong, or
- browsing is not possible, an empty string is returned.
+ An empty string is returned when the "Cancel" button is hit,
+ something went wrong, or browsing is not possible.
*browsedir()*
browsedir({title}, {initdir})
@@ -2811,6 +2813,8 @@ bufadd({name}) *bufadd()*
created buffer. When {name} is an empty string then a new
buffer is always created.
The buffer will not have' 'buflisted' set.
+< Can also be used as a |method|: >
+ let bufnr = 'somename'->bufadd()
bufexists({expr}) *bufexists()*
The result is a Number, which is |TRUE| if a buffer called
@@ -2834,11 +2838,17 @@ bufexists({expr}) *bufexists()*
Use "bufexists(0)" to test for the existence of an alternate
file name.
+ Can also be used as a |method|: >
+ let exists = 'somename'->bufexists()
+
buflisted({expr}) *buflisted()*
The result is a Number, which is |TRUE| if a buffer called
{expr} exists and is listed (has the 'buflisted' option set).
The {expr} argument is used like with |bufexists()|.
+ Can also be used as a |method|: >
+ let listed = 'somename'->buflisted()
+
bufload({expr}) *bufload()*
Ensure the buffer {expr} is loaded. When the buffer name
refers to an existing file then the file is read. Otherwise
@@ -2848,15 +2858,21 @@ bufload({expr}) *bufload()*
there will be no dialog, the buffer will be loaded anyway.
The {expr} argument is used like with |bufexists()|.
+ Can also be used as a |method|: >
+ eval 'somename'->bufload()
+
bufloaded({expr}) *bufloaded()*
The result is a Number, which is |TRUE| if a buffer called
{expr} exists and is loaded (shown in a window or hidden).
The {expr} argument is used like with |bufexists()|.
+ Can also be used as a |method|: >
+ let loaded = 'somename'->bufloaded()
+
bufname([{expr}]) *bufname()*
The result is the name of a buffer, as it is displayed by the
":ls" command.
-+ If {expr} is omitted the current buffer is used.
+ If {expr} is omitted the current buffer is used.
If {expr} is a Number, that buffer number's name is given.
Number zero is the alternate buffer for the current window.
If {expr} is a String, it is used as a |file-pattern| to match
@@ -2875,6 +2891,9 @@ bufname([{expr}]) *bufname()*
If the {expr} is a String, but you want to use it as a buffer
number, force it to be a Number by adding zero to it: >
:echo bufname("3" + 0)
+< Can also be used as a |method|: >
+ echo bufnr->bufname()
+
< If the buffer doesn't exist, or doesn't have a name, an empty
string is returned. >
bufname("#") alternate buffer name
@@ -2897,6 +2916,9 @@ bufnr([{expr} [, {create}]])
number necessarily exist, because ":bwipeout" may have removed
them. Use bufexists() to test for the existence of a buffer.
+ Can also be used as a |method|: >
+ echo bufref->bufnr()
+
bufwinid({expr}) *bufwinid()*
The result is a Number, which is the |window-ID| of the first
window associated with buffer {expr}. For the use of {expr},
@@ -5624,6 +5646,8 @@ invert({expr}) *invert()*
Bitwise invert. The argument is converted to a number. A
List, Dict or Float argument causes an error. Example: >
:let bits = invert(bits)
+< Can also be used as a |method|: >
+ :let bits = bits->invert()
isdirectory({directory}) *isdirectory()*
The result is a Number, which is |TRUE| when a directory
@@ -6645,7 +6669,8 @@ or({expr}, {expr}) *or()*
to a number. A List, Dict or Float argument causes an error.
Example: >
:let bits = or(bits, 0x80)
-
+< Can also be used as a |method|: >
+ :let bits = bits->or(0x80)
pathshorten({expr}) *pathshorten()*
Shorten directory names in the path {expr} and return the
@@ -9807,6 +9832,8 @@ xor({expr}, {expr}) *xor()*
to a number. A List, Dict or Float argument causes an error.
Example: >
:let bits = xor(bits, 0x80)
+< Can also be used as a |method|: >
+ :let bits = bits->xor(0x80)
<
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua
index 1cac57a8ff..6f8645c806 100644
--- a/src/nvim/eval.lua
+++ b/src/nvim/eval.lua
@@ -24,7 +24,7 @@ return {
abs={args=1, base=1},
acos={args=1, base=1, func="float_op_wrapper", data="&acos"}, -- WJMc
add={args=2, base=1},
- ['and']={args=2},
+ ['and']={args=2, base=1},
api_info={},
append={args=2, base=LAST},
appendbufline={args=3, base=LAST},
@@ -50,16 +50,16 @@ return {
atan2={args=2, base=1},
browse={args=4},
browsedir={args=2},
- bufadd={args=1},
- bufexists={args=1},
- buffer_exists={args=1, func='f_bufexists'}, -- obsolete
+ bufadd={args=1, base=1},
+ bufexists={args=1, base=1},
+ buffer_exists={args=1, base=1, func='f_bufexists'}, -- obsolete
buffer_name={args={0, 1}, func='f_bufname'}, -- obsolete
buffer_number={args={0, 1}, func='f_bufnr'}, -- obsolete
- buflisted={args=1},
- bufload={args=1},
- bufloaded={args=1},
- bufname={args={0, 1}},
- bufnr={args={0, 2}},
+ buflisted={args=1, base=1},
+ bufload={args=1, base=1},
+ bufloaded={args=1, base=1},
+ bufname={args={0, 1}, base=1},
+ bufnr={args={0, 2}, base=1},
bufwinid={args=1},
bufwinnr={args=1},
byte2line={args=1},
@@ -203,7 +203,7 @@ return {
inputsecret={args={1, 2}},
insert={args={2, 3}, base=1},
interrupt={args=0},
- invert={args=1},
+ invert={args=1, base=1},
isdirectory={args=1},
isinf={args=1, base=1},
islocked={args=1},
@@ -254,7 +254,7 @@ return {
msgpackparse={args=1},
nextnonblank={args=1},
nr2char={args={1, 2}},
- ['or']={args=2},
+ ['or']={args=2, base=1},
pathshorten={args=1},
pow={args=2, base=1},
prevnonblank={args=1},
@@ -421,6 +421,6 @@ return {
winwidth={args=1},
wordcount={},
writefile={args={2, 3}},
- xor={args=2},
+ xor={args=2, base=1},
},
}
diff --git a/src/nvim/testdir/test_arglist.vim b/src/nvim/testdir/test_arglist.vim
index a1ef8325ec..01d8f32893 100644
--- a/src/nvim/testdir/test_arglist.vim
+++ b/src/nvim/testdir/test_arglist.vim
@@ -90,8 +90,8 @@ func Test_argadd_empty_curbuf()
call assert_equal('', bufname('%'))
call assert_equal(1, line('$'))
rew
- call assert_notequal(curbuf, bufnr('%'))
- call assert_equal('Xargadd', bufname('%'))
+ call assert_notequal(curbuf, '%'->bufnr())
+ call assert_equal('Xargadd', '%'->bufname())
call assert_equal(2, line('$'))
%argd
diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim
index 2493cc2e27..1c56e936a8 100644
--- a/src/nvim/testdir/test_functions.vim
+++ b/src/nvim/testdir/test_functions.vim
@@ -1414,12 +1414,12 @@ func Test_bufadd_bufload()
let curbuf = bufnr('')
call writefile(['some', 'text'], 'XotherName')
- let buf = bufadd('XotherName')
+ let buf = 'XotherName'->bufadd()
call assert_notequal(0, buf)
- call assert_equal(1, bufexists('XotherName'))
+ eval 'XotherName'->bufexists()->assert_equal(1)
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
- call bufload(buf)
+ eval buf->bufload()
call assert_equal(1, bufloaded(buf))
call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
call assert_equal(curbuf, bufnr(''))
diff --git a/src/nvim/testdir/test_hide.vim b/src/nvim/testdir/test_hide.vim
index 128b8ff945..41b1a4ad7c 100644
--- a/src/nvim/testdir/test_hide.vim
+++ b/src/nvim/testdir/test_hide.vim
@@ -37,7 +37,7 @@ function Test_hide()
" :hide as a command
hide
call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
- call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
+ call assert_equal([1, 1], ['Xf1'->buflisted(), 'Xf1'->bufloaded()])
bwipeout! Xf1
new Xf1
diff --git a/src/nvim/testdir/test_vimscript.vim b/src/nvim/testdir/test_vimscript.vim
index 5922660ef9..d5837e88c9 100644
--- a/src/nvim/testdir/test_vimscript.vim
+++ b/src/nvim/testdir/test_vimscript.vim
@@ -1372,6 +1372,7 @@ func Test_bitwise_functions()
" and
call assert_equal(127, and(127, 127))
call assert_equal(16, and(127, 16))
+ eval 127->and(16)->assert_equal(16)
call assert_equal(0, and(127, 128))
call assert_fails("call and(1.0, 1)", 'E805:')
call assert_fails("call and([], 1)", 'E745:')
@@ -1382,6 +1383,7 @@ func Test_bitwise_functions()
" or
call assert_equal(23, or(16, 7))
call assert_equal(15, or(8, 7))
+ eval 8->or(7)->assert_equal(15)
call assert_equal(123, or(0, 123))
call assert_fails("call or(1.0, 1)", 'E805:')
call assert_fails("call or([], 1)", 'E745:')
@@ -1392,6 +1394,7 @@ func Test_bitwise_functions()
" xor
call assert_equal(0, xor(127, 127))
call assert_equal(111, xor(127, 16))
+ eval 127->xor(16)->assert_equal(111)
call assert_equal(255, xor(127, 128))
call assert_fails("call xor(1.0, 1)", 'E805:')
call assert_fails("call xor([], 1)", 'E745:')
@@ -1401,6 +1404,7 @@ func Test_bitwise_functions()
call assert_fails("call xor(1, {})", 'E728:')
" invert
call assert_equal(65408, and(invert(127), 65535))
+ eval 127->invert()->and(65535)->assert_equal(65408)
call assert_equal(65519, and(invert(16), 65535))
call assert_equal(65407, and(invert(128), 65535))
call assert_fails("call invert(1.0)", 'E805:')