Patch 8.1.1993
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_bufline.vim, src/testdir/test_charsearch.vim,
            src/testdir/test_clientserver.vim, src/testdir/test_cmdline.vim,
            src/testdir/test_cursor_func.vim, src/testdir/test_diffmode.vim,
            src/testdir/test_environ.vim, src/testdir/test_functions.vim,
            src/testdir/test_matchadd_conceal_utf8.vim,
            src/testdir/test_popupwin.vim, src/testdir/test_search.vim,
            src/testdir/test_searchpos.vim, src/testdir/test_utf8.vim


*** ../vim-8.1.1992/runtime/doc/eval.txt        2019-09-04 22:28:53.057026902 
+0200
--- runtime/doc/eval.txt        2019-09-06 21:27:39.235813263 +0200
***************
*** 5823,5829 ****
  
                Can also be used as a |method|, the base is used for the
                second argument: >
!                       GetPattern()->histadd('search')
  
  histdel({history} [, {item}])                         *histdel()*
                Clear {history}, i.e. delete all its entries.  See |hist-names|
--- 5833,5839 ----
  
                Can also be used as a |method|, the base is used for the
                second argument: >
!                       GetHistory()->histadd('search')
  
  histdel({history} [, {item}])                         *histdel()*
                Clear {history}, i.e. delete all its entries.  See |hist-names|
***************
*** 7909,7914 ****
--- 7923,7931 ----
                arbitrary number that can only be used to compare to the
                attribute at other positions.
  
+               Can also be used as a |method|: >
+                       GetRow()->screenattr(col)
+ 
  screenchar({row}, {col})                                      *screenchar()*
                The result is a Number, which is the character at position
                [row, col] on the screen.  This works for every possible
***************
*** 7919,7924 ****
--- 7936,7944 ----
                This is mainly to be used for testing.
                Returns -1 when row or col is out of range.
  
+               Can also be used as a |method|: >
+                       GetRow()->screenchar(col)
+ 
  screenchars({row}, {col})                                     *screenchars()*
                The result is a List of Numbers.  The first number is the same
                as what |screenchar()| returns.  Further numbers are
***************
*** 7926,7931 ****
--- 7946,7954 ----
                This is mainly to be used for testing.
                Returns an empty List when row or col is out of range.
  
+               Can also be used as a |method|: >
+                       GetRow()->screenchars(col)
+ 
  screencol()                                                   *screencol()*
                The result is a Number, which is the current screen column of
                the cursor. The leftmost column has number 1.
***************
*** 7956,7961 ****
--- 7979,7987 ----
                a Tab it would be the same as "endcol", while for a double
                width character it would be the same as "col".
  
+               Can also be used as a |method|: >
+                       GetWinid()->screenpos(lnum, col)
+ 
  screenrow()                                                   *screenrow()*
                The result is a Number, which is the current screen row of the
                cursor.  The top line has number one.
***************
*** 7972,7977 ****
--- 7998,8006 ----
                This is mainly to be used for testing.
                Returns an empty String when row or col is out of range.
  
+               Can also be used as a |method|: >
+                       GetRow()->screenstring(col)
+ 
  search({pattern} [, {flags} [, {stopline} [, {timeout}]]])    *search()*
                Search for regexp pattern {pattern}.  The search starts at the
                cursor position (you can use |cursor()| to set it).
***************
*** 8058,8063 ****
--- 8087,8094 ----
                without the 'e' flag if the cursor is on the "f" of "if".
                The 'n' flag tells the function not to move the cursor.
  
+               Can also be used as a |method|: >
+                       GetPattern()->search()
  
  searchdecl({name} [, {global} [, {thisblock}]])                       
*searchdecl()*
                Search for the declaration of {name}.
***************
*** 8077,8082 ****
--- 8108,8116 ----
                           echo getline('.')
                        endif
  <
+               Can also be used as a |method|: >
+                       GetName()->searchdecl()
+ <
                                                        *searchpair()*
  searchpair({start}, {middle}, {end} [, {flags} [, {skip}
                                [, {stopline} [, {timeout}]]]])
***************
*** 8191,8196 ****
--- 8225,8233 ----
  <             In this example "submatch" is 2 when a lowercase letter is
                found |/\l|, 3 when an uppercase letter is found |/\u|.
  
+               Can also be used as a |method|: >
+                       GetPattern()->searchpos()
+ 
  server2client({clientid}, {string})                   *server2client()*
                Send a reply string to {clientid}.  The most recent {clientid}
                that sent a string can be retrieved with expand("<client>").
***************
*** 8202,8207 ****
--- 8239,8247 ----
                See also |clientserver|.
                Example: >
                        :echo server2client(expand("<client>"), "HELLO")
+ 
+ <             Can also be used as a |method|: >
+                       GetClientId()->server2client(string)
  <
  serverlist()                                  *serverlist()*
                Return a list of available server names, one per line.
***************
*** 8225,8230 ****
--- 8265,8273 ----
                {lnum} is not valid then 1 is returned.  On success 0 is
                returned.
  
+               Can also be used as a |method|: >
+                       GetText()->setbufline(buf, lnum)
+ 
  setbufvar({expr}, {varname}, {val})                   *setbufvar()*
                Set option or local variable {varname} in buffer {expr} to
                {val}.
***************
*** 8238,8243 ****
--- 8281,8289 ----
                        :call setbufvar("todo", "myvar", "foobar")
  <             This function is not available in the |sandbox|.
  
+               Can also be used as a |method|: >
+                       GetValue()->setbufvar(buf, varname)
+ 
  setcharsearch({dict})                                 *setcharsearch()*
                Set the current character search information to {dict},
                which contains one or more of the following entries:
***************
*** 8258,8263 ****
--- 8304,8312 ----
                        :call setcharsearch(prevsearch)
  <             Also see |getcharsearch()|.
  
+               Can also be used as a |method|: >
+                       SavedSearch()->setcharsearch()
+ 
  setcmdpos({pos})                                      *setcmdpos()*
                Set the cursor position in the command line to byte position
                {pos}.  The first position is 1.
***************
*** 8273,8283 ****
--- 8322,8338 ----
                Returns 0 when successful, 1 when not editing the command
                line.
  
+               Can also be used as a |method|: >
+                       GetPos()->setcmdpos()
+ 
  setenv({name}, {val})                                         *setenv()*
                Set environment variable {name} to {val}.
                When {val} is |v:null| the environment variable is deleted.
                See also |expr-env|.
  
+               Can also be used as a |method|, passing the value as the base: >
+                       GetPath()->setenv('PATH')
+ 
  setfperm({fname}, {mode})                             *setfperm()* *chmod*
                Set the file permissions for {fname} to {mode}.
                {mode} must be a string with 9 characters.  It is of the form
***************
*** 8324,8329 ****
--- 8379,8387 ----
  
  <             Note: The '[ and '] marks are not set.
  
+               Can also be used as a |method|, passing the text as the base: >
+                       GetText()->setline(lnum)
+ 
  setloclist({nr}, {list} [, {action} [, {what}]])              *setloclist()*
                Create or replace or add to the location list for window {nr}.
                {nr} can be the window number or the |window-ID|.
*** ../vim-8.1.1992/src/evalfunc.c      2019-09-05 22:33:23.264963492 +0200
--- src/evalfunc.c      2019-09-06 21:28:20.995733779 +0200
***************
*** 700,726 ****
  #ifdef FEAT_RUBY
      {"rubyeval",      1, 1, FEARG_1,    f_rubyeval},
  #endif
!     {"screenattr",    2, 2, 0,          f_screenattr},
!     {"screenchar",    2, 2, 0,          f_screenchar},
!     {"screenchars",   2, 2, 0,          f_screenchars},
      {"screencol",     0, 0, 0,          f_screencol},
!     {"screenpos",     3, 3, 0,          f_screenpos},
      {"screenrow",     0, 0, 0,          f_screenrow},
!     {"screenstring",  2, 2, 0,          f_screenstring},
!     {"search",                1, 4, 0,          f_search},
!     {"searchdecl",    1, 3, 0,          f_searchdecl},
      {"searchpair",    3, 7, 0,          f_searchpair},
      {"searchpairpos", 3, 7, 0,          f_searchpairpos},
!     {"searchpos",     1, 4, 0,          f_searchpos},
!     {"server2client", 2, 2, 0,          f_server2client},
      {"serverlist",    0, 0, 0,          f_serverlist},
!     {"setbufline",    3, 3, 0,          f_setbufline},
!     {"setbufvar",     3, 3, 0,          f_setbufvar},
!     {"setcharsearch", 1, 1, 0,          f_setcharsearch},
!     {"setcmdpos",     1, 1, 0,          f_setcmdpos},
!     {"setenv",                2, 2, 0,          f_setenv},
      {"setfperm",      2, 2, FEARG_1,    f_setfperm},
!     {"setline",               2, 2, 0,          f_setline},
      {"setloclist",    2, 4, 0,          f_setloclist},
      {"setmatches",    1, 2, 0,          f_setmatches},
      {"setpos",                2, 2, 0,          f_setpos},
--- 700,726 ----
  #ifdef FEAT_RUBY
      {"rubyeval",      1, 1, FEARG_1,    f_rubyeval},
  #endif
!     {"screenattr",    2, 2, FEARG_1,    f_screenattr},
!     {"screenchar",    2, 2, FEARG_1,    f_screenchar},
!     {"screenchars",   2, 2, FEARG_1,    f_screenchars},
      {"screencol",     0, 0, 0,          f_screencol},
!     {"screenpos",     3, 3, FEARG_1,    f_screenpos},
      {"screenrow",     0, 0, 0,          f_screenrow},
!     {"screenstring",  2, 2, FEARG_1,    f_screenstring},
!     {"search",                1, 4, FEARG_1,    f_search},
!     {"searchdecl",    1, 3, FEARG_1,    f_searchdecl},
      {"searchpair",    3, 7, 0,          f_searchpair},
      {"searchpairpos", 3, 7, 0,          f_searchpairpos},
!     {"searchpos",     1, 4, FEARG_1,    f_searchpos},
!     {"server2client", 2, 2, FEARG_1,    f_server2client},
      {"serverlist",    0, 0, 0,          f_serverlist},
!     {"setbufline",    3, 3, FEARG_3,    f_setbufline},
!     {"setbufvar",     3, 3, FEARG_3,    f_setbufvar},
!     {"setcharsearch", 1, 1, FEARG_1,    f_setcharsearch},
!     {"setcmdpos",     1, 1, FEARG_1,    f_setcmdpos},
!     {"setenv",                2, 2, FEARG_2,    f_setenv},
      {"setfperm",      2, 2, FEARG_1,    f_setfperm},
!     {"setline",               2, 2, FEARG_2,    f_setline},
      {"setloclist",    2, 4, 0,          f_setloclist},
      {"setmatches",    1, 2, 0,          f_setmatches},
      {"setpos",                2, 2, 0,          f_setpos},
*** ../vim-8.1.1992/src/testdir/test_bufline.vim        2019-08-24 
22:58:08.307264136 +0200
--- src/testdir/test_bufline.vim        2019-09-06 21:18:56.808758300 +0200
***************
*** 20,26 ****
    let b = bufnr('%')
    wincmd w
    call assert_equal(1, setbufline(b, 5, ['x']))
!   call assert_equal(1, setbufline(bufnr('$') + 1, 1, ['x']))
    call assert_equal(0, setbufline(b, 4, ['d', 'e']))
    call assert_equal(['c'], b->getbufline(3))
    call assert_equal(['d'], getbufline(b, 4))
--- 20,26 ----
    let b = bufnr('%')
    wincmd w
    call assert_equal(1, setbufline(b, 5, ['x']))
!   call assert_equal(1, ['x']->setbufline(bufnr('$') + 1, 1))
    call assert_equal(0, setbufline(b, 4, ['d', 'e']))
    call assert_equal(['c'], b->getbufline(3))
    call assert_equal(['d'], getbufline(b, 4))
*** ../vim-8.1.1992/src/testdir/test_charsearch.vim     2019-01-09 
23:00:57.997176121 +0100
--- src/testdir/test_charsearch.vim     2019-09-06 21:22:54.116165939 +0200
***************
*** 20,26 ****
    " check that setcharsearch() changes the settings.
    3
    normal! ylfep
!   call setcharsearch({'char': 'k'})
    normal! ;p
    call setcharsearch({'forward': 0})
    normal! $;p
--- 20,26 ----
    " check that setcharsearch() changes the settings.
    3
    normal! ylfep
!   eval {'char': 'k'}->setcharsearch()
    normal! ;p
    call setcharsearch({'forward': 0})
    normal! $;p
*** ../vim-8.1.1992/src/testdir/test_clientserver.vim   2019-09-04 
22:28:53.061026888 +0200
--- src/testdir/test_clientserver.vim   2019-09-06 21:16:03.177475913 +0200
***************
*** 73,79 ****
    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.
--- 73,79 ----
    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, ":eval 
expand('<client>')->server2client('another')\<CR>", 'g:myserverid')
    let peek_result = 'nothing'
    let r = g:myserverid->remote_peek('peek_result')
    " unpredictable whether the result is already available.
*** ../vim-8.1.1992/src/testdir/test_cmdline.vim        2019-08-24 
22:58:08.307264136 +0200
--- src/testdir/test_cmdline.vim        2019-09-06 21:24:24.848095451 +0200
***************
*** 672,678 ****
    call assert_equal('"12ab', @:)
  
    " setcmdpos() returns 1 when not editing the command line.
!   call assert_equal(1, setcmdpos(3))
  endfunc
  
  func Test_cmdline_overstrike()
--- 672,678 ----
    call assert_equal('"12ab', @:)
  
    " setcmdpos() returns 1 when not editing the command line.
!   call assert_equal(1, 3->setcmdpos())
  endfunc
  
  func Test_cmdline_overstrike()
*** ../vim-8.1.1992/src/testdir/test_cursor_func.vim    2019-08-23 
22:31:33.217176868 +0200
--- src/testdir/test_cursor_func.vim    2019-09-06 20:52:55.507737741 +0200
***************
*** 87,93 ****
    call assert_equal({'row': winrow,
        \ 'col': wincol + 13,
        \ 'curscol': wincol + 13,
!       \ 'endcol': wincol + 13}, screenpos(winid, 1, 7))
    call assert_equal({'row': winrow + 2,
        \ 'col': wincol + 1,
        \ 'curscol': wincol + 1,
--- 87,93 ----
    call assert_equal({'row': winrow,
        \ 'col': wincol + 13,
        \ 'curscol': wincol + 13,
!       \ 'endcol': wincol + 13}, winid->screenpos(1, 7))
    call assert_equal({'row': winrow + 2,
        \ 'col': wincol + 1,
        \ 'curscol': wincol + 1,
*** ../vim-8.1.1992/src/testdir/test_diffmode.vim       2019-08-23 
22:31:33.217176868 +0200
--- src/testdir/test_diffmode.vim       2019-09-06 20:51:20.064263673 +0200
***************
*** 330,336 ****
    call setline(1, ['One', '', 'Two', 'Three'])
    diffthis
    redraw
!   call assert_notequal(normattr, screenattr(1, 1))
    diffoff!
    redraw
    call assert_equal(normattr, screenattr(1, 1))
--- 330,336 ----
    call setline(1, ['One', '', 'Two', 'Three'])
    diffthis
    redraw
!   call assert_notequal(normattr, 1->screenattr(1))
    diffoff!
    redraw
    call assert_equal(normattr, screenattr(1, 1))
*** ../vim-8.1.1992/src/testdir/test_environ.vim        2019-08-24 
22:58:08.307264136 +0200
--- src/testdir/test_environ.vim        2019-09-06 21:25:54.151985490 +0200
***************
*** 18,24 ****
  
  func Test_setenv()
    unlet! $TESTENV
!   call setenv('TEST ENV', 'foo')
    call assert_equal('foo', getenv('TEST ENV'))
    call setenv('TEST ENV', v:null)
    call assert_equal(v:null, getenv('TEST ENV'))
--- 18,24 ----
  
  func Test_setenv()
    unlet! $TESTENV
!   eval 'foo'->setenv('TEST ENV')
    call assert_equal('foo', getenv('TEST ENV'))
    call setenv('TEST ENV', v:null)
    call assert_equal(v:null, getenv('TEST ENV'))
*** ../vim-8.1.1992/src/testdir/test_functions.vim      2019-09-04 
22:28:53.061026888 +0200
--- src/testdir/test_functions.vim      2019-09-06 21:28:09.175756863 +0200
***************
*** 1137,1143 ****
    wincmd h
    let wh = winheight('.')
    let dummy_buf = bufnr('dummy_buf2', v:true)
!   call setbufvar(dummy_buf, '&buftype', 'nofile')
    execute 'belowright vertical split #' . dummy_buf
    call assert_equal(wh, winheight('.'))
  
--- 1137,1143 ----
    wincmd h
    let wh = winheight('.')
    let dummy_buf = bufnr('dummy_buf2', v:true)
!   eval 'nofile'->setbufvar(dummy_buf, '&buftype')
    execute 'belowright vertical split #' . dummy_buf
    call assert_equal(wh, winheight('.'))
  
***************
*** 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:')
  
--- 1413,1419 ----
    " is invalid in that buffer.
    call writefile(['just one line'], 'Xfuncrange2')
    new
!   eval 10->range()->setline(1)
    write Xfuncrange1
    call assert_fails('5,8call EditAnotherFile()', 'E16:')
  
*** ../vim-8.1.1992/src/testdir/test_matchadd_conceal_utf8.vim  2019-06-15 
17:57:43.972724036 +0200
--- src/testdir/test_matchadd_conceal_utf8.vim  2019-09-06 20:50:44.472466766 
+0200
***************
*** 10,16 ****
  func s:screenline(lnum) abort
    let line = []
    for c in range(1, winwidth(0))
!     call add(line, nr2char(screenchar(a:lnum, c)))
    endfor
    return s:trim(join(line, ''))
  endfunc
--- 10,16 ----
  func s:screenline(lnum) abort
    let line = []
    for c in range(1, winwidth(0))
!     call add(line, nr2char(a:lnum->screenchar(c)))
    endfor
    return s:trim(join(line, ''))
  endfunc
*** ../vim-8.1.1992/src/testdir/test_popupwin.vim       2019-09-04 
18:15:16.178573707 +0200
--- src/testdir/test_popupwin.vim       2019-09-06 20:54:37.243203128 +0200
***************
*** 833,839 ****
  
    sleep 700m
    redraw
!   let line = join(map(range(1, 5), 'screenstring(1, v:val)'), '')
    call assert_equal('hello', line)
  
    call popup_create('on the command line', #{
--- 833,839 ----
  
    sleep 700m
    redraw
!   let line = join(map(range(1, 5), '1->screenstring(v:val)'), '')
    call assert_equal('hello', line)
  
    call popup_create('on the command line', #{
*** ../vim-8.1.1992/src/testdir/test_search.vim 2019-09-01 14:45:23.757964939 
+0200
--- src/testdir/test_search.vim 2019-09-06 21:11:45.614550454 +0200
***************
*** 1280,1286 ****
  
    normal gg
  
!   call search('foobar', 'c')
    call assert_equal([1, 1], [line('.'), col('.')])
  
    normal j
--- 1280,1286 ----
  
    normal gg
  
!   eval 'foobar'->search('c')
    call assert_equal([1, 1], [line('.'), col('.')])
  
    normal j
***************
*** 1318,1320 ****
--- 1318,1355 ----
      set norl
    endif
  endfunc
+ 
+ func Test_searchdecl()
+   let lines =<< trim END
+      int global;
+ 
+      func()
+      {
+        int global;
+        if (cond) {
+        int local;
+        }
+        int local;
+        // comment
+      }
+   END
+   new
+   call setline(1, lines)
+   10
+   call assert_equal(0, searchdecl('local', 0, 0))
+   call assert_equal(7, getcurpos()[1])
+ 
+   10
+   call assert_equal(0, 'local'->searchdecl(0, 1))
+   call assert_equal(9, getcurpos()[1])
+ 
+   10
+   call assert_equal(0, searchdecl('global'))
+   call assert_equal(5, getcurpos()[1])
+ 
+   10
+   call assert_equal(0, searchdecl('global', 1))
+   call assert_equal(1, getcurpos()[1])
+ 
+   bwipe!
+ endfunc
*** ../vim-8.1.1992/src/testdir/test_searchpos.vim      2016-01-15 
15:33:16.000000000 +0100
--- src/testdir/test_searchpos.vim      2019-09-06 21:14:11.481940092 +0200
***************
*** 7,13 ****
    call cursor(1, 1)
    call assert_equal([1, 1, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
    call cursor(1, 2)
!   call assert_equal([2, 1, 1], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
    set cpo-=c
    call cursor(1, 2)
    call assert_equal([1, 2, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
--- 7,13 ----
    call cursor(1, 1)
    call assert_equal([1, 1, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
    call cursor(1, 2)
!   call assert_equal([2, 1, 1], '\%(\([a-z]\)\|\_.\)\{-}xyz'->searchpos('pcW'))
    set cpo-=c
    call cursor(1, 2)
    call assert_equal([1, 2, 2], searchpos('\%(\([a-z]\)\|\_.\)\{-}xyz', 'pcW'))
*** ../vim-8.1.1992/src/testdir/test_utf8.vim   2019-08-31 22:16:30.774127008 
+0200
--- src/testdir/test_utf8.vim   2019-09-06 20:48:43.657189587 +0200
***************
*** 112,118 ****
    call setline(1, ["ABC\u0308"])
    redraw
    call assert_equal([0x0041], screenchars(1, 1))
!   call assert_equal([0x0042], screenchars(1, 2))
    call assert_equal([0x0043, 0x0308], screenchars(1, 3))
    call assert_equal("A", screenstring(1, 1))
    call assert_equal("B", screenstring(1, 2))
--- 112,118 ----
    call setline(1, ["ABC\u0308"])
    redraw
    call assert_equal([0x0041], screenchars(1, 1))
!   call assert_equal([0x0042], 1->screenchars(2))
    call assert_equal([0x0043, 0x0308], screenchars(1, 3))
    call assert_equal("A", screenstring(1, 1))
    call assert_equal("B", screenstring(1, 2))
*** ../vim-8.1.1992/src/version.c       2019-09-06 20:40:17.759227838 +0200
--- src/version.c       2019-09-06 21:28:54.259666514 +0200
***************
*** 759,760 ****
--- 759,762 ----
  {   /* Add new patch number below this line */
+ /**/
+     1993,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
201. When somebody asks you where you are, you tell them in which chat room.

 /// 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/201909061935.x86JZ1ns006081%40masaka.moolenaar.net.

Raspunde prin e-mail lui