Patch 8.1.1987
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_clientserver.vim,
            src/testdir/test_eval_stuff.vim, src/testdir/test_functions.vim,
            src/testdir/test_reltime.vim, src/testdir/test_rename.vim


*** ../vim-8.1.1986/runtime/doc/eval.txt        2019-09-04 20:05:54.750532206 
+0200
--- runtime/doc/eval.txt        2019-09-04 22:26:08.549604647 +0200
***************
*** 7539,7544 ****
--- 7553,7561 ----
                        range(0)                " []
                        range(2, 0)             " error!
  <
+               Can also be used as a |method|: >
+                       GetExpr()->range()
+ <
                                                        *readdir()*
  readdir({directory} [, {expr}])
                Return a list with file and directory names in {directory}.
***************
*** 7568,7573 ****
--- 7585,7593 ----
                    endfunction
                    echo s:tree(".")
  <
+               Can also be used as a |method|: >
+                       GetDirName()->readdir()
+ <
                                                        *readfile()*
  readfile({fname} [, {type} [, {max}]])
                Read file {fname} and return a |List|, each line of the file
***************
*** 7602,7607 ****
--- 7622,7630 ----
                the result is an empty list.
                Also see |writefile()|.
  
+               Can also be used as a |method|: >
+                       GetFileName()->readfile()
+ 
  reg_executing()                                               
*reg_executing()*
                Returns the single letter name of the register being executed.
                Returns an empty string when no register is being executed.
***************
*** 7623,7628 ****
--- 7646,7655 ----
                and {end}.
                The {start} and {end} arguments must be values returned by
                reltime().
+ 
+               Can also be used as a |method|: >
+                       GetStart()->reltime()
+ <
                {only available when compiled with the |+reltime| feature}
  
  reltimefloat({time})                          *reltimefloat()*
***************
*** 7633,7639 ****
                        let seconds = reltimefloat(reltime(start))
  <             See the note of reltimestr() about overhead.
                Also see |profiling|.
!               {only available when compiled with the |+reltime| feature}
  
  reltimestr({time})                            *reltimestr()*
                Return a String that represents the time value of {time}.
--- 7660,7670 ----
                        let seconds = reltimefloat(reltime(start))
  <             See the note of reltimestr() about overhead.
                Also see |profiling|.
! 
!               Can also be used as a |method|: >
!                       reltime(start)->reltimefloat()
! 
! <             {only available when compiled with the |+reltime| feature}
  
  reltimestr({time})                            *reltimestr()*
                Return a String that represents the time value of {time}.
***************
*** 7648,7654 ****
                can use split() to remove it. >
                        echo split(reltimestr(reltime(start)))[0]
  <             Also see |profiling|.
!               {only available when compiled with the |+reltime| feature}
  
                                                        *remote_expr()* *E449*
  remote_expr({server}, {string} [, {idvar} [, {timeout}]])
--- 7679,7689 ----
                can use split() to remove it. >
                        echo split(reltimestr(reltime(start)))[0]
  <             Also see |profiling|.
! 
!               Can also be used as a |method|: >
!                       reltime(start)->reltimestr()
! 
! <             {only available when compiled with the |+reltime| feature}
  
                                                        *remote_expr()* *E449*
  remote_expr({server}, {string} [, {idvar} [, {timeout}]])
***************
*** 7677,7682 ****
--- 7712,7719 ----
                        :echo remote_expr("gvim", "2+2")
                        :echo remote_expr("gvim1", "b:current_syntax")
  <
+               Can also be used as a |method|: >
+                       ServerName()->remote_expr(expr)
  
  remote_foreground({server})                           *remote_foreground()*
                Move the Vim server with the name {server} to the foreground.
***************
*** 7688,7694 ****
                Note: This does not restore the window if it was minimized,
                like foreground() does.
                This function is not available in the |sandbox|.
!               {only in the Win32, Athena, Motif and GTK GUI versions and the
                Win32 console version}
  
  
--- 7725,7735 ----
                Note: This does not restore the window if it was minimized,
                like foreground() does.
                This function is not available in the |sandbox|.
! 
!               Can also be used as a |method|: >
!                       ServerName()->remote_foreground()
! 
! <             {only in the Win32, Athena, Motif and GTK GUI versions and the
                Win32 console version}
  
  
***************
*** 7706,7711 ****
--- 7747,7755 ----
                        :let repl = ""
                        :echo "PEEK: ".remote_peek(id, "repl").": ".repl
  
+ <             Can also be used as a |method|: >
+                       ServerId()->remote_peek()
+ 
  remote_read({serverid}, [{timeout}])                  *remote_read()*
                Return the oldest available reply from {serverid} and consume
                it.  Unless a {timeout} in seconds is given, it blocks until a
***************
*** 7715,7720 ****
--- 7759,7767 ----
                {only available when compiled with the |+clientserver| feature}
                Example: >
                        :echo remote_read(id)
+ 
+ <             Can also be used as a |method|: >
+                       ServerId()->remote_read()
  <
                                                        *remote_send()* *E241*
  remote_send({server}, {string} [, {idvar}])
***************
*** 7739,7749 ****
                :echo remote_send("gvim", ":sleep 10 | echo ".
                 \ 'server2client(expand("<client>"), "HELLO")<CR>')
  <
                                        *remote_startserver()* *E941* *E942*
  remote_startserver({name})
                Become the server {name}.  This fails if already running as a
                server, when |v:servername| is not empty.
!               {only available when compiled with the |+clientserver| feature}
  
  remove({list}, {idx} [, {end}])                               *remove()*
                Without {end}: Remove the item at {idx} from |List| {list} and
--- 7786,7803 ----
                :echo remote_send("gvim", ":sleep 10 | echo ".
                 \ 'server2client(expand("<client>"), "HELLO")<CR>')
  <
+               Can also be used as a |method|: >
+                       ServerName()->remote_send(keys)
+ <
                                        *remote_startserver()* *E941* *E942*
  remote_startserver({name})
                Become the server {name}.  This fails if already running as a
                server, when |v:servername| is not empty.
! 
!               Can also be used as a |method|: >
!                       ServerName()->remote_startserver()
! 
! <             {only available when compiled with the |+clientserver| feature}
  
  remove({list}, {idx} [, {end}])                               *remove()*
                Without {end}: Remove the item at {idx} from |List| {list} and
***************
*** 7774,7780 ****
                        :call remove(mylist, 0, 9)
  
  remove({dict}, {key})
!               Remove the entry from {dict} with key {key}.  Example: >
                        :echo "removed " . remove(dict, "one")
  <             If there is no {key} in {dict} this is an error.
  
--- 7828,7835 ----
                        :call remove(mylist, 0, 9)
  
  remove({dict}, {key})
!               Remove the entry from {dict} with key {key} and return it.
!               Example: >
                        :echo "removed " . remove(dict, "one")
  <             If there is no {key} in {dict} this is an error.
  
***************
*** 7786,7791 ****
--- 7841,7849 ----
                NOTE: If {to} exists it is overwritten without warning.
                This function is not available in the |sandbox|.
  
+               Can also be used as a |method|: >
+                       GetOldName()->rename(newname)
+ 
  repeat({expr}, {count})                                       *repeat()*
                Repeat {expr} {count} times and return the concatenated
                result.  Example: >
***************
*** 7815,7820 ****
--- 7873,7880 ----
                current directory (provided the result is still a relative
                path name) and also keeps a trailing path separator.
  
+               Can also be used as a |method|: >
+                       GetName()->resolve()
  
  reverse({object})                                     *reverse()*
                Reverse the order of items in {object} in-place.
***************
*** 7852,7858 ****
                Hashes are represented as Vim |Dictionary| type.
                Other objects are represented as strings resulted from their
                "Object#to_s" method.
!               {only available when compiled with the |+ruby| feature}
  
  screenattr({row}, {col})                                      *screenattr()*
                Like |screenchar()|, but return the attribute.  This is a rather
--- 7912,7922 ----
                Hashes are represented as Vim |Dictionary| type.
                Other objects are represented as strings resulted from their
                "Object#to_s" method.
! 
!               Can also be used as a |method|: >
!                       GetRubyExpr()->rubyeval()
! 
! <             {only available when compiled with the |+ruby| feature}
  
  screenattr({row}, {col})                                      *screenattr()*
                Like |screenchar()|, but return the attribute.  This is a rather
*** ../vim-8.1.1986/src/evalfunc.c      2019-09-04 21:56:48.979806628 +0200
--- src/evalfunc.c      2019-09-04 22:25:44.357689680 +0200
***************
*** 684,715 ****
  #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
      {"pyxeval",               1, 1, FEARG_1,    f_pyxeval},
  #endif
!     {"range",         1, 3, 0,          f_range},
!     {"readdir",               1, 2, 0,          f_readdir},
!     {"readfile",      1, 3, 0,          f_readfile},
      {"reg_executing", 0, 0, 0,          f_reg_executing},
      {"reg_recording", 0, 0, 0,          f_reg_recording},
!     {"reltime",               0, 2, 0,          f_reltime},
  #ifdef FEAT_FLOAT
!     {"reltimefloat",  1, 1, 0,          f_reltimefloat},
  #endif
!     {"reltimestr",    1, 1, 0,          f_reltimestr},
!     {"remote_expr",   2, 4, 0,          f_remote_expr},
!     {"remote_foreground", 1, 1, 0,      f_remote_foreground},
!     {"remote_peek",   1, 2, 0,          f_remote_peek},
!     {"remote_read",   1, 2, 0,          f_remote_read},
!     {"remote_send",   2, 3, 0,          f_remote_send},
!     {"remote_startserver", 1, 1, 0,     f_remote_startserver},
      {"remove",                2, 3, FEARG_1,    f_remove},
!     {"rename",                2, 2, 0,          f_rename},
      {"repeat",                2, 2, FEARG_1,    f_repeat},
!     {"resolve",               1, 1, 0,          f_resolve},
      {"reverse",               1, 1, FEARG_1,    f_reverse},
  #ifdef FEAT_FLOAT
      {"round",         1, 1, FEARG_1,    f_round},
  #endif
  #ifdef FEAT_RUBY
!     {"rubyeval",      1, 1, 0,          f_rubyeval},
  #endif
      {"screenattr",    2, 2, 0,          f_screenattr},
      {"screenchar",    2, 2, 0,          f_screenchar},
--- 684,715 ----
  #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3)
      {"pyxeval",               1, 1, FEARG_1,    f_pyxeval},
  #endif
!     {"range",         1, 3, FEARG_1,    f_range},
!     {"readdir",               1, 2, FEARG_1,    f_readdir},
!     {"readfile",      1, 3, FEARG_1,    f_readfile},
      {"reg_executing", 0, 0, 0,          f_reg_executing},
      {"reg_recording", 0, 0, 0,          f_reg_recording},
!     {"reltime",               0, 2, FEARG_1,    f_reltime},
  #ifdef FEAT_FLOAT
!     {"reltimefloat",  1, 1, FEARG_1,    f_reltimefloat},
  #endif
!     {"reltimestr",    1, 1, FEARG_1,    f_reltimestr},
!     {"remote_expr",   2, 4, FEARG_1,    f_remote_expr},
!     {"remote_foreground", 1, 1, FEARG_1,  f_remote_foreground},
!     {"remote_peek",   1, 2, FEARG_1,    f_remote_peek},
!     {"remote_read",   1, 2, FEARG_1,    f_remote_read},
!     {"remote_send",   2, 3, FEARG_1,    f_remote_send},
!     {"remote_startserver", 1, 1, FEARG_1,  f_remote_startserver},
      {"remove",                2, 3, FEARG_1,    f_remove},
!     {"rename",                2, 2, FEARG_1,    f_rename},
      {"repeat",                2, 2, FEARG_1,    f_repeat},
!     {"resolve",               1, 1, FEARG_1,    f_resolve},
      {"reverse",               1, 1, FEARG_1,    f_reverse},
  #ifdef FEAT_FLOAT
      {"round",         1, 1, FEARG_1,    f_round},
  #endif
  #ifdef FEAT_RUBY
!     {"rubyeval",      1, 1, FEARG_1,    f_rubyeval},
  #endif
      {"screenattr",    2, 2, 0,          f_screenattr},
      {"screenchar",    2, 2, 0,          f_screenchar},
*** ../vim-8.1.1986/src/testdir/test_clientserver.vim   2019-08-07 
23:07:03.960858821 +0200
--- src/testdir/test_clientserver.vim   2019-09-04 22:21:50.566512698 +0200
***************
*** 34,40 ****
    " When using valgrind it takes much longer.
    call WaitForAssert({-> assert_match(name, serverlist())})
  
!   call remote_foreground(name)
  
    call remote_send(name, ":let testvar = 'yes'\<CR>")
    call WaitFor('remote_expr("' . name . '", "exists(\"testvar\") ? testvar : 
\"\"", "", 1) == "yes"')
--- 34,40 ----
    " When using valgrind it takes much longer.
    call WaitForAssert({-> assert_match(name, serverlist())})
  
!   eval name->remote_foreground()
  
    call remote_send(name, ":let testvar = 'yes'\<CR>")
    call WaitFor('remote_expr("' . name . '", "exists(\"testvar\") ? testvar : 
\"\"", "", 1) == "yes"')
***************
*** 53,59 ****
      endif
      " Wait for the server to be up and answering requests.
      sleep 100m
!     call WaitForAssert({-> assert_true(remote_expr(name, "v:version", "", 1) 
!= "")})
  
      call remote_send(name, ":let testvar = 'maybe'\<CR>")
      call WaitForAssert({-> assert_equal('maybe', remote_expr(name, "testvar", 
"", 2))})
--- 53,59 ----
      endif
      " Wait for the server to be up and answering requests.
      sleep 100m
!     call WaitForAssert({-> assert_true(name->remote_expr("v:version", "", 1) 
!= "")})
  
      call remote_send(name, ":let testvar = 'maybe'\<CR>")
      call WaitForAssert({-> assert_equal('maybe', remote_expr(name, "testvar", 
"", 2))})
***************
*** 63,69 ****
  
    " Expression evaluated locally.
    if v:servername == ''
!     call remote_startserver('MYSELF')
      " May get MYSELF1 when running the test again.
      call assert_match('MYSELF', v:servername)
    endif
--- 63,69 ----
  
    " Expression evaluated locally.
    if v:servername == ''
!     eval 'MYSELF'->remote_startserver()
      " May get MYSELF1 when running the test again.
      call assert_match('MYSELF', v:servername)
    endif
***************
*** 71,81 ****
    call assert_equal('myself', remote_expr(v:servername, 'testvar'))
  
    call remote_send(name, ":call server2client(expand('<client>'), 'got 
it')\<CR>", 'g:myserverid')
!   call assert_equal('got it', remote_read(g:myserverid, 2))
  
    call remote_send(name, ":call server2client(expand('<client>'), 
'another')\<CR>", 'g:myserverid')
    let peek_result = 'nothing'
!   let r = remote_peek(g:myserverid, 'peek_result')
    " unpredictable whether the result is already available.
    if r > 0
      call assert_equal('another', peek_result)
--- 71,81 ----
    call assert_equal('myself', remote_expr(v:servername, 'testvar'))
  
    call remote_send(name, ":call server2client(expand('<client>'), 'got 
it')\<CR>", 'g:myserverid')
!   call assert_equal('got it', g:myserverid->remote_read(2))
  
    call remote_send(name, ":call server2client(expand('<client>'), 
'another')\<CR>", 'g:myserverid')
    let peek_result = 'nothing'
!   let r = g:myserverid->remote_peek('peek_result')
    " unpredictable whether the result is already available.
    if r > 0
      call assert_equal('another', peek_result)
***************
*** 89,95 ****
    call assert_equal('another', g:peek_result)
    call assert_equal('another', remote_read(g:myserverid, 2))
  
!   call remote_send(name, ":qa!\<CR>")
    try
      call WaitForAssert({-> assert_equal("dead", job_status(job))})
    finally
--- 89,95 ----
    call assert_equal('another', g:peek_result)
    call assert_equal('another', remote_read(g:myserverid, 2))
  
!   eval name->remote_send(":qa!\<CR>")
    try
      call WaitForAssert({-> assert_equal("dead", job_status(job))})
    finally
*** ../vim-8.1.1986/src/testdir/test_eval_stuff.vim     2019-07-20 
21:11:09.367858652 +0200
--- src/testdir/test_eval_stuff.vim     2019-09-04 22:12:13.112563203 +0200
***************
*** 75,81 ****
    call setline(1, ['one', 'two', 'three'])
    setlocal ff=dos
    write XReadfile
!   let lines = readfile('XReadfile')
    call assert_equal(['one', 'two', 'three'], lines)
    let lines = readfile('XReadfile', '', 2)
    call assert_equal(['one', 'two'], lines)
--- 75,81 ----
    call setline(1, ['one', 'two', 'three'])
    setlocal ff=dos
    write XReadfile
!   let lines = 'XReadfile'->readfile()
    call assert_equal(['one', 'two', 'three'], lines)
    let lines = readfile('XReadfile', '', 2)
    call assert_equal(['one', 'two'], lines)
*** ../vim-8.1.1986/src/testdir/test_functions.vim      2019-09-04 
20:05:54.750532206 +0200
--- src/testdir/test_functions.vim      2019-09-04 22:25:18.817779472 +0200
***************
*** 253,259 ****
    call delete('Xlink')
  
    silent !ln -s -f Xlink2/ Xlink1
!   call assert_equal('Xlink2', resolve('Xlink1'))
    call assert_equal('Xlink2/', resolve('Xlink1/'))
    call delete('Xlink1')
  
--- 253,259 ----
    call delete('Xlink')
  
    silent !ln -s -f Xlink2/ Xlink1
!   call assert_equal('Xlink2', 'Xlink1'->resolve())
    call assert_equal('Xlink2/', resolve('Xlink1/'))
    call delete('Xlink1')
  
***************
*** 1413,1419 ****
    " is invalid in that buffer.
    call writefile(['just one line'], 'Xfuncrange2')
    new
!   call setline(1, range(10))
    write Xfuncrange1
    call assert_fails('5,8call EditAnotherFile()', 'E16:')
  
--- 1413,1419 ----
    " is invalid in that buffer.
    call writefile(['just one line'], 'Xfuncrange2')
    new
!   call setline(1, 10->range())
    write Xfuncrange1
    call assert_fails('5,8call EditAnotherFile()', 'E16:')
  
***************
*** 1544,1550 ****
    call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files))
  
    " Only results containing "f"
!   let files = readdir('Xdir', { x -> stridx(x, 'f') !=- 1 })
    call assert_equal(['foo.txt'], sort(files))
  
    " Only .txt files
--- 1544,1550 ----
    call assert_equal(['bar.txt', 'dir', 'foo.txt'], sort(files))
  
    " Only results containing "f"
!   let files = 'Xdir'->readdir({ x -> stridx(x, 'f') !=- 1 })
    call assert_equal(['foo.txt'], sort(files))
  
    " Only .txt files
*** ../vim-8.1.1986/src/testdir/test_reltime.vim        2019-06-15 
17:57:43.972724036 +0200
--- src/testdir/test_reltime.vim        2019-09-04 22:15:31.927853054 +0200
***************
*** 8,18 ****
    let now = reltime()
    sleep 10m
    let later = reltime()
!   let elapsed = reltime(now)
    call assert_true(reltimestr(elapsed) =~ '0\.0')
!   call assert_true(reltimestr(elapsed) != '0.0')
    call assert_true(reltimefloat(elapsed) < 0.1)
!   call assert_true(reltimefloat(elapsed) > 0.0)
  
    let same = reltime(now, now)
    call assert_equal('0.000', split(reltimestr(same))[0][:4])
--- 8,18 ----
    let now = reltime()
    sleep 10m
    let later = reltime()
!   let elapsed = now->reltime()
    call assert_true(reltimestr(elapsed) =~ '0\.0')
!   call assert_true(elapsed->reltimestr() != '0.0')
    call assert_true(reltimefloat(elapsed) < 0.1)
!   call assert_true(elapsed->reltimefloat() > 0.0)
  
    let same = reltime(now, now)
    call assert_equal('0.000', split(reltimestr(same))[0][:4])
*** ../vim-8.1.1986/src/testdir/test_rename.vim 2019-03-02 06:41:34.345330494 
+0100
--- src/testdir/test_rename.vim 2019-09-04 22:23:53.406079954 +0200
***************
*** 25,31 ****
    set fileignorecase
    call writefile(['foo'], 'Xrename')
  
!   call assert_equal(0, rename('Xrename', 'XRENAME'))
  
    call assert_equal(['foo'], readfile('XRENAME'))
  
--- 25,31 ----
    set fileignorecase
    call writefile(['foo'], 'Xrename')
  
!   call assert_equal(0, 'Xrename'->rename('XRENAME'))
  
    call assert_equal(['foo'], readfile('XRENAME'))
  
*** ../vim-8.1.1986/src/version.c       2019-09-04 21:56:48.979806628 +0200
--- src/version.c       2019-09-04 22:27:18.513358829 +0200
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     1987,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
188. You purchase a laptop so you can surf while sitting on the can.

 /// 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/201909042029.x84KThZx018748%40masaka.moolenaar.net.

Raspunde prin e-mail lui