To: vim_dev@googlegroups.com Subject: Patch 8.1.1915 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1915 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_functions.vim, src/testdir/test_cd.vim, src/testdir/test_cindent.vim, src/testdir/test_match.vim, src/testdir/test_popup.vim, src/testdir/test_cursor_func.vim, src/testdir/test_method.vim, src/testdir/test_bufline.vim, src/testdir/test_diffmode.vim *** ../vim-8.1.1914/runtime/doc/eval.txt 2019-08-23 20:58:42.024375479 +0200 --- runtime/doc/eval.txt 2019-08-23 22:15:35.094535196 +0200 *************** *** 3405,3410 **** --- 3410,3418 ---- let list = map(split(str, '\zs'), {_, val -> char2nr(val)}) < Result: [65, 66, 67] + Can also be used as a |method|: > + GetChar()->char2nr() + chdir({dir}) *chdir()* Change the current working directory to {dir}. The scope of the directory change depends on the directory of the current *************** *** 3425,3430 **** --- 3433,3441 ---- " ... do some work call chdir(save_dir) endif + + < Can also be used as a |method|: > + GetDir()->chdir() < cindent({lnum}) *cindent()* Get the amount of indent for line {lnum} according the C *************** *** 3435,3446 **** --- 3446,3463 ---- feature, -1 is returned. See |C-indenting|. + Can also be used as a |method|: > + GetLnum()->cindent() + clearmatches([{win}]) *clearmatches()* Clears all matches previously defined for the current window by |matchadd()| and the |:match| commands. 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|: > + GetWin()->clearmatches() + < *col()* col({expr}) The result is a Number, which is the byte index of the column position given with {expr}. The accepted positions are: *************** *** 3476,3481 **** --- 3493,3501 ---- \:set ve=all \:echo col(".") . "\n" \let &ve = save_ve + + < Can also be used as a |method|: > + GetPos()->col() < complete({startcol}, {matches}) *complete()* *E785* *************** *** 3507,3512 **** --- 3527,3536 ---- < This isn't very useful, but it shows how it works. Note that an empty string is returned to avoid a zero being inserted. + Can also be used as a |method|, the second argument is passed + in: > + GetMatches()->complete(col('.')) + complete_add({expr}) *complete_add()* Add {expr} to the list of matches. Only to be used by the function specified with the 'completefunc' option. *************** *** 3516,3521 **** --- 3540,3548 ---- See |complete-functions| for an explanation of {expr}. It is the same as one item in the list that 'omnifunc' would return. + Can also be used as a |method|: > + GetMoreMatches()->complete_add() + complete_check() *complete_check()* Check for a key typed while looking for completion matches. This is to be used when looking for matches takes some time. *************** *** 3576,3581 **** --- 3603,3611 ---- call complete_info(['mode']) " Get only 'mode' and 'pum_visible' call complete_info(['mode', 'pum_visible']) + + < Can also be used as a |method|: > + GetItems()->complete_info() < *confirm()* confirm({msg} [, {choices} [, {default} [, {type}]]]) *************** *** 3631,3636 **** --- 3661,3669 ---- don't fit, a vertical layout is used anyway. For some systems the horizontal layout is always used. + Can also be used as a |method|in: > + BuildMessage()->confirm("&Yes\n&No") + *copy()* copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't different from using {expr} directly. *************** *** 3760,3771 **** --- 3793,3810 ---- position within a or after the last character. Returns 0 when the position could be set, -1 otherwise. + Can also be used as a |method|: > + GetCursorPos()->cursor() + debugbreak({pid}) *debugbreak()* Specifically used to interrupt a program being debugged. It will cause process {pid} to get a SIGTRAP. Behavior for other processes is undefined. See |terminal-debugger|. {only available on MS-Windows} + Can also be used as a |method|: > + GetPid()->debugbreak() + deepcopy({expr} [, {noref}]) *deepcopy()* *E698* Make a copy of {expr}. For Numbers and Strings this isn't different from using {expr} directly. *************** *** 3787,3792 **** --- 3826,3834 ---- {noref} set to 1 will fail. Also see |copy()|. + Can also be used as a |method|: > + GetObject()->deepcopy() + delete({fname} [, {flags}]) *delete()* Without {flags} or with {flags} empty: Deletes the file by the name {fname}. This also works when {fname} is a symbolic link. *************** *** 3808,3813 **** --- 3850,3858 ---- To delete a line from the buffer use |:delete| or |deletebufline()|. + Can also be used as a |method|: > + GetName()->delete() + deletebufline({expr}, {first} [, {last}]) *deletebufline()* Delete lines {first} to {last} (inclusive) from buffer {expr}. If {last} is omitted then delete line {first} only. *************** *** 3819,3824 **** --- 3864,3872 ---- when using |line()| this refers to the current buffer. Use "$" to refer to the last line in buffer {expr}. + Can also be used as a |method|: > + GetBuffer()->deletebufline(1) + *did_filetype()* did_filetype() Returns |TRUE| when autocommands are being executed and the FileType event has been triggered at least once. Can be used *************** *** 3840,3845 **** --- 3888,3896 ---- line, "'m" mark m, etc. Returns 0 if the current window is not in diff mode. + Can also be used as a |method|: > + GetLnum()->diff_filler() + diff_hlID({lnum}, {col}) *diff_hlID()* Returns the highlight ID for diff mode at line {lnum} column {col} (byte index). When the current line does not have a *************** *** 3851,3856 **** --- 3902,3909 ---- The highlight ID can be used with |synIDattr()| to obtain syntax information about the highlighting. + Can also be used as a |method|: > + GetLnum()->diff_hlID(col) environ() *environ()* Return all of environment variables as dictionary. You can check if an environment variable exists like this: > *** ../vim-8.1.1914/src/evalfunc.c 2019-08-22 22:54:51.851603883 +0200 --- src/evalfunc.c 2019-08-23 22:15:54.970421248 +0200 *************** *** 494,509 **** {"ch_status", 1, 2, FEARG_1, f_ch_status}, #endif {"changenr", 0, 0, 0, f_changenr}, ! {"char2nr", 1, 2, 0, f_char2nr}, ! {"chdir", 1, 1, 0, f_chdir}, ! {"cindent", 1, 1, 0, f_cindent}, ! {"clearmatches", 0, 1, 0, f_clearmatches}, ! {"col", 1, 1, 0, f_col}, ! {"complete", 2, 2, 0, f_complete}, ! {"complete_add", 1, 1, 0, f_complete_add}, {"complete_check", 0, 0, 0, f_complete_check}, ! {"complete_info", 0, 1, 0, f_complete_info}, ! {"confirm", 1, 4, 0, f_confirm}, {"copy", 1, 1, FEARG_1, f_copy}, #ifdef FEAT_FLOAT {"cos", 1, 1, FEARG_1, f_cos}, --- 494,509 ---- {"ch_status", 1, 2, FEARG_1, f_ch_status}, #endif {"changenr", 0, 0, 0, f_changenr}, ! {"char2nr", 1, 2, FEARG_1, f_char2nr}, ! {"chdir", 1, 1, FEARG_1, f_chdir}, ! {"cindent", 1, 1, FEARG_1, f_cindent}, ! {"clearmatches", 0, 1, FEARG_1, f_clearmatches}, ! {"col", 1, 1, FEARG_1, f_col}, ! {"complete", 2, 2, FEARG_2, f_complete}, ! {"complete_add", 1, 1, FEARG_1, f_complete_add}, {"complete_check", 0, 0, 0, f_complete_check}, ! {"complete_info", 0, 1, FEARG_1, f_complete_info}, ! {"confirm", 1, 4, FEARG_1, f_confirm}, {"copy", 1, 1, FEARG_1, f_copy}, #ifdef FEAT_FLOAT {"cos", 1, 1, FEARG_1, f_cos}, *************** *** 511,526 **** #endif {"count", 2, 4, FEARG_1, f_count}, {"cscope_connection",0,3, 0, f_cscope_connection}, ! {"cursor", 1, 3, 0, f_cursor}, #ifdef MSWIN ! {"debugbreak", 1, 1, 0, f_debugbreak}, #endif ! {"deepcopy", 1, 2, 0, f_deepcopy}, ! {"delete", 1, 2, 0, f_delete}, ! {"deletebufline", 2, 3, 0, f_deletebufline}, {"did_filetype", 0, 0, 0, f_did_filetype}, ! {"diff_filler", 1, 1, 0, f_diff_filler}, ! {"diff_hlID", 2, 2, 0, f_diff_hlID}, {"empty", 1, 1, FEARG_1, f_empty}, {"environ", 0, 0, 0, f_environ}, {"escape", 2, 2, 0, f_escape}, --- 511,526 ---- #endif {"count", 2, 4, FEARG_1, f_count}, {"cscope_connection",0,3, 0, f_cscope_connection}, ! {"cursor", 1, 3, FEARG_1, f_cursor}, #ifdef MSWIN ! {"debugbreak", 1, 1, FEARG_1, f_debugbreak}, #endif ! {"deepcopy", 1, 2, FEARG_1, f_deepcopy}, ! {"delete", 1, 2, FEARG_1, f_delete}, ! {"deletebufline", 2, 3, FEARG_1, f_deletebufline}, {"did_filetype", 0, 0, 0, f_did_filetype}, ! {"diff_filler", 1, 1, FEARG_1, f_diff_filler}, ! {"diff_hlID", 2, 2, FEARG_1, f_diff_hlID}, {"empty", 1, 1, FEARG_1, f_empty}, {"environ", 0, 0, 0, f_environ}, {"escape", 2, 2, 0, f_escape}, *** ../vim-8.1.1914/src/testdir/test_functions.vim 2019-08-22 22:18:12.712452690 +0200 --- src/testdir/test_functions.vim 2019-08-23 22:11:20.448016484 +0200 *************** *** 1078,1084 **** call assert_equal(7, col('$')) call assert_equal(4, col("'x")) call assert_equal(6, col("'Y")) ! call assert_equal(2, col([1, 2])) call assert_equal(7, col([1, '$'])) call assert_equal(0, col('')) --- 1078,1084 ---- call assert_equal(7, col('$')) call assert_equal(4, col("'x")) call assert_equal(6, col("'Y")) ! call assert_equal(2, [1, 2]->col()) call assert_equal(7, col([1, '$'])) call assert_equal(0, col('')) *************** *** 1413,1419 **** call assert_equal(1, a) call feedkeys('y', 'L') ! let a = confirm('Are you sure?', "&Yes\n&No") call assert_equal(1, a) call feedkeys('n', 'L') --- 1413,1419 ---- call assert_equal(1, a) call feedkeys('y', 'L') ! let a = 'Are you sure?'->confirm("&Yes\n&No") call assert_equal(1, a) call feedkeys('n', 'L') *************** *** 1514,1520 **** let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) call assert_equal(1, len(files)) ! call delete('Xdir', 'rf') endfunc func Test_delete_rf() --- 1514,1520 ---- let files = readdir('Xdir', {x -> len(add(l, x)) == 2 ? -1 : 1}) call assert_equal(1, len(files)) ! eval 'Xdir'->delete('rf') endfunc func Test_delete_rf() *************** *** 1548,1553 **** --- 1548,1554 ---- func Test_char2nr() call assert_equal(12354, char2nr('あ', 1)) + call assert_equal(120, 'x'->char2nr()) endfunc func Test_eventhandler() *** ../vim-8.1.1914/src/testdir/test_cd.vim 2019-05-07 22:06:48.679310672 +0200 --- src/testdir/test_cd.vim 2019-08-23 21:26:31.828543589 +0200 *************** *** 85,91 **** call assert_equal('y', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) tabnext | wincmd t ! call chdir('..') call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) --- 85,91 ---- call assert_equal('y', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) tabnext | wincmd t ! eval '..'->chdir() call assert_equal('Xdir', fnamemodify(getcwd(1, 2), ':t')) call assert_equal('Xdir', fnamemodify(getcwd(2, 2), ':t')) call assert_equal('z', fnamemodify(getcwd(3, 2), ':t')) *** ../vim-8.1.1914/src/testdir/test_cindent.vim 2019-06-24 00:58:02.908020514 +0200 --- src/testdir/test_cindent.vim 2019-08-23 21:27:24.448299384 +0200 *************** *** 121,129 **** new setlocal cindent call setline(1, ['int main(void)', '{', 'return 0;', '}']) ! call assert_equal(cindent(0), -1) ! call assert_equal(cindent(3), &sw) ! call assert_equal(cindent(line('$')+1), -1) bwipe! endfunc --- 121,129 ---- new setlocal cindent call setline(1, ['int main(void)', '{', 'return 0;', '}']) ! call assert_equal(-1, cindent(0)) ! call assert_equal(&sw, 3->cindent()) ! call assert_equal(-1, cindent(line('$')+1)) bwipe! endfunc *** ../vim-8.1.1914/src/testdir/test_match.vim 2019-08-07 23:07:03.960858821 +0200 --- src/testdir/test_match.vim 2019-08-23 21:29:23.483653416 +0200 *************** *** 215,221 **** \] call assert_equal(expect, savematches) ! call clearmatches(winid) call assert_equal([], getmatches(winid)) call setmatches(savematches, winid) --- 215,221 ---- \] call assert_equal(expect, savematches) ! eval winid->clearmatches() call assert_equal([], getmatches(winid)) call setmatches(savematches, winid) *** ../vim-8.1.1914/src/testdir/test_popup.vim 2019-08-18 23:01:33.725885954 +0200 --- src/testdir/test_popup.vim 2019-08-23 21:41:23.210438265 +0200 *************** *** 250,256 **** func Test_noinsert_complete() func! s:complTest1() abort ! call complete(1, ['source', 'soundfold']) return '' endfunc --- 250,256 ---- func Test_noinsert_complete() func! s:complTest1() abort ! eval ['source', 'soundfold']->complete(1) return '' endfunc *************** *** 403,409 **** return 0 else call complete_add('four1') ! call complete_add('four2') call complete_check() call complete_add('four3') call complete_add('four4') --- 403,409 ---- return 0 else call complete_add('four1') ! eval 'four2'->complete_add() call complete_check() call complete_add('four3') call complete_add('four4') *************** *** 993,999 **** if empty(g:compl_what) let g:compl_info = complete_info() else ! let g:compl_info = complete_info(g:compl_what) endif return '' endfunc --- 993,999 ---- if empty(g:compl_what) let g:compl_info = complete_info() else ! let g:compl_info = g:compl_what->complete_info() endif return '' endfunc *** ../vim-8.1.1914/src/testdir/test_cursor_func.vim 2019-07-07 18:27:52.365277132 +0200 --- src/testdir/test_cursor_func.vim 2019-08-23 21:45:12.541054277 +0200 *************** *** 22,28 **** call cursor(3, 0) call assert_equal([3, 1, 0, 1], getcurpos()[1:]) " below last line goes to last line ! call cursor(9, 1) call assert_equal([4, 1, 0, 1], getcurpos()[1:]) call setline(1, ["\"]) --- 22,28 ---- call cursor(3, 0) call assert_equal([3, 1, 0, 1], getcurpos()[1:]) " below last line goes to last line ! eval [9, 1]->cursor() call assert_equal([4, 1, 0, 1], getcurpos()[1:]) call setline(1, ["\"]) *** ../vim-8.1.1914/src/testdir/test_method.vim 2019-08-17 21:04:12.806190044 +0200 --- src/testdir/test_method.vim 2019-08-23 22:10:00.776490083 +0200 *************** *** 8,13 **** --- 8,14 ---- eval l->assert_notequal([3, 2, 1]) eval l->assert_notequal([3, 2, 1], 'wrong') call assert_equal(l, l->copy()) + call assert_equal(l, l->deepcopy()) call assert_equal(1, l->count(2)) call assert_false(l->empty()) call assert_true([]->empty()) *************** *** 38,43 **** --- 39,45 ---- let d = #{one: 1, two: 2, three: 3} call assert_equal(d, d->copy()) + call assert_equal(d, d->deepcopy()) call assert_equal(1, d->count(2)) call assert_false(d->empty()) call assert_true({}->empty()) *** ../vim-8.1.1914/src/testdir/test_bufline.vim 2019-08-21 22:49:48.111267837 +0200 --- src/testdir/test_bufline.vim 2019-08-23 22:12:33.107589237 +0200 *************** *** 132,138 **** call assert_equal(0, deletebufline(b, 2, 8)) call assert_equal(['aaa'], getbufline(b, 1, 2)) exe "bd!" b ! call assert_equal(1, deletebufline(b, 1)) call assert_equal(1, deletebufline(-1, 1)) --- 132,138 ---- call assert_equal(0, deletebufline(b, 2, 8)) call assert_equal(['aaa'], getbufline(b, 1, 2)) exe "bd!" b ! call assert_equal(1, b->deletebufline(1)) call assert_equal(1, deletebufline(-1, 1)) *** ../vim-8.1.1914/src/testdir/test_diffmode.vim 2019-08-04 17:35:49.331707782 +0200 --- src/testdir/test_diffmode.vim 2019-08-23 22:15:50.686445793 +0200 *************** *** 674,680 **** call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText") call diff_hlID(2, 1)->synIDattr("name")->assert_equal("") call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd") ! call diff_hlID(4, 1)->synIDattr("name")->assert_equal("") wincmd w call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") --- 674,680 ---- call diff_hlID(1, 2)->synIDattr("name")->assert_equal("DiffText") call diff_hlID(2, 1)->synIDattr("name")->assert_equal("") call diff_hlID(3, 1)->synIDattr("name")->assert_equal("DiffAdd") ! eval 4->diff_hlID(1)->synIDattr("name")->assert_equal("") wincmd w call assert_equal(synIDattr(diff_hlID(1, 1), "name"), "DiffChange") *************** *** 693,699 **** diffthis redraw ! call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'diff_filler(v:val)')) wincmd w call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) --- 693,699 ---- diffthis redraw ! call assert_equal([0, 0, 0, 0, 0, 0, 0, 1, 0], map(range(-1, 7), 'v:val->diff_filler()')) wincmd w call assert_equal([0, 0, 0, 0, 2, 0, 0, 0], map(range(-1, 6), 'diff_filler(v:val)')) *** ../vim-8.1.1914/src/version.c 2019-08-23 21:17:30.651058449 +0200 --- src/version.c 2019-08-23 22:30:46.485434590 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1915, /**/ -- hundred-and-one symptoms of being an internet addict: 103. When you find yourself in the "Computer" section of Barnes & Noble enjoying yourself. /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///