To: vim_dev@googlegroups.com Subject: Patch 8.1.1911 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.1911 Problem: More functions can be used as methods. Solution: Make a few more functions usable as a method. Files: runtime/doc/eval.txt, src/evalfunc.c, src/testdir/test69.in, src/testdir/test69.ok, src/testdir/test_functions.vim *** ../vim-8.1.1910/runtime/doc/eval.txt 2019-08-21 22:49:48.107267870 +0200 --- runtime/doc/eval.txt 2019-08-22 22:11:23.442671324 +0200 *************** *** 3294,3300 **** for the current buffer. The first character has byte count one. Also see |line2byte()|, |go| and |:goto|. ! {not available when compiled without the |+byte_offset| feature} byteidx({expr}, {nr}) *byteidx()* --- 3299,3309 ---- for the current buffer. The first character has byte count one. Also see |line2byte()|, |go| and |:goto|. ! ! Can also be used as a |method|: > ! GetOffset()->byte2line() ! ! < {not available when compiled without the |+byte_offset| feature} byteidx({expr}, {nr}) *byteidx()* *************** *** 3318,3323 **** --- 3327,3335 ---- If there are exactly {nr} characters the length of the string in bytes is returned. + Can also be used as a |method|: > + GetName()->byteidx(idx) + byteidxcomp({expr}, {nr}) *byteidxcomp()* Like byteidx(), except that a composing character is counted as a separate character. Example: > *************** *** 3331,3336 **** --- 3343,3351 ---- Only works different from byteidx() when 'encoding' is set to a Unicode encoding. + Can also be used as a |method|: > + GetName()->byteidxcomp(idx) + call({func}, {arglist} [, {dict}]) *call()* *E699* Call function {func} with the items in |List| {arglist} as arguments. *************** *** 3340,3345 **** --- 3355,3363 ---- {dict} is for functions with the "dict" attribute. It will be used to set the local variable "self". |Dictionary-function| + Can also be used as a |method|: > + GetFunc()->call([arg, arg], dict) + ceil({expr}) *ceil()* Return the smallest integral value greater than or equal to {expr} as a |Float| (round up). *** ../vim-8.1.1910/src/evalfunc.c 2019-08-21 22:49:48.111267837 +0200 --- src/evalfunc.c 2019-08-22 22:10:20.251040789 +0200 *************** *** 466,475 **** {"bufnr", 1, 2, FEARG_1, f_bufnr}, {"bufwinid", 1, 1, FEARG_1, f_bufwinid}, {"bufwinnr", 1, 1, FEARG_1, f_bufwinnr}, ! {"byte2line", 1, 1, 0, f_byte2line}, ! {"byteidx", 2, 2, 0, f_byteidx}, ! {"byteidxcomp", 2, 2, 0, f_byteidxcomp}, ! {"call", 2, 3, 0, f_call}, #ifdef FEAT_FLOAT {"ceil", 1, 1, FEARG_1, f_ceil}, #endif --- 466,475 ---- {"bufnr", 1, 2, FEARG_1, f_bufnr}, {"bufwinid", 1, 1, FEARG_1, f_bufwinid}, {"bufwinnr", 1, 1, FEARG_1, f_bufwinnr}, ! {"byte2line", 1, 1, FEARG_1, f_byte2line}, ! {"byteidx", 2, 2, FEARG_1, f_byteidx}, ! {"byteidxcomp", 2, 2, FEARG_1, f_byteidxcomp}, ! {"call", 2, 3, FEARG_1, f_call}, #ifdef FEAT_FLOAT {"ceil", 1, 1, FEARG_1, f_ceil}, #endif *** ../vim-8.1.1910/src/testdir/test69.in 2014-06-12 18:32:43.000000000 +0200 --- src/testdir/test69.in 2019-08-22 22:09:52.079208660 +0200 *************** *** 165,185 **** x STARTTEST - :let a = '.é.' " one char of two bytes - :let b = '.é.' " normal e with composing char - /^byteidx - :put =string([byteidx(a, 0), byteidx(a, 1), byteidx(a, 2), byteidx(a, 3), byteidx(a, 4)]) - :put =string([byteidx(b, 0), byteidx(b, 1), byteidx(b, 2), byteidx(b, 3), byteidx(b, 4)]) - /^byteidxcomp - :put =string([byteidxcomp(a, 0), byteidxcomp(a, 1), byteidxcomp(a, 2), byteidxcomp(a, 3), byteidxcomp(a, 4)]) - :let b = '.é.' - :put =string([byteidxcomp(b, 0), byteidxcomp(b, 1), byteidxcomp(b, 2), byteidxcomp(b, 3), byteidxcomp(b, 4), byteidxcomp(b, 5)]) - ENDTEST - - byteidx - byteidxcomp - - STARTTEST /^substitute :let y = substitute('123', '\zs', 'a', 'g') | put =y ENDTEST --- 165,170 ---- *** ../vim-8.1.1910/src/testdir/test69.ok 2014-06-12 18:32:43.000000000 +0200 --- src/testdir/test69.ok 2019-08-22 22:09:45.559247798 +0200 *************** *** 153,166 **** áx - byteidx - [0, 1, 3, 4, -1] - [0, 1, 4, 5, -1] - byteidxcomp - [0, 1, 3, 4, -1] - [0, 1, 2, 4, 5, -1] - - substitute a1a2a3a --- 153,158 ---- *** ../vim-8.1.1910/src/testdir/test_functions.vim 2019-08-18 23:01:33.725885954 +0200 --- src/testdir/test_functions.vim 2019-08-22 22:15:33.609286182 +0200 *************** *** 872,878 **** set fileformat=mac call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], ! \ map(range(-1, 8), 'byte2line(v:val)')) call assert_equal([-1, -1, 1, 3, 6, 8, -1], \ map(range(-1, 5), 'line2byte(v:val)')) --- 872,878 ---- set fileformat=mac call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1], ! \ map(range(-1, 8), 'v:val->byte2line()')) call assert_equal([-1, -1, 1, 3, 6, 8, -1], \ map(range(-1, 5), 'line2byte(v:val)')) *************** *** 895,900 **** --- 895,928 ---- bw! endfunc + func Test_byteidx() + let a = '.é.' " one char of two bytes + call assert_equal(0, byteidx(a, 0)) + call assert_equal(0, byteidxcomp(a, 0)) + call assert_equal(1, byteidx(a, 1)) + call assert_equal(1, byteidxcomp(a, 1)) + call assert_equal(3, byteidx(a, 2)) + call assert_equal(3, byteidxcomp(a, 2)) + call assert_equal(4, byteidx(a, 3)) + call assert_equal(4, byteidxcomp(a, 3)) + call assert_equal(-1, byteidx(a, 4)) + call assert_equal(-1, byteidxcomp(a, 4)) + + let b = '.é.' " normal e with composing char + call assert_equal(0, b->byteidx(0)) + call assert_equal(1, b->byteidx(1)) + call assert_equal(4, b->byteidx(2)) + call assert_equal(5, b->byteidx(3)) + call assert_equal(-1, b->byteidx(4)) + + call assert_equal(0, b->byteidxcomp(0)) + call assert_equal(1, b->byteidxcomp(1)) + call assert_equal(2, b->byteidxcomp(2)) + call assert_equal(4, b->byteidxcomp(3)) + call assert_equal(5, b->byteidxcomp(4)) + call assert_equal(-1, b->byteidxcomp(5)) + endfunc + func Test_count() let l = ['a', 'a', 'A', 'b'] call assert_equal(2, count(l, 'a')) *************** *** 1506,1511 **** --- 1534,1540 ---- func Test_call() call assert_equal(3, call('len', [123])) + call assert_equal(3, 'len'->call([123])) call assert_fails("call call('len', 123)", 'E714:') call assert_equal(0, call('', [])) *************** *** 1513,1518 **** --- 1542,1548 ---- return len(self.data) endfunction let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")} + eval mydict.len->call([], mydict)->assert_equal(4) call assert_fails("call call('Mylen', [], 0)", 'E715:') endfunc *** ../vim-8.1.1910/src/version.c 2019-08-22 21:23:17.679357091 +0200 --- src/version.c 2019-08-22 22:16:25.997008422 +0200 *************** *** 763,764 **** --- 763,766 ---- { /* Add new patch number below this line */ + /**/ + 1911, /**/ -- hundred-and-one symptoms of being an internet addict: 96. On Super Bowl Sunday, you followed the score by going to the Yahoo main page instead of turning on the TV. /// 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 ///