diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-09-08 21:51:41 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-09-08 21:51:41 +0200 |
commit | f92e58cadb03156879e9bdbf6341bf662d9c87cc (patch) | |
tree | 13bdd750b1d0c9db7f2267d2300eba24f6560619 /src | |
parent | 7ee80f766130f22598c928415c92ec612a8f18cf (diff) | |
download | vim-git-f92e58cadb03156879e9bdbf6341bf662d9c87cc.tar.gz |
patch 8.1.2013: more functions can be used as methodsv8.1.2013
Problem: More functions can be used as methods.
Solution: Make various functions usable as a method.
Diffstat (limited to 'src')
-rw-r--r-- | src/evalfunc.c | 46 | ||||
-rw-r--r-- | src/testdir/test_cursor_func.vim | 2 | ||||
-rw-r--r-- | src/testdir/test_execute_func.vim | 2 | ||||
-rw-r--r-- | src/testdir/test_functions.vim | 13 | ||||
-rw-r--r-- | src/testdir/test_listchars.vim | 2 | ||||
-rw-r--r-- | src/testdir/test_timers.vim | 8 | ||||
-rw-r--r-- | src/testdir/test_undo.vim | 2 | ||||
-rw-r--r-- | src/testdir/test_window_cmd.vim | 18 | ||||
-rw-r--r-- | src/testdir/test_window_id.vim | 17 | ||||
-rw-r--r-- | src/version.c | 2 |
10 files changed, 69 insertions, 43 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c index 7c53b0058..dafd3b6af 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -822,46 +822,46 @@ static funcentry_T global_functions[] = #endif {"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}, - {"timer_start", 2, 3, 0, f_timer_start}, - {"timer_stop", 1, 1, 0, f_timer_stop}, + {"timer_info", 0, 1, FEARG_1, f_timer_info}, + {"timer_pause", 2, 2, FEARG_1, f_timer_pause}, + {"timer_start", 2, 3, FEARG_1, f_timer_start}, + {"timer_stop", 1, 1, FEARG_1, f_timer_stop}, {"timer_stopall", 0, 0, 0, f_timer_stopall}, #endif - {"tolower", 1, 1, 0, f_tolower}, - {"toupper", 1, 1, 0, f_toupper}, - {"tr", 3, 3, 0, f_tr}, - {"trim", 1, 2, 0, f_trim}, + {"tolower", 1, 1, FEARG_1, f_tolower}, + {"toupper", 1, 1, FEARG_1, f_toupper}, + {"tr", 3, 3, FEARG_1, f_tr}, + {"trim", 1, 2, FEARG_1, f_trim}, #ifdef FEAT_FLOAT {"trunc", 1, 1, FEARG_1, f_trunc}, #endif {"type", 1, 1, FEARG_1, f_type}, - {"undofile", 1, 1, 0, f_undofile}, + {"undofile", 1, 1, FEARG_1, f_undofile}, {"undotree", 0, 0, 0, f_undotree}, {"uniq", 1, 3, FEARG_1, f_uniq}, {"values", 1, 1, FEARG_1, f_values}, - {"virtcol", 1, 1, 0, f_virtcol}, + {"virtcol", 1, 1, FEARG_1, f_virtcol}, {"visualmode", 0, 1, 0, f_visualmode}, {"wildmenumode", 0, 0, 0, f_wildmenumode}, - {"win_execute", 2, 3, 0, f_win_execute}, - {"win_findbuf", 1, 1, 0, f_win_findbuf}, - {"win_getid", 0, 2, 0, f_win_getid}, - {"win_gotoid", 1, 1, 0, f_win_gotoid}, - {"win_id2tabwin", 1, 1, 0, f_win_id2tabwin}, - {"win_id2win", 1, 1, 0, f_win_id2win}, - {"win_screenpos", 1, 1, 0, f_win_screenpos}, + {"win_execute", 2, 3, FEARG_2, f_win_execute}, + {"win_findbuf", 1, 1, FEARG_1, f_win_findbuf}, + {"win_getid", 0, 2, FEARG_1, f_win_getid}, + {"win_gotoid", 1, 1, FEARG_1, f_win_gotoid}, + {"win_id2tabwin", 1, 1, FEARG_1, f_win_id2tabwin}, + {"win_id2win", 1, 1, FEARG_1, f_win_id2win}, + {"win_screenpos", 1, 1, FEARG_1, f_win_screenpos}, {"winbufnr", 1, 1, FEARG_1, f_winbufnr}, {"wincol", 0, 0, 0, f_wincol}, - {"winheight", 1, 1, 0, f_winheight}, - {"winlayout", 0, 1, 0, f_winlayout}, + {"winheight", 1, 1, FEARG_1, f_winheight}, + {"winlayout", 0, 1, FEARG_1, f_winlayout}, {"winline", 0, 0, 0, f_winline}, - {"winnr", 0, 1, 0, f_winnr}, + {"winnr", 0, 1, FEARG_1, f_winnr}, {"winrestcmd", 0, 0, 0, f_winrestcmd}, - {"winrestview", 1, 1, 0, f_winrestview}, + {"winrestview", 1, 1, FEARG_1, f_winrestview}, {"winsaveview", 0, 0, 0, f_winsaveview}, - {"winwidth", 1, 1, 0, f_winwidth}, + {"winwidth", 1, 1, FEARG_1, f_winwidth}, {"wordcount", 0, 0, 0, f_wordcount}, - {"writefile", 2, 3, 0, f_writefile}, + {"writefile", 2, 3, FEARG_1, f_writefile}, {"xor", 2, 2, FEARG_1, f_xor}, }; diff --git a/src/testdir/test_cursor_func.vim b/src/testdir/test_cursor_func.vim index 66d5d035e..dc65fdca2 100644 --- a/src/testdir/test_cursor_func.vim +++ b/src/testdir/test_cursor_func.vim @@ -83,7 +83,7 @@ func Test_screenpos() call assert_equal({'row': winrow, \ 'col': wincol + 0, \ 'curscol': wincol + 7, - \ 'endcol': wincol + 7}, screenpos(winid, 1, 1)) + \ 'endcol': wincol + 7}, winid->screenpos(1, 1)) call assert_equal({'row': winrow, \ 'col': wincol + 13, \ 'curscol': wincol + 13, diff --git a/src/testdir/test_execute_func.vim b/src/testdir/test_execute_func.vim index f3d7e3730..f81a86b6a 100644 --- a/src/testdir/test_execute_func.vim +++ b/src/testdir/test_execute_func.vim @@ -91,7 +91,7 @@ func Test_win_execute() if has('textprop') let popupwin = popup_create('the popup win', {'line': 2, 'col': 3}) redraw - let line = win_execute(popupwin, 'echo getline(1)') + let line = 'echo getline(1)'->win_execute(popupwin) call assert_match('the popup win', line) call popup_close(popupwin) diff --git a/src/testdir/test_functions.vim b/src/testdir/test_functions.vim index 4c6d2a89f..2e051bb26 100644 --- a/src/testdir/test_functions.vim +++ b/src/testdir/test_functions.vim @@ -266,7 +266,7 @@ endfunc func s:normalize_fname(fname) let ret = substitute(a:fname, '\', '/', 'g') let ret = substitute(ret, '//', '/', 'g') - return tolower(ret) + return ret->tolower() endfunc func Test_resolve_win32() @@ -505,7 +505,7 @@ func Test_toupper() \ toupper(' !"#$%&''()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~')) " Test with a few lowercase diacritics. - call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", toupper("aàáâãäåāăąǎǟǡả")) + call assert_equal("AÀÁÂÃÄÅĀĂĄǍǞǠẢ", "aàáâãäåāăąǎǟǡả"->toupper()) call assert_equal("BḂḆ", toupper("bḃḇ")) call assert_equal("CÇĆĈĊČ", toupper("cçćĉċč")) call assert_equal("DĎĐḊḎḐ", toupper("dďđḋḏḑ")) @@ -568,6 +568,11 @@ func Test_toupper() call toupper("123\xC0\x80\xC0") endfunc +func Test_tr() + call assert_equal('foo', tr('bar', 'bar', 'foo')) + call assert_equal('zxy', 'cab'->tr('abc', 'xyz')) +endfunc + " Tests for the mode() function let current_modes = '' func Save_mode() @@ -1203,7 +1208,7 @@ endfunc func Test_trim() call assert_equal("Testing", trim(" \t\r\r\x0BTesting \t\n\r\n\t\x0B\x0B")) - call assert_equal("Testing", trim(" \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B")) + call assert_equal("Testing", " \t \r\r\n\n\x0BTesting \t\n\r\n\t\x0B\x0B"->trim()) call assert_equal("RESERVE", trim("xyz \twwRESERVEzyww \t\t", " wxyz\t")) call assert_equal("wRE \tSERVEzyww", trim("wRE \tSERVEzyww")) call assert_equal("abcd\t xxxx tail", trim(" \tabcd\t xxxx tail")) @@ -1617,7 +1622,7 @@ func Test_bufadd_bufload() call assert_equal([''], getbufline(buf, 1, '$')) let curbuf = bufnr('') - call writefile(['some', 'text'], 'XotherName') + eval ['some', 'text']->writefile('XotherName') let buf = 'XotherName'->bufadd() call assert_notequal(0, buf) eval 'XotherName'->bufexists()->assert_equal(1) diff --git a/src/testdir/test_listchars.vim b/src/testdir/test_listchars.vim index a304c53d1..987ed661d 100644 --- a/src/testdir/test_listchars.vim +++ b/src/testdir/test_listchars.vim @@ -25,7 +25,7 @@ func Test_listchars() redraw! for i in range(1, 5) call cursor(i, 1) - call assert_equal([expected[i - 1]], ScreenLines(i, virtcol('$'))) + call assert_equal([expected[i - 1]], ScreenLines(i, '$'->virtcol())) endfor set listchars-=trail:< diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim index 261be278d..a6a36f793 100644 --- a/src/testdir/test_timers.vim +++ b/src/testdir/test_timers.vim @@ -71,7 +71,7 @@ endfunc func Test_timer_info() let id = timer_start(1000, 'MyHandler') - let info = timer_info(id) + let info = id->timer_info() call assert_equal(id, info[0]['id']) call assert_equal(1000, info[0]['time']) call assert_true(info[0]['remaining'] > 500) @@ -109,7 +109,7 @@ func Test_timer_paused() let info = timer_info(id) call assert_equal(0, info[0]['paused']) - call timer_pause(id, 1) + eval id->timer_pause(1) let info = timer_info(id) call assert_equal(1, info[0]['paused']) sleep 100m @@ -149,7 +149,7 @@ func Test_timer_delete_myself() endfunc func StopTimer1(timer) - let g:timer2 = timer_start(10, 'StopTimer2') + let g:timer2 = 10->timer_start('StopTimer2') " avoid maxfuncdepth error call timer_pause(g:timer1, 1) sleep 20m @@ -262,7 +262,7 @@ func Test_timer_peek_and_get_char() let intr = timer_start(100, 'Interrupt') let c = getchar() call assert_equal(char2nr('a'), c) - call timer_stop(intr) + eval intr->timer_stop() endfunc func Test_timer_getchar_zero() diff --git a/src/testdir/test_undo.vim b/src/testdir/test_undo.vim index 5154b20b3..c42427306 100644 --- a/src/testdir/test_undo.vim +++ b/src/testdir/test_undo.vim @@ -456,7 +456,7 @@ funct Test_undofile() call delete('Xundodir', 'd') " Test undofile() with 'undodir' set to a non-existing directory. - call assert_equal('', undofile('Xundofoo')) + call assert_equal('', 'Xundofoo'->undofile()) if isdirectory('/tmp') set undodir=/tmp diff --git a/src/testdir/test_window_cmd.vim b/src/testdir/test_window_cmd.vim index f2a9f1797..9bdae2c68 100644 --- a/src/testdir/test_window_cmd.vim +++ b/src/testdir/test_window_cmd.vim @@ -72,7 +72,7 @@ endfunc func Test_window_quit() e Xa split Xb - call assert_equal(2, winnr('$')) + call assert_equal(2, '$'->winnr()) call assert_equal('Xb', bufname(winbufnr(1))) call assert_equal('Xa', bufname(winbufnr(2))) @@ -88,7 +88,7 @@ func Test_window_horizontal_split() 3wincmd s call assert_equal(2, winnr('$')) call assert_equal(3, winheight(0)) - call assert_equal(winwidth(1), winwidth(2)) + call assert_equal(winwidth(1), 2->winwidth()) call assert_fails('botright topleft wincmd s', 'E442:') bw @@ -300,7 +300,7 @@ func Test_window_height() wincmd + call assert_equal(wh1, winheight(1)) - call assert_equal(wh2, winheight(2)) + call assert_equal(wh2, 2->winheight()) 2wincmd _ call assert_equal(2, winheight(1)) @@ -845,4 +845,16 @@ func Test_winnr() only | tabonly endfunc +func Test_winrestview() + split runtest.vim + normal 50% + let view = winsaveview() + close + split runtest.vim + eval view->winrestview() + call assert_equal(view, winsaveview()) + + bwipe! +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/testdir/test_window_id.vim b/src/testdir/test_window_id.vim index d10d83165..8bf4ede35 100644 --- a/src/testdir/test_window_id.vim +++ b/src/testdir/test_window_id.vim @@ -67,7 +67,7 @@ func Test_win_getid() call win_gotoid(id2) call assert_equal("two", expand("%")) - call win_gotoid(id4) + eval id4->win_gotoid() call assert_equal("four", expand("%")) call win_gotoid(id1) call assert_equal("one", expand("%")) @@ -75,17 +75,17 @@ func Test_win_getid() call assert_equal("five", expand("%")) call assert_equal(0, win_id2win(9999)) - call assert_equal(nr5, win_id2win(id5)) + call assert_equal(nr5, id5->win_id2win()) call assert_equal(0, win_id2win(id1)) tabnext call assert_equal(nr1, win_id2win(id1)) call assert_equal([0, 0], win_id2tabwin(9999)) - call assert_equal([1, nr2], win_id2tabwin(id2)) + call assert_equal([1, nr2], id2->win_id2tabwin()) call assert_equal([2, nr4], win_id2tabwin(id4)) call assert_equal([], win_findbuf(9999)) - call assert_equal([id2], win_findbuf(bufnr2)) + call assert_equal([id2], bufnr2->win_findbuf()) call win_gotoid(id5) split call assert_equal(sort([id5, win_getid()]), sort(win_findbuf(bufnr5))) @@ -98,7 +98,7 @@ func Test_win_getid_curtab() tabfirst copen only - call assert_equal(win_getid(1), win_getid(1, 1)) + call assert_equal(win_getid(1), 1->win_getid( 1)) tabclose! endfunc @@ -120,4 +120,11 @@ func Test_winlayout() call assert_equal(['col', [['leaf', w3], ['row', [['leaf', w4], ['leaf', w2]]], ['leaf', w1]]], winlayout()) only! + + let w1 = win_getid() + call assert_equal(['leaf', w1], winlayout(1)) + tabnew + let w2 = win_getid() + call assert_equal(['leaf', w2], 2->winlayout()) + tabclose endfunc diff --git a/src/version.c b/src/version.c index fee4ea3cd..d86f9f56d 100644 --- 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 */ /**/ + 2013, +/**/ 2012, /**/ 2011, |