# HG changeset patch # User Bram Moolenaar # Date 1567962004 -7200 # Node ID 8a2fb21c23c062d08b1cb3b4d74317bbf04d50a1 # Parent e7a81e948c1280fba459409a83bcaa9865f05d65 patch 8.1.2011: more functions can be used as methods Commit: https://github.com/vim/vim/commit/ce90e36f5969e733a0a919f1736453332c33aad6 Author: Bram Moolenaar Date: Sun Sep 8 18:58:44 2019 +0200 patch 8.1.2011: more functions can be used as methods Problem: More functions can be used as methods. Solution: Make various functions usable as a method. Make the window command test faster. diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt --- a/runtime/doc/eval.txt +++ b/runtime/doc/eval.txt @@ -9606,6 +9606,8 @@ tabpagebuflist([{arg}]) *tabpagebufl endfor < Note that a buffer may appear in more than one window. + Can also be used as a |method|: > + GetTabpage()->tabpagebuflist() tabpagenr([{arg}]) *tabpagenr()* The result is a Number, which is the number of the current @@ -9628,6 +9630,9 @@ tabpagewinnr({tabarg} [, {arg}]) *tabp tabpagewinnr(4, '$') " number of windows in tab page 4 < When {tabarg} is invalid zero is returned. + Can also be used as a |method|: > + GetTabpage()->tabpagewinnr() +< *tagfiles()* tagfiles() Returns a |List| with the file names used to search for tags for the current buffer. This is the 'tags' option expanded. @@ -9676,6 +9681,9 @@ taglist({expr} [, {filename}]) *tagli located by Vim. Refer to |tags-file-format| for the format of the tags file generated by the different ctags tools. + Can also be used as a |method|: > + GetTagpattern()->taglist() + tan({expr}) *tan()* Return the tangent of {expr}, measured in radians, as a |Float| in the range [-inf, inf]. diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt --- a/runtime/doc/testing.txt +++ b/runtime/doc/testing.txt @@ -44,6 +44,8 @@ test_alloc_fail({id}, {countdown}, {repe let memory allocation fail {repeat} times. When {repeat} is smaller than one it fails one time. + Can also be used as a |method|: > + GetAllocId()->test_alloc_fail() test_autochdir() *test_autochdir()* Set a flag to enable the effect of 'autochdir' before Vim @@ -55,6 +57,8 @@ test_feedinput({string}) *test_feedin were typed by the user. This uses a low level input buffer. This function works only when with |+unix| or GUI is running. + Can also be used as a |method|: > + GetText()->test_feedinput() test_garbagecollect_now() *test_garbagecollect_now()* Like garbagecollect(), but executed right away. This must @@ -73,6 +77,8 @@ test_getvalue({name}) *test_getvalue {name} are supported: need_fileinfo + Can also be used as a |method|: > + GetName()->test_getvalue() test_ignore_error({expr}) *test_ignore_error()* Ignore any error containing {expr}. A normal message is given @@ -84,6 +90,8 @@ test_ignore_error({expr}) *test_ignor When the {expr} is the string "RESET" then the list of ignored errors is made empty. + Can also be used as a |method|: > + GetErrorText()->test_ignore_error() test_null_blob() *test_null_blob()* Return a |Blob| that is null. Only useful for testing. @@ -124,6 +132,9 @@ test_option_not_set({name}) *test_opt even though the value is "double". Only to be used for testing! + Can also be used as a |method|: > + GetOptionName()->test_option_not_set() + test_override({name}, {val}) *test_override()* Overrides certain parts of Vim's internal processing to be able @@ -155,12 +166,17 @@ test_override({name}, {val}) *test_ov < The value of "starting" is saved. It is restored by: > call test_override('starting', 0) +< Can also be used as a |method|: > + GetOverrideVal()-> test_override('starting') test_refcount({expr}) *test_refcount()* Return the reference count of {expr}. When {expr} is of a type that does not have a reference count, returns -1. Only to be used for testing. + Can also be used as a |method|: > + GetVarname()->test_refcount() + test_scrollbar({which}, {value}, {dragging}) *test_scrollbar()* Pretend using scrollbar {which} to move it to position @@ -179,6 +195,8 @@ test_scrollbar({which}, {value}, {draggi Only works when the {which} scrollbar actually exists, obviously only when using the GUI. + Can also be used as a |method|: > + GetValue()->test_scrollbar('right', 0) test_setmouse({row}, {col}) *test_setmouse()* Set the mouse position to be used for the next mouse action. @@ -197,6 +215,9 @@ test_settime({expr}) *test_settime() {expr} must evaluate to a number. When the value is zero the normal behavior is restored. + Can also be used as a |method|: > + GetTime()->test_settime() + ============================================================================== 3. Assert functions *assert-functions-details* diff --git a/src/evalfunc.c b/src/evalfunc.c --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -754,11 +754,11 @@ static funcentry_T global_functions[] = {"synstack", 2, 2, 0, f_synstack}, {"system", 1, 2, FEARG_1, f_system}, {"systemlist", 1, 2, FEARG_1, f_systemlist}, - {"tabpagebuflist", 0, 1, 0, f_tabpagebuflist}, + {"tabpagebuflist", 0, 1, FEARG_1, f_tabpagebuflist}, {"tabpagenr", 0, 1, 0, f_tabpagenr}, - {"tabpagewinnr", 1, 2, 0, f_tabpagewinnr}, + {"tabpagewinnr", 1, 2, FEARG_1, f_tabpagewinnr}, {"tagfiles", 0, 0, 0, f_tagfiles}, - {"taglist", 1, 2, 0, f_taglist}, + {"taglist", 1, 2, FEARG_1, f_taglist}, #ifdef FEAT_FLOAT {"tan", 1, 1, FEARG_1, f_tan}, {"tanh", 1, 1, FEARG_1, f_tanh}, @@ -793,13 +793,13 @@ static funcentry_T global_functions[] = {"term_start", 1, 2, 0, f_term_start}, {"term_wait", 1, 2, 0, f_term_wait}, #endif - {"test_alloc_fail", 3, 3, 0, f_test_alloc_fail}, + {"test_alloc_fail", 3, 3, FEARG_1, f_test_alloc_fail}, {"test_autochdir", 0, 0, 0, f_test_autochdir}, - {"test_feedinput", 1, 1, 0, f_test_feedinput}, - {"test_garbagecollect_now", 0, 0, 0, f_test_garbagecollect_now}, - {"test_garbagecollect_soon", 0, 0, 0, f_test_garbagecollect_soon}, - {"test_getvalue", 1, 1, 0, f_test_getvalue}, - {"test_ignore_error", 1, 1, 0, f_test_ignore_error}, + {"test_feedinput", 1, 1, FEARG_1, f_test_feedinput}, + {"test_garbagecollect_now", 0, 0, 0, f_test_garbagecollect_now}, + {"test_garbagecollect_soon", 0, 0, 0, f_test_garbagecollect_soon}, + {"test_getvalue", 1, 1, FEARG_1, f_test_getvalue}, + {"test_ignore_error", 1, 1, FEARG_1, f_test_ignore_error}, {"test_null_blob", 0, 0, 0, f_test_null_blob}, #ifdef FEAT_JOB_CHANNEL {"test_null_channel", 0, 0, 0, f_test_null_channel}, @@ -811,16 +811,16 @@ static funcentry_T global_functions[] = {"test_null_list", 0, 0, 0, f_test_null_list}, {"test_null_partial", 0, 0, 0, f_test_null_partial}, {"test_null_string", 0, 0, 0, f_test_null_string}, - {"test_option_not_set", 1, 1, 0, f_test_option_not_set}, - {"test_override", 2, 2, 0, f_test_override}, - {"test_refcount", 1, 1, 0, f_test_refcount}, + {"test_option_not_set", 1, 1, FEARG_1, f_test_option_not_set}, + {"test_override", 2, 2, FEARG_2, f_test_override}, + {"test_refcount", 1, 1, FEARG_1, f_test_refcount}, #ifdef FEAT_GUI - {"test_scrollbar", 3, 3, 0, f_test_scrollbar}, + {"test_scrollbar", 3, 3, FEARG_2, f_test_scrollbar}, #endif #ifdef FEAT_MOUSE {"test_setmouse", 2, 2, 0, f_test_setmouse}, #endif - {"test_settime", 1, 1, 0, f_test_settime}, + {"test_settime", 1, 1, FEARG_1, f_test_settime}, #ifdef FEAT_TIMERS {"timer_info", 0, 1, 0, f_timer_info}, {"timer_pause", 2, 2, 0, f_timer_pause}, diff --git a/src/testdir/test_assert.vim b/src/testdir/test_assert.vim --- a/src/testdir/test_assert.vim +++ b/src/testdir/test_assert.vim @@ -259,7 +259,7 @@ endfunc func Test_override() call test_override('char_avail', 1) - call test_override('redraw', 1) + eval 1->test_override('redraw') call test_override('ALL', 0) call assert_fails("call test_override('xxx', 1)", 'E475') call assert_fails("call test_override('redraw', 'yes')", 'E474') diff --git a/src/testdir/test_gui.vim b/src/testdir/test_gui.vim --- a/src/testdir/test_gui.vim +++ b/src/testdir/test_gui.vim @@ -398,71 +398,68 @@ func Test_set_guifont() endfunc func Test_set_guifontset() + CheckFeature xfontset let skipped = '' - if !has('xfontset') - let skipped = g:not_supported . 'xfontset' - else - let ctype_saved = v:ctype + let ctype_saved = v:ctype + + " First, since XCreateFontSet(3) is very sensitive to locale, fonts must + " be chosen meticulously. + let font_head = '-misc-fixed-medium-r-normal--14' - " First, since XCreateFontSet(3) is very sensitive to locale, fonts must - " be chosen meticulously. - let font_head = '-misc-fixed-medium-r-normal--14' + let font_aw70 = font_head . '-130-75-75-c-70' + let font_aw140 = font_head . '-130-75-75-c-140' - let font_aw70 = font_head . '-130-75-75-c-70' - let font_aw140 = font_head . '-130-75-75-c-140' + let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' + let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' - let font_jisx0201 = font_aw70 . '-jisx0201.1976-0' - let font_jisx0208 = font_aw140 . '-jisx0208.1983-0' - - let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') - let short_XLFDs = join([ font_aw140, font_aw70 ], ',') - let singleton = font_head . '-*' - let aliases = 'k14,r14' + let full_XLFDs = join([ font_jisx0208, font_jisx0201 ], ',') + let short_XLFDs = join([ font_aw140, font_aw70 ], ',') + let singleton = font_head . '-*' + let aliases = 'k14,r14' - " Second, among 'locales', look up such a locale that gets 'set - " guifontset=' to work successfully with every fontset specified with - " 'fontsets'. - let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] - let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] + " Second, among 'locales', look up such a locale that gets 'set + " guifontset=' to work successfully with every fontset specified with + " 'fontsets'. + let locales = [ 'ja_JP.UTF-8', 'ja_JP.eucJP', 'ja_JP.SJIS' ] + let fontsets = [ full_XLFDs, short_XLFDs, singleton, aliases ] - let feasible = 0 - for locale in locales + let feasible = 0 + for locale in locales + try + exec 'language ctype' locale + catch /^Vim\%((\a\+)\)\=:E197/ + continue + endtry + let done = 0 + for fontset in fontsets try - exec 'language ctype' locale - catch /^Vim\%((\a\+)\)\=:E197/ - continue + exec 'set guifontset=' . fontset + catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ + break endtry - let done = 0 - for fontset in fontsets - try - exec 'set guifontset=' . fontset - catch /^Vim\%((\a\+)\)\=:E\%(250\|252\|234\|597\|598\)/ - break - endtry - let done += 1 - endfor - if done == len(fontsets) - let feasible = 1 - break - endif + let done += 1 endfor + if done == len(fontsets) + let feasible = 1 + break + endif + endfor - " Third, give a set of tests if it is found feasible. - if !feasible - let skipped = g:not_hosted - else - " N.B. 'v:ctype' has already been set to an appropriate value in the - " previous loop. - for fontset in fontsets - exec 'set guifontset=' . fontset - call assert_equal(fontset, &guifontset) - endfor - endif + " Third, give a set of tests if it is found feasible. + if !feasible + let skipped = g:not_hosted + else + " N.B. 'v:ctype' has already been set to an appropriate value in the + " previous loop. + for fontset in fontsets + exec 'set guifontset=' . fontset + call assert_equal(fontset, &guifontset) + endfor + endif - " Finally, restore ctype. - exec 'language ctype' ctype_saved - endif + " Finally, restore ctype. + exec 'language ctype' ctype_saved if !empty(skipped) throw skipped @@ -677,7 +674,7 @@ func Test_scrollbars() set guioptions+=rlb " scroll to move line 11 at top, moves the cursor there - call test_scrollbar('left', 10, 0) + eval 10->test_scrollbar('left', 0) redraw call assert_equal(1, winline()) call assert_equal(11, line('.')) diff --git a/src/testdir/test_messages.vim b/src/testdir/test_messages.vim --- a/src/testdir/test_messages.vim +++ b/src/testdir/test_messages.vim @@ -90,7 +90,7 @@ func Test_echoerr() if has('float') call assert_equal("\n1.23 IgNoRe", execute(':echoerr 1.23 "IgNoRe"')) endif - call test_ignore_error('') + eval ''->test_ignore_error() call assert_match("function('\\d*')", execute(':echoerr {-> 1234}')) call test_ignore_error('RESET') endfunc diff --git a/src/testdir/test_options.vim b/src/testdir/test_options.vim --- a/src/testdir/test_options.vim +++ b/src/testdir/test_options.vim @@ -510,7 +510,7 @@ func Test_shortmess_F2() call assert_true(empty(execute('bn', ''))) call assert_false(test_getvalue('need_fileinfo')) call assert_true(empty(execute('bn', ''))) - call assert_false(test_getvalue('need_fileinfo')) + call assert_false('need_fileinfo'->test_getvalue()) set hidden call assert_true(empty(execute('bn', ''))) call assert_false(test_getvalue('need_fileinfo')) diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim --- a/src/testdir/test_quickfix.vim +++ b/src/testdir/test_quickfix.vim @@ -517,7 +517,7 @@ func Test_nomem() call test_alloc_fail(GetAllocId('qf_dirname_start'), 0, 0) call assert_fails('vimgrep vim runtest.vim', 'E342:') - call test_alloc_fail(GetAllocId('qf_dirname_now'), 0, 0) + call GetAllocId('qf_dirname_now')->test_alloc_fail(0, 0) call assert_fails('vimgrep vim runtest.vim', 'E342:') call test_alloc_fail(GetAllocId('qf_namebuf'), 0, 0) diff --git a/src/testdir/test_taglist.vim b/src/testdir/test_taglist.vim --- a/src/testdir/test_taglist.vim +++ b/src/testdir/test_taglist.vim @@ -13,7 +13,7 @@ func Test_taglist() split Xtext call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo"), {i, v -> v.name})) - call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xtext"), {i, v -> v.name})) + call assert_equal(['FFoo', 'BFoo'], map("Foo"->taglist("Xtext"), {i, v -> v.name})) call assert_equal(['FFoo', 'BFoo'], map(taglist("Foo", "Xfoo"), {i, v -> v.name})) call assert_equal(['BFoo', 'FFoo'], map(taglist("Foo", "Xbar"), {i, v -> v.name})) diff --git a/src/testdir/test_termcodes.vim b/src/testdir/test_termcodes.vim --- a/src/testdir/test_termcodes.vim +++ b/src/testdir/test_termcodes.vim @@ -646,7 +646,7 @@ func Test_term_rgb_response() " response to t_RB, 4 digits, dark set background=light - call test_option_not_set('background') + eval 'background'->test_option_not_set() let red = 0x29 let green = 0x4a let blue = 0x6b diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim --- a/src/testdir/test_timers.vim +++ b/src/testdir/test_timers.vim @@ -251,7 +251,7 @@ func FeedAndPeek(timer) endfunc func Interrupt(timer) - call test_feedinput("\") + eval "\"->test_feedinput() endfunc func Test_timer_peek_and_get_char() diff --git a/src/testdir/test_viminfo.vim b/src/testdir/test_viminfo.vim --- a/src/testdir/test_viminfo.vim +++ b/src/testdir/test_viminfo.vim @@ -171,7 +171,7 @@ func Test_cmdline_history_order() call histdel(':') " items go before and after - call test_settime(8) + eval 8->test_settime() call histadd(':', "echo '8'") call test_settime(39) call histadd(':', "echo '39'") diff --git a/src/testdir/test_vimscript.vim b/src/testdir/test_vimscript.vim --- a/src/testdir/test_vimscript.vim +++ b/src/testdir/test_vimscript.vim @@ -1596,7 +1596,7 @@ func Test_refcount() call assert_equal(1, test_refcount(x)) let x = {} - call assert_equal(1, test_refcount(x)) + call assert_equal(1, x->test_refcount()) let x = 0zff call assert_equal(1, test_refcount(x)) diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim --- a/src/testdir/test_window_cmd.vim +++ b/src/testdir/test_window_cmd.vim @@ -485,7 +485,7 @@ func Test_window_newtab() wincmd T call assert_equal(2, tabpagenr('$')) call assert_equal(['Xb', 'Xa'], map(tabpagebuflist(1), 'bufname(v:val)')) - call assert_equal(['Xc' ], map(tabpagebuflist(2), 'bufname(v:val)')) + call assert_equal(['Xc' ], map(2->tabpagebuflist(), 'bufname(v:val)')) %bw! endfunc @@ -598,8 +598,11 @@ endfunc func Fun_RenewFile() " Need to wait a bit for the timestamp to be older. - sleep 2 - silent execute '!echo "1" > tmp.txt' + let old_ftime = getftime("tmp.txt") + while getftime("tmp.txt") == old_ftime + sleep 100m + silent execute '!echo "1" > tmp.txt' + endwhile sp wincmd p edit! tmp.txt @@ -835,7 +838,7 @@ func Test_winnr() tabnew call assert_equal(8, tabpagewinnr(1, 'j')) - call assert_equal(2, tabpagewinnr(1, 'k')) + call assert_equal(2, 1->tabpagewinnr('k')) call assert_equal(4, tabpagewinnr(1, 'h')) call assert_equal(6, tabpagewinnr(1, 'l')) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -758,6 +758,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2011, +/**/ 2010, /**/ 2009,