Patch 8.1.1888
Problem: More functions can be used as methods.
Solution: Make various functions usable as a method.
Files: runtime/doc/eval.txt, src/evalfunc.c,
src/testdir/test_vimscript.vim, src/testdir/test_balloon_gui.vim,
src/testdir/test_popup.vim, src/testdir/test_functions.vim,
src/testdir/test_hide.vim, src/testdir/test_arglist.vim
*** ../vim-8.1.1887/runtime/doc/eval.txt 2019-08-17 21:36:11.843341321
+0200
--- runtime/doc/eval.txt 2019-08-18 22:56:29.123820670 +0200
***************
*** 2933,2938 ****
--- 2937,2944 ----
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)
append({lnum}, {text}) *append()*
***************
*** 3084,3089 ****
--- 3090,3097 ----
func BalloonCallback(result)
call balloon_show(a:result)
endfunc
+ < Can also be used as a |method|: >
+ GetText()->balloon_show()
<
The intended use is that fetching the content of the balloon
is initiated from 'balloonexpr'. It will invoke an
***************
*** 3101,3107 ****
splits are made for the current window size and optimize to
show debugger output.
Returns a |List| with the split lines.
! {only available when compiled with the |+balloon_eval_term|
feature}
*browse()*
--- 3109,3118 ----
splits are made for the current window size and optimize to
show debugger output.
Returns a |List| with the split lines.
! Can also be used as a |method|: >
! GetText()->balloon_split()->balloon_show()
!
! < {only available when compiled with the |+balloon_eval_term|
feature}
*browse()*
***************
*** 3140,3145 ****
--- 3151,3158 ----
let bufnr = bufadd('someName')
call bufload(bufnr)
call setbufline(bufnr, 1, ['some', 'text'])
+ < 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
***************
*** 3162,3175 ****
for MS-Windows 8.3 names in the form "c:\DOCUME~1"
Use "bufexists(0)" to test for the existence of an alternate
file name.
! *buffer_exists()*
! Obsolete name: buffer_exists().
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()|.
bufload({expr}) *bufload()*
Ensure the buffer {expr} is loaded. When the buffer name
refers to an existing file then the file is read. Otherwise
--- 3175,3194 ----
for MS-Windows 8.3 names in the form "c:\DOCUME~1"
Use "bufexists(0)" to test for the existence of an alternate
file name.
!
! Can also be used as a |method|: >
! let exists = 'somename'->bufexists()
! <
! Obsolete name: buffer_exists(). *buffer_exists()*
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
***************
*** 3179,3189 ****
--- 3198,3214 ----
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.
***************
*** 3205,3210 ****
--- 3230,3238 ----
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
***************
*** 3228,3235 ****
of existing buffers. Note that not all buffers with a smaller
number necessarily exist, because ":bwipeout" may have removed
them. Use bufexists() to test for the existence of a buffer.
! *buffer_number()*
! Obsolete name: buffer_number().
*last_buffer_nr()*
Obsolete name for bufnr("$"): last_buffer_nr().
--- 3256,3266 ----
of existing buffers. Note that not all buffers with a smaller
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()
! <
! Obsolete name: buffer_number(). *buffer_number()*
*last_buffer_nr()*
Obsolete name for bufnr("$"): last_buffer_nr().
***************
*** 5821,5826 ****
--- 5861,5868 ----
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
***************
*** 6749,6759 ****
--- 6791,6804 ----
let str = join(map(list, {_, val -> nr2char(val)}), '')
< Result: "ABC"
+
or({expr}, {expr}) *or()*
Bitwise OR on the two arguments. The arguments are converted
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()*
***************
*** 9419,9424 ****
--- 9465,9471 ----
autocommands and not actually show syntax highlighting.
*E994*
Not all commands are allowed in popup windows.
+ When window {id} does not exist then no error is given.
win_findbuf({bufnr}) *win_findbuf()*
Returns a list with |window-ID|s for windows that contain
***************
*** 9674,9679 ****
--- 9721,9728 ----
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)
<
***************
*** 10258,10263 ****
--- 10307,10317 ----
allow for method chaining, e.g.: >
eval GetList()->Filter()->append('$')
+ A function can also be called as part of evaluating an expression or when it
+ is used as a method: >
+ let x = GetList()
+ let y = GetList()->Filter()
+
AUTOMATICALLY LOADING FUNCTIONS ~
*autoload-functions*
*** ../vim-8.1.1887/src/evalfunc.c 2019-08-18 22:25:54.661448011 +0200
--- src/evalfunc.c 2019-08-18 22:56:39.419754365 +0200
***************
*** 419,425 ****
{"acos", 1, 1, FEARG_1, f_acos}, // WJMc
#endif
{"add", 2, 2, FEARG_1, f_add},
! {"and", 2, 2, 0, f_and},
{"append", 2, 2, FEARG_LAST, f_append},
{"appendbufline", 3, 3, FEARG_LAST, f_appendbufline},
{"argc", 0, 1, 0, f_argc},
--- 419,425 ----
{"acos", 1, 1, FEARG_1, f_acos}, // WJMc
#endif
{"add", 2, 2, FEARG_1, f_add},
! {"and", 2, 2, FEARG_1, f_and},
{"append", 2, 2, FEARG_LAST, f_append},
{"appendbufline", 3, 3, FEARG_LAST, f_appendbufline},
{"argc", 0, 1, 0, f_argc},
***************
*** 447,469 ****
#endif
#ifdef FEAT_BEVAL
{"balloon_gettext", 0, 0, 0, f_balloon_gettext},
! {"balloon_show", 1, 1, 0, f_balloon_show},
# if defined(FEAT_BEVAL_TERM)
! {"balloon_split", 1, 1, 0, f_balloon_split},
# endif
#endif
{"browse", 4, 4, 0, f_browse},
{"browsedir", 2, 2, 0, f_browsedir},
! {"bufadd", 1, 1, 0, f_bufadd},
! {"bufexists", 1, 1, 0, f_bufexists},
! {"buffer_exists", 1, 1, 0, f_bufexists}, // obsolete
{"buffer_name", 1, 1, 0, f_bufname}, // obsolete
{"buffer_number", 1, 1, 0, f_bufnr}, // obsolete
! {"buflisted", 1, 1, 0, f_buflisted},
! {"bufload", 1, 1, 0, f_bufload},
! {"bufloaded", 1, 1, 0, f_bufloaded},
! {"bufname", 1, 1, 0, f_bufname},
! {"bufnr", 1, 2, 0, f_bufnr},
{"bufwinid", 1, 1, 0, f_bufwinid},
{"bufwinnr", 1, 1, 0, f_bufwinnr},
{"byte2line", 1, 1, 0, f_byte2line},
--- 447,469 ----
#endif
#ifdef FEAT_BEVAL
{"balloon_gettext", 0, 0, 0, f_balloon_gettext},
! {"balloon_show", 1, 1, FEARG_1, f_balloon_show},
# if defined(FEAT_BEVAL_TERM)
! {"balloon_split", 1, 1, FEARG_1, f_balloon_split},
# endif
#endif
{"browse", 4, 4, 0, f_browse},
{"browsedir", 2, 2, 0, f_browsedir},
! {"bufadd", 1, 1, FEARG_1, f_bufadd},
! {"bufexists", 1, 1, FEARG_1, f_bufexists},
! {"buffer_exists", 1, 1, FEARG_1, f_bufexists}, // obsolete
{"buffer_name", 1, 1, 0, f_bufname}, // obsolete
{"buffer_number", 1, 1, 0, f_bufnr}, // obsolete
! {"buflisted", 1, 1, FEARG_1, f_buflisted},
! {"bufload", 1, 1, FEARG_1, f_bufload},
! {"bufloaded", 1, 1, FEARG_1, f_bufloaded},
! {"bufname", 1, 1, FEARG_1, f_bufname},
! {"bufnr", 1, 2, FEARG_1, f_bufnr},
{"bufwinid", 1, 1, 0, f_bufwinid},
{"bufwinnr", 1, 1, 0, f_bufwinnr},
{"byte2line", 1, 1, 0, f_byte2line},
***************
*** 626,632 ****
{"inputsave", 0, 0, 0, f_inputsave},
{"inputsecret", 1, 2, 0, f_inputsecret},
{"insert", 2, 3, FEARG_1, f_insert},
! {"invert", 1, 1, 0, f_invert},
{"isdirectory", 1, 1, 0, f_isdirectory},
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
{"isinf", 1, 1, FEARG_1, f_isinf},
--- 626,632 ----
{"inputsave", 0, 0, 0, f_inputsave},
{"inputsecret", 1, 2, 0, f_inputsecret},
{"insert", 2, 3, FEARG_1, f_insert},
! {"invert", 1, 1, FEARG_1, f_invert},
{"isdirectory", 1, 1, 0, f_isdirectory},
#if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
{"isinf", 1, 1, FEARG_1, f_isinf},
***************
*** 690,696 ****
#endif
{"nextnonblank", 1, 1, 0, f_nextnonblank},
{"nr2char", 1, 2, 0, f_nr2char},
! {"or", 2, 2, 0, f_or},
{"pathshorten", 1, 1, 0, f_pathshorten},
#ifdef FEAT_PERL
{"perleval", 1, 1, 0, f_perleval},
--- 690,696 ----
#endif
{"nextnonblank", 1, 1, 0, f_nextnonblank},
{"nr2char", 1, 2, 0, f_nr2char},
! {"or", 2, 2, FEARG_1, f_or},
{"pathshorten", 1, 1, 0, f_pathshorten},
#ifdef FEAT_PERL
{"perleval", 1, 1, 0, f_perleval},
***************
*** 976,982 ****
{"winwidth", 1, 1, 0, f_winwidth},
{"wordcount", 0, 0, 0, f_wordcount},
{"writefile", 2, 3, 0, f_writefile},
! {"xor", 2, 2, 0, f_xor},
};
/*
--- 976,982 ----
{"winwidth", 1, 1, 0, f_winwidth},
{"wordcount", 0, 0, 0, f_wordcount},
{"writefile", 2, 3, 0, f_writefile},
! {"xor", 2, 2, FEARG_1, f_xor},
};
/*
*** ../vim-8.1.1887/src/testdir/test_vimscript.vim 2019-08-14
21:12:00.977833219 +0200
--- src/testdir/test_vimscript.vim 2019-08-18 22:39:35.595174517 +0200
***************
*** 1330,1335 ****
--- 1330,1336 ----
" 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:')
***************
*** 1340,1345 ****
--- 1341,1347 ----
" 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:')
***************
*** 1350,1355 ****
--- 1352,1358 ----
" 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:')
***************
*** 1359,1364 ****
--- 1362,1368 ----
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:')
*** ../vim-8.1.1887/src/testdir/test_balloon_gui.vim 2019-08-08
21:52:35.518263963 +0200
--- src/testdir/test_balloon_gui.vim 2019-08-18 22:42:47.245575162 +0200
***************
*** 12,18 ****
call balloon_show('')
let msg = 'that that'
! call balloon_show(msg)
call assert_equal(msg, balloon_gettext())
sleep 10m
call balloon_show('')
--- 12,18 ----
call balloon_show('')
let msg = 'that that'
! eval msg->balloon_show()
call assert_equal(msg, balloon_gettext())
sleep 10m
call balloon_show('')
*** ../vim-8.1.1887/src/testdir/test_popup.vim 2019-08-17 19:36:01.206907191
+0200
--- src/testdir/test_popup.vim 2019-08-18 22:45:56.920126750 +0200
***************
*** 758,766 ****
endfunc
func Test_balloon_split()
! if !exists('*balloon_split')
! return
! endif
call assert_equal([
\ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"',
\ ], balloon_split(
--- 758,765 ----
endfunc
func Test_balloon_split()
! CheckFunction balloon_split
!
call assert_equal([
\ 'tempname: 0x555555e380a0 "/home/mool/.viminfz.tmp"',
\ ], balloon_split(
***************
*** 771,783 ****
\ ], balloon_split(
\ 'one two three four one two three four one two three four'))
! call assert_equal([
! \ 'struct = {',
! \ ' one = 1,',
! \ ' two = 2,',
! \ ' three = 3}',
! \ ], balloon_split(
! \ 'struct = {one = 1, two = 2, three = 3}'))
call assert_equal([
\ 'struct = {',
--- 770,783 ----
\ ], balloon_split(
\ 'one two three four one two three four one two three four'))
! eval 'struct = {one = 1, two = 2, three = 3}'
! \ ->balloon_split()
! \ ->assert_equal([
! \ 'struct = {',
! \ ' one = 1,',
! \ ' two = 2,',
! \ ' three = 3}',
! \ ])
call assert_equal([
\ 'struct = {',
*** ../vim-8.1.1887/src/testdir/test_functions.vim 2019-08-07
23:07:03.960858821 +0200
--- src/testdir/test_functions.vim 2019-08-18 22:53:53.328834531 +0200
***************
*** 1537,1548 ****
let curbuf = bufnr('')
call writefile(['some', 'text'], 'XotherName')
! let buf = bufadd('XotherName')
call assert_notequal(0, buf)
! call assert_equal(1, bufexists('XotherName'))
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
! call bufload(buf)
call assert_equal(1, bufloaded(buf))
call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
call assert_equal(curbuf, bufnr(''))
--- 1537,1548 ----
let curbuf = bufnr('')
call writefile(['some', 'text'], 'XotherName')
! let buf = 'XotherName'->bufadd()
call assert_notequal(0, buf)
! eval 'XotherName'->bufexists()->assert_equal(1)
call assert_equal(0, getbufvar(buf, '&buflisted'))
call assert_equal(0, bufloaded(buf))
! eval buf->bufload()
call assert_equal(1, bufloaded(buf))
call assert_equal(['some', 'text'], getbufline(buf, 1, '$'))
call assert_equal(curbuf, bufnr(''))
*** ../vim-8.1.1887/src/testdir/test_hide.vim 2016-11-15 20:38:20.000000000
+0100
--- src/testdir/test_hide.vim 2019-08-18 22:52:24.637422110 +0200
***************
*** 37,43 ****
" :hide as a command
hide
call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
! call assert_equal([1, 1], [buflisted('Xf1'), bufloaded('Xf1')])
bwipeout! Xf1
new Xf1
--- 37,43 ----
" :hide as a command
hide
call assert_equal([orig_bname, orig_winnr], [bufname(''), winnr('$')])
! call assert_equal([1, 1], ['Xf1'->buflisted(), 'Xf1'->bufloaded()])
bwipeout! Xf1
new Xf1
*** ../vim-8.1.1887/src/testdir/test_arglist.vim 2019-08-03
13:50:04.562299913 +0200
--- src/testdir/test_arglist.vim 2019-08-18 22:56:49.319690679 +0200
***************
*** 90,97 ****
call assert_equal('', bufname('%'))
call assert_equal(1, line('$'))
rew
! call assert_notequal(curbuf, bufnr('%'))
! call assert_equal('Xargadd', bufname('%'))
call assert_equal(2, line('$'))
call delete('Xargadd')
--- 90,97 ----
call assert_equal('', bufname('%'))
call assert_equal(1, line('$'))
rew
! call assert_notequal(curbuf, '%'->bufnr())
! call assert_equal('Xargadd', '%'->bufname())
call assert_equal(2, line('$'))
call delete('Xargadd')
*** ../vim-8.1.1887/src/version.c 2019-08-18 22:25:54.669447972 +0200
--- src/version.c 2019-08-18 22:57:12.483541932 +0200
***************
*** 767,768 ****
--- 767,770 ----
{ /* Add new patch number below this line */
+ /**/
+ 1888,
/**/
--
>From "know your smileys":
~#:-( I just washed my hair, and I can't do nuthin' with it.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/201908182102.x7IL2NWS003083%40masaka.moolenaar.net.