mirror of
https://github.com/vim/vim.git
synced 2025-10-01 04:54:07 -04:00
patch 8.1.1911: more functions can be used as methods
Problem: More functions can be used as methods. Solution: Make a few more functions usable as a method.
This commit is contained in:
@@ -3299,7 +3299,11 @@ byte2line({byte}) *byte2line()*
|
|||||||
for the current buffer. The first character has byte count
|
for the current buffer. The first character has byte count
|
||||||
one.
|
one.
|
||||||
Also see |line2byte()|, |go| and |:goto|.
|
Also see |line2byte()|, |go| and |:goto|.
|
||||||
{not available when compiled without the |+byte_offset|
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetOffset()->byte2line()
|
||||||
|
|
||||||
|
< {not available when compiled without the |+byte_offset|
|
||||||
feature}
|
feature}
|
||||||
|
|
||||||
byteidx({expr}, {nr}) *byteidx()*
|
byteidx({expr}, {nr}) *byteidx()*
|
||||||
@@ -3323,6 +3327,9 @@ byteidx({expr}, {nr}) *byteidx()*
|
|||||||
If there are exactly {nr} characters the length of the string
|
If there are exactly {nr} characters the length of the string
|
||||||
in bytes is returned.
|
in bytes is returned.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetName()->byteidx(idx)
|
||||||
|
|
||||||
byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
||||||
Like byteidx(), except that a composing character is counted
|
Like byteidx(), except that a composing character is counted
|
||||||
as a separate character. Example: >
|
as a separate character. Example: >
|
||||||
@@ -3336,6 +3343,9 @@ byteidxcomp({expr}, {nr}) *byteidxcomp()*
|
|||||||
Only works different from byteidx() when 'encoding' is set to
|
Only works different from byteidx() when 'encoding' is set to
|
||||||
a Unicode encoding.
|
a Unicode encoding.
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetName()->byteidxcomp(idx)
|
||||||
|
|
||||||
call({func}, {arglist} [, {dict}]) *call()* *E699*
|
call({func}, {arglist} [, {dict}]) *call()* *E699*
|
||||||
Call function {func} with the items in |List| {arglist} as
|
Call function {func} with the items in |List| {arglist} as
|
||||||
arguments.
|
arguments.
|
||||||
@@ -3345,6 +3355,9 @@ call({func}, {arglist} [, {dict}]) *call()* *E699*
|
|||||||
{dict} is for functions with the "dict" attribute. It will be
|
{dict} is for functions with the "dict" attribute. It will be
|
||||||
used to set the local variable "self". |Dictionary-function|
|
used to set the local variable "self". |Dictionary-function|
|
||||||
|
|
||||||
|
Can also be used as a |method|: >
|
||||||
|
GetFunc()->call([arg, arg], dict)
|
||||||
|
|
||||||
ceil({expr}) *ceil()*
|
ceil({expr}) *ceil()*
|
||||||
Return the smallest integral value greater than or equal to
|
Return the smallest integral value greater than or equal to
|
||||||
{expr} as a |Float| (round up).
|
{expr} as a |Float| (round up).
|
||||||
|
@@ -466,10 +466,10 @@ static funcentry_T global_functions[] =
|
|||||||
{"bufnr", 1, 2, FEARG_1, f_bufnr},
|
{"bufnr", 1, 2, FEARG_1, f_bufnr},
|
||||||
{"bufwinid", 1, 1, FEARG_1, f_bufwinid},
|
{"bufwinid", 1, 1, FEARG_1, f_bufwinid},
|
||||||
{"bufwinnr", 1, 1, FEARG_1, f_bufwinnr},
|
{"bufwinnr", 1, 1, FEARG_1, f_bufwinnr},
|
||||||
{"byte2line", 1, 1, 0, f_byte2line},
|
{"byte2line", 1, 1, FEARG_1, f_byte2line},
|
||||||
{"byteidx", 2, 2, 0, f_byteidx},
|
{"byteidx", 2, 2, FEARG_1, f_byteidx},
|
||||||
{"byteidxcomp", 2, 2, 0, f_byteidxcomp},
|
{"byteidxcomp", 2, 2, FEARG_1, f_byteidxcomp},
|
||||||
{"call", 2, 3, 0, f_call},
|
{"call", 2, 3, FEARG_1, f_call},
|
||||||
#ifdef FEAT_FLOAT
|
#ifdef FEAT_FLOAT
|
||||||
{"ceil", 1, 1, FEARG_1, f_ceil},
|
{"ceil", 1, 1, FEARG_1, f_ceil},
|
||||||
#endif
|
#endif
|
||||||
|
@@ -164,21 +164,6 @@ ENDTEST
|
|||||||
á
|
á
|
||||||
x
|
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
|
STARTTEST
|
||||||
/^substitute
|
/^substitute
|
||||||
:let y = substitute('123', '\zs', 'a', 'g') | put =y
|
:let y = substitute('123', '\zs', 'a', 'g') | put =y
|
||||||
|
@@ -153,14 +153,6 @@ aaa
|
|||||||
áx
|
á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
|
substitute
|
||||||
a1a2a3a
|
a1a2a3a
|
||||||
|
|
||||||
|
@@ -872,7 +872,7 @@ func Test_byte2line_line2byte()
|
|||||||
|
|
||||||
set fileformat=mac
|
set fileformat=mac
|
||||||
call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
|
call assert_equal([-1, -1, 1, 1, 2, 2, 2, 3, 3, -1],
|
||||||
\ map(range(-1, 8), 'byte2line(v:val)'))
|
\ map(range(-1, 8), 'v:val->byte2line()'))
|
||||||
call assert_equal([-1, -1, 1, 3, 6, 8, -1],
|
call assert_equal([-1, -1, 1, 3, 6, 8, -1],
|
||||||
\ map(range(-1, 5), 'line2byte(v:val)'))
|
\ map(range(-1, 5), 'line2byte(v:val)'))
|
||||||
|
|
||||||
@@ -895,6 +895,34 @@ func Test_byte2line_line2byte()
|
|||||||
bw!
|
bw!
|
||||||
endfunc
|
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()
|
func Test_count()
|
||||||
let l = ['a', 'a', 'A', 'b']
|
let l = ['a', 'a', 'A', 'b']
|
||||||
call assert_equal(2, count(l, 'a'))
|
call assert_equal(2, count(l, 'a'))
|
||||||
@@ -1506,6 +1534,7 @@ endfunc
|
|||||||
|
|
||||||
func Test_call()
|
func Test_call()
|
||||||
call assert_equal(3, call('len', [123]))
|
call assert_equal(3, call('len', [123]))
|
||||||
|
call assert_equal(3, 'len'->call([123]))
|
||||||
call assert_fails("call call('len', 123)", 'E714:')
|
call assert_fails("call call('len', 123)", 'E714:')
|
||||||
call assert_equal(0, call('', []))
|
call assert_equal(0, call('', []))
|
||||||
|
|
||||||
@@ -1513,6 +1542,7 @@ func Test_call()
|
|||||||
return len(self.data)
|
return len(self.data)
|
||||||
endfunction
|
endfunction
|
||||||
let mydict = {'data': [0, 1, 2, 3], 'len': function("Mylen")}
|
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:')
|
call assert_fails("call call('Mylen', [], 0)", 'E715:')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
@@ -761,6 +761,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1911,
|
||||||
/**/
|
/**/
|
||||||
1910,
|
1910,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user