]> granicus.if.org Git - vim/commitdiff
patch 8.1.1996: more functions can be used as methods v8.1.1996
authorBram Moolenaar <Bram@vim.org>
Fri, 6 Sep 2019 20:46:09 +0000 (22:46 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 6 Sep 2019 20:46:09 +0000 (22:46 +0200)
Problem:    More functions can be used as methods.
Solution:   Make various functions usable as a method.

13 files changed:
runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_bufwintabinfo.vim
src/testdir/test_cursor_func.vim
src/testdir/test_expr.vim
src/testdir/test_functions.vim
src/testdir/test_put.vim
src/testdir/test_quickfix.vim
src/testdir/test_sha256.vim
src/testdir/test_tabpage.vim
src/testdir/test_tagjump.vim
src/testdir/test_vartabs.vim
src/version.c

index cc90cbf913225476937863dc88013266604f2728..56aa6a345f47d459afaed6bffde87e36ca228923 100644 (file)
@@ -1,4 +1,4 @@
-*eval.txt*     For Vim version 8.1.  Last change: 2019 Sep 04
+*eval.txt*     For Vim version 8.1.  Last change: 2019 Sep 06
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -3154,7 +3154,7 @@ bufadd({name})                                            *bufadd()*
                number.  Otherwise return the buffer number of the newly
                created buffer.  When {name} is an empty string then a new
                buffer is always created.
-               The buffer will not have' 'buflisted' set and not be loaded
+               The buffer will not have 'buflisted' set and not be loaded
                yet.  To add some text to the buffer use this: >
                        let bufnr = bufadd('someName')
                        call bufload(bufnr)
@@ -6465,7 +6465,7 @@ listener_add({callback} [, {buf}])                        *listener_add()*
                buffer is used.
                Returns a unique ID that can be passed to |listener_remove()|.
 
-               The {callback} is invoked with four arguments:
+               The {callback} is invoked with five arguments:
                    a:bufnr     the buffer that was changed
                    a:start     first changed line number
                    a:end       first line number below the change
@@ -8396,6 +8396,10 @@ setloclist({nr}, {list} [, {action} [, {what}]])         *setloclist()*
                only the items listed in {what} are set. Refer to |setqflist()|
                for the list of supported keys in {what}.
 
+               Can also be used as a |method|, the base is passed as the
+               second argument: >
+                       GetLoclist()->setloclist(winnr)
+
 setmatches({list} [, {win}])                           *setmatches()*
                Restores a list of matches saved by |getmatches() for the
                current window|.  Returns 0 if successful, otherwise -1.  All
@@ -8404,6 +8408,9 @@ setmatches({list} [, {win}])                              *setmatches()*
                If {win} is specified, use the window with this number or
                window ID instead of the current window.
 
+               Can also be used as a |method|: >
+                       GetMatches()->setmatches()
+<
                                                        *setpos()*
 setpos({expr}, {list})
                Set the position for {expr}.  Possible values:
@@ -8453,6 +8460,9 @@ setpos({expr}, {list})
                also set the preferred column.  Also see the "curswant" key in
                |winrestview()|.
 
+               Can also be used as a |method|: >
+                       GetPosition()->setpos('.')
+
 setqflist({list} [, {action} [, {what}]])              *setqflist()*
                Create or replace or add to the quickfix list.
 
@@ -8554,7 +8564,10 @@ setqflist({list} [, {action} [, {what}]])                *setqflist()*
                independent of the 'errorformat' setting.  Use a command like
                `:cc 1` to jump to the first position.
 
-
+               Can also be used as a |method|, the base is passed as the
+               second argument: >
+                       GetErrorlist()->setqflist()
+<
                                                        *setreg()*
 setreg({regname}, {value} [, {options}])
                Set the register {regname} to {value}.
@@ -8602,6 +8615,10 @@ setreg({regname}, {value} [, {options}])
                nothing: >
                        :call setreg('a', '', 'al')
 
+<              Can also be used as a |method|, the base is passed as the
+               second argument: >
+                       GetText()->setreg('a')
+
 settabvar({tabnr}, {varname}, {val})                   *settabvar()*
                Set tab-local variable {varname} to {val} in tab page {tabnr}.
                |t:var|
@@ -8611,6 +8628,9 @@ settabvar({tabnr}, {varname}, {val})                      *settabvar()*
                Tabs are numbered starting with one.
                This function is not available in the |sandbox|.
 
+               Can also be used as a |method|, the base is used as the value: >
+                       GetValue()->settabvar(tab, name)
+
 settabwinvar({tabnr}, {winnr}, {varname}, {val})       *settabwinvar()*
                Set option or local variable {varname} in window {winnr} to
                {val}.
@@ -8629,6 +8649,9 @@ settabwinvar({tabnr}, {winnr}, {varname}, {val})  *settabwinvar()*
                        :call settabwinvar(3, 2, "myvar", "foobar")
 <              This function is not available in the |sandbox|.
 
+               Can also be used as a |method|, the base is used as the value: >
+                       GetValue()->settabvar(tab, winnr, name)
+
 settagstack({nr}, {dict} [, {action}])                 *settagstack()*
                Modify the tag stack of the window {nr} using {dict}.
                {nr} can be the window number or the |window-ID|.
@@ -8660,16 +8683,26 @@ settagstack({nr}, {dict} [, {action}])                  *settagstack()*
                        call settagstack(1003, stack)
                        unlet stack
 <
-setwinvar({nr}, {varname}, {val})                      *setwinvar()*
+               Can also be used as a |method|, the base is used as the Dict: >
+                       GetStack()->settagstack(winnr)
+
+setwinvar({winnr}, {varname}, {val})                   *setwinvar()*
                Like |settabwinvar()| for the current tab page.
                Examples: >
                        :call setwinvar(1, "&list", 0)
                        :call setwinvar(2, "myvar", "foobar")
 
+<              Can also be used as a |method|, the base is used as the value: >
+                       GetValue()->setwinvar(winnr, name)
+
 sha256({string})                                               *sha256()*
                Returns a String with 64 hex characters, which is the SHA256
                checksum of {string}.
-               {only available when compiled with the |+cryptv| feature}
+
+               Can also be used as a |method|: >
+                       GetText()->sha256()
+
+<              {only available when compiled with the |+cryptv| feature}
 
 shellescape({string} [, {special}])                    *shellescape()*
                Escape {string} for use as a shell command argument.
@@ -8701,6 +8734,8 @@ shellescape({string} [, {special}])                       *shellescape()*
                    :call system("chmod +w -- " . shellescape(expand("%")))
 <              See also |::S|.
 
+               Can also be used as a |method|: >
+                       GetCommand()->shellescape()
 
 shiftwidth([{col}])                                            *shiftwidth()*
                Returns the effective value of 'shiftwidth'. This is the
@@ -8714,6 +8749,9 @@ shiftwidth([{col}])                                               *shiftwidth()*
                'vartabstop' feature. If the 'vartabstop' setting is enabled and
                no {col} argument is given, column 1 will be assumed.
 
+               Can also be used as a |method|: >
+                       GetColumn()->shiftwidth()
+
 sign_ functions are documented here: |sign-functions-details|
 
 
index 2949c8920fbc63a93a5767f99e357a4ee00018ba..0aa8fbfd09eb255450f8b51588863ac55aa76540 100644 (file)
@@ -336,6 +336,7 @@ typedef struct
 #define FEARG_1    1       // base is the first argument
 #define FEARG_2    2       // base is the second argument
 #define FEARG_3    3       // base is the third argument
+#define FEARG_4    4       // base is the fourth argument
 #define FEARG_LAST 9       // base is the last argument
 
 static funcentry_T global_functions[] =
@@ -721,20 +722,20 @@ static funcentry_T global_functions[] =
     {"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},
-    {"setqflist",      1, 3, 0,          f_setqflist},
-    {"setreg",         2, 3, 0,          f_setreg},
-    {"settabvar",      3, 3, 0,          f_settabvar},
-    {"settabwinvar",   4, 4, 0,          f_settabwinvar},
-    {"settagstack",    2, 3, 0,          f_settagstack},
-    {"setwinvar",      3, 3, 0,          f_setwinvar},
+    {"setloclist",     2, 4, FEARG_2,    f_setloclist},
+    {"setmatches",     1, 2, FEARG_1,    f_setmatches},
+    {"setpos",         2, 2, FEARG_2,    f_setpos},
+    {"setqflist",      1, 3, FEARG_1,    f_setqflist},
+    {"setreg",         2, 3, FEARG_2,    f_setreg},
+    {"settabvar",      3, 3, FEARG_3,    f_settabvar},
+    {"settabwinvar",   4, 4, FEARG_4,    f_settabwinvar},
+    {"settagstack",    2, 3, FEARG_2,    f_settagstack},
+    {"setwinvar",      3, 3, FEARG_3,    f_setwinvar},
 #ifdef FEAT_CRYPT
-    {"sha256",         1, 1, 0,          f_sha256},
+    {"sha256",         1, 1, FEARG_1,    f_sha256},
 #endif
-    {"shellescape",    1, 2, 0,          f_shellescape},
-    {"shiftwidth",     0, 1, 0,          f_shiftwidth},
+    {"shellescape",    1, 2, FEARG_1,    f_shellescape},
+    {"shiftwidth",     0, 1, FEARG_1,    f_shiftwidth},
 #ifdef FEAT_SIGNS
     {"sign_define",    1, 2, FEARG_1,    f_sign_define},
     {"sign_getdefined",        0, 1, FEARG_1,    f_sign_getdefined},
@@ -1060,6 +1061,16 @@ call_internal_method(
        for (i = 2; i < argcount; ++i)
            argv[i + 1] = argvars[i];
     }
+    else if (global_functions[fi].f_argtype == FEARG_4)
+    {
+       // base value goes fourth
+       argv[0] = argvars[0];
+       argv[1] = argvars[1];
+       argv[2] = argvars[2];
+       argv[3] = *basetv;
+       for (i = 3; i < argcount; ++i)
+           argv[i + 1] = argvars[i];
+    }
     else
     {
        // FEARG_1: base value goes first
index 4e2c5d284e0fa1c43e833daa27cec3991a8c291a..ee22ebd455e6b58fc82df1a0850dfd83dd032039 100644 (file)
@@ -47,7 +47,7 @@ function Test_getbufwintabinfo()
     tabnew | let w3_id = win_getid()
     new | let w4_id = win_getid()
     vert new | let w5_id = win_getid()
-    call setwinvar(0, 'signal', 'green')
+    eval 'green'->setwinvar(0, 'signal')
     tabfirst
     let winlist = getwininfo()
     call assert_equal(5, len(winlist))
index 4fc28c9cf5752c67879def54825e378a62a9a329..66d5d035ea6cefb6e858a8d0ac5af3224ffae1ff 100644 (file)
@@ -37,7 +37,7 @@ endfunc
 " Very short version of what matchparen does.
 function s:Highlight_Matching_Pair()
   let save_cursor = getcurpos()
-  call setpos('.', save_cursor)
+  eval save_cursor->setpos('.')
 endfunc
 
 func Test_curswant_with_autocommand()
index 9f4373278f04a822f6f79cdd85bd28939f49b132..110cecb6059ae4dc7d26b1190545037ddee03495 100644 (file)
@@ -504,7 +504,7 @@ func Test_setmatches()
     let set[0]['conceal'] = 5
     let exp[0]['conceal'] = '5'
   endif
-  call setmatches(set)
+  eval set->setmatches()
   call assert_equal(exp, getmatches())
 endfunc
 
index 1d8d74ddb1f62889feced9d3ec531c9a4dd6c12f..3588c767a06fd0f9300f71fe73afb8d6ad958583 100644 (file)
@@ -1180,7 +1180,7 @@ func Test_shellescape()
   let save_shell = &shell
   set shell=bash
   call assert_equal("'text'", shellescape('text'))
-  call assert_equal("'te\"xt'", shellescape('te"xt'))
+  call assert_equal("'te\"xt'", 'te"xt'->shellescape())
   call assert_equal("'te'\\''xt'", shellescape("te'xt"))
 
   call assert_equal("'te%xt'", shellescape("te%xt"))
index afe82f9a60e00342b8dfcdaff522e1bc56fbf75d..225ebd1f3dc333e5ff7d8a0655852a7ed1f00da2 100644 (file)
@@ -41,7 +41,7 @@ func Test_put_lines()
   call assert_equal(['Line 3', '', 'Line 1', 'Line2'], getline(1,'$'))
   " clean up
   bw!
-  call setreg('a', a[0], a[1])
+  eval a[0]->setreg('a', a[1])
 endfunc
 
 func Test_put_expr()
index 7a1f96d7490b546a337c691f714446ef457ff394..402a96dc53b4e2a87f880a660f6649be1cdc5138 100644 (file)
@@ -711,7 +711,7 @@ func Test_locationlist()
       " NOTE: problem 1:
       " intentionally not setting 'lnum' so that the quickfix entries are not
       " valid
-      call setloclist(0, qflist, ' ')
+      eval qflist->setloclist(0, ' ')
     endfor
 
     " Test A
@@ -1515,7 +1515,7 @@ endfunc
 
 func Test_setqflist_invalid_nr()
   " The following command used to crash Vim
-  call setqflist([], ' ', {'nr' : $XXX_DOES_NOT_EXIST})
+  eval []->setqflist(' ', {'nr' : $XXX_DOES_NOT_EXIST})
 endfunc
 
 func Test_quickfix_set_list_with_act()
index d0f92b1bad31685793ad587a1325df540c55fa16..f6f430b04e15b98a96b1bb479e8a8f1dfcfe37cd 100644 (file)
@@ -6,17 +6,17 @@ CheckFunction sha256
 
 function Test_sha256()
   " test for empty string:
-  call assert_equal(sha256(""), 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855')
+  call assert_equal('e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855', sha256(""))
 
   "'test for 1 char:
-  call assert_equal(sha256("a"), 'ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb')
+  call assert_equal('ca978112ca1bbdcafac231b39a23dc4da786eff8147c4e72b9807785afee48bb', sha256("a"))
   "
   "test for 3 chars:
-  call assert_equal(sha256("abc"), 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad')
+  call assert_equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad', "abc"->sha256())
 
   " test for contains meta char:
-  call assert_equal(sha256("foo\nbar"), '807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776')
+  call assert_equal('807eff6267f3f926a21d234f7b0cf867a86f47e07a532f15e8cc39ed110ca776', sha256("foo\nbar"))
 
   " test for contains non-ascii char:
-  call assert_equal(sha256("\xde\xad\xbe\xef"), '5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953')
+  call assert_equal('5f78c33274e43fa9de5659265c1d917e25c03722dcb0b8d27db8d5feaa813953', sha256("\xde\xad\xbe\xef"))
 endfunction
index c8ac1141fd20d804ae6e71ca4d62e85044639902..020fe27659e21cb6b2c5f88eba212f5d3177be57 100644 (file)
@@ -34,7 +34,7 @@ function Test_tabpage()
   tabnew
   tabfirst
   call settabvar(2, 'val_num', 100)
-  call settabvar(2, 'val_str', 'SetTabVar test')
+  eval 'SetTabVar test'->settabvar(2, 'val_str')
   call settabvar(2, 'val_list', ['red', 'blue', 'green'])
   "
   call assert_true(gettabvar(2, 'val_num') == 100 && gettabvar(2, 'val_str') == 'SetTabVar test' && gettabvar(2, 'val_list') == ['red', 'blue', 'green'])
@@ -183,7 +183,7 @@ function Test_tabpage_with_autocmd()
   let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
   call assert_equal(['a', 'a'], s:li)
   let s:li = []
-  C call map(copy(winr), 'settabwinvar('.tabn.', v:val, ''a'', v:val*2)')
+  C call map(copy(winr), '(v:val*2)->settabwinvar(' .. tabn .. ', v:val, ''a'')')
   let s:li = split(join(map(copy(winr), 'gettabwinvar('.tabn.', v:val, "a")')), '\s\+')
   call assert_equal(['2', '4'], s:li)
 
index 4c16129a21d866b42bd78df8ccdc16c97f7b8d2b..6d47020a52cc39b5cbdfd335f387f930fde871ab 100644 (file)
@@ -303,7 +303,7 @@ func Test_getsettagstack()
   " Try to set current index to invalid values
   call settagstack(1, {'curidx' : -1})
   call assert_equal(1, gettagstack().curidx)
-  call settagstack(1, {'curidx' : 50})
+  eval {'curidx' : 50}->settagstack(1)
   call assert_equal(4, gettagstack().curidx)
 
   " Try pushing invalid items onto the stack
index b0f3e15aab18a92a2d03d2ae7a7769d853521605..47844fb1105e0759b1b5807334c1daf1599ad2ee 100644 (file)
@@ -329,7 +329,7 @@ func Test_vartabs_shiftwidth()
   let lines = ScreenLines([1, 2], winwidth(0))
   call s:compare_lines(expect2, lines)
   call assert_equal(20, shiftwidth(virtcol('.')-2))
-  call assert_equal(30, shiftwidth(virtcol('.')))
+  call assert_equal(30, virtcol('.')->shiftwidth())
   norm! $>>
   let expect3 = ['                                        ', '                    x                   ', '~                                       ']
   let lines = ScreenLines([1, 3], winwidth(0))
index 65512c98fb1cd6c12e7579474912529321116368..9610b1aaae6f3579578ef7975e6ca1eba5b2e553 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1996,
 /**/
     1995,
 /**/