Skip to content

Commit a144983

Browse files
committed
patch 8.1.1961: more functions can be used as a method
Problem: More functions can be used as a method. Solution: Allow more functions to be used as a method. Add a test for mapcheck().
1 parent db022f3 commit a144983

8 files changed

Lines changed: 110 additions & 28 deletions

File tree

runtime/doc/eval.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6699,6 +6699,8 @@ maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
66996699
mapped, and have it do the original mapping too. Sketch: >
67006700
exe 'nnoremap <Tab> ==' . maparg('<Tab>', 'n')
67016701
6702+
< Can also be used as a |method|: >
6703+
GetKey()->maparg('n')
67026704
67036705
mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
67046706
Check if there is a mapping that matches with {name} in mode
@@ -6733,6 +6735,9 @@ mapcheck({name} [, {mode} [, {abbr}]]) *mapcheck()*
67336735
< This avoids adding the "_vv" mapping when there already is a
67346736
mapping for "_v" or for "_vvv".
67356737

6738+
Can also be used as a |method|: >
6739+
GetKey()->mapcheck('n')
6740+
67366741
match({expr}, {pat} [, {start} [, {count}]]) *match()*
67376742
When {expr} is a |List| then this returns the index of the
67386743
first item where {pat} matches. Each item is used as a
@@ -6791,6 +6796,9 @@ match({expr}, {pat} [, {start} [, {count}]]) *match()*
67916796
the pattern. 'smartcase' is NOT used. The matching is always
67926797
done like 'magic' is set and 'cpoptions' is empty.
67936798

6799+
Can also be used as a |method|: >
6800+
GetList()->match('word')
6801+
<
67946802
*matchadd()* *E798* *E799* *E801* *E957*
67956803
matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
67966804
Defines a pattern to be highlighted in the current window (a
@@ -6846,6 +6854,9 @@ matchadd({group}, {pattern} [, {priority} [, {id} [, {dict}]]])
68466854
available from |getmatches()|. All matches can be deleted in
68476855
one operation by |clearmatches()|.
68486856

6857+
Can also be used as a |method|: >
6858+
GetGroup()->matchadd('TODO')
6859+
<
68496860
*matchaddpos()*
68506861
matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
68516862
Same as |matchadd()|, but requires a list of positions {pos}
@@ -6880,6 +6891,9 @@ matchaddpos({group}, {pos} [, {priority} [, {id} [, {dict}]]])
68806891
|getmatches()| with an entry "pos1", "pos2", etc., with the
68816892
value a list like the {pos} item.
68826893

6894+
Can also be used as a |method|: >
6895+
GetGroup()->matchaddpos([23, 11])
6896+
68836897
matcharg({nr}) *matcharg()*
68846898
Selects the {nr} match item, as set with a |:match|,
68856899
|:2match| or |:3match| command.
@@ -6892,6 +6906,9 @@ matcharg({nr}) *matcharg()*
68926906
Highlighting matches using the |:match| commands are limited
68936907
to three matches. |matchadd()| does not have this limitation.
68946908

6909+
Can also be used as a |method|: >
6910+
GetMatch()->matcharg()
6911+
68956912
matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
68966913
Deletes a match with ID {id} previously defined by |matchadd()|
68976914
or one of the |:match| commands. Returns 0 if successful,
@@ -6900,6 +6917,9 @@ matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
69006917
If {win} is specified, use the window with this number or
69016918
window ID instead of the current window.
69026919

6920+
Can also be used as a |method|: >
6921+
GetMatch()->matchdelete()
6922+
69036923
matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
69046924
Same as |match()|, but return the index of first character
69056925
after the match. Example: >
@@ -6919,6 +6939,9 @@ matchend({expr}, {pat} [, {start} [, {count}]]) *matchend()*
69196939
< result is "-1".
69206940
When {expr} is a |List| the result is equal to |match()|.
69216941

6942+
Can also be used as a |method|: >
6943+
GetText()->matchend('word')
6944+
69226945
matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
69236946
Same as |match()|, but return a |List|. The first item in the
69246947
list is the matched string, same as what matchstr() would
@@ -6929,6 +6952,9 @@ matchlist({expr}, {pat} [, {start} [, {count}]]) *matchlist()*
69296952
< Results in: ['acd', 'a', '', 'c', 'd', '', '', '', '', '']
69306953
When there is no match an empty list is returned.
69316954

6955+
Can also be used as a |method|: >
6956+
GetList()->matchlist('word')
6957+
69326958
matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
69336959
Same as |match()|, but return the matched string. Example: >
69346960
:echo matchstr("testing", "ing")
@@ -6942,6 +6968,9 @@ matchstr({expr}, {pat} [, {start} [, {count}]]) *matchstr()*
69426968
When {expr} is a |List| then the matching item is returned.
69436969
The type isn't changed, it's not necessarily a String.
69446970

6971+
Can also be used as a |method|: >
6972+
GetText()->matchstr('word')
6973+
69456974
matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
69466975
Same as |matchstr()|, but return the matched string, the start
69476976
position and the end position of the match. Example: >
@@ -6960,6 +6989,8 @@ matchstrpos({expr}, {pat} [, {start} [, {count}]]) *matchstrpos()*
69606989
< result is ["x", 1, 2, 3].
69616990
The type isn't changed, it's not necessarily a String.
69626991

6992+
Can also be used as a |method|: >
6993+
GetText()->matchstrpos('word')
69636994
*max()*
69646995
max({expr}) Return the maximum value of all items in {expr}.
69656996
{expr} can be a list or a dictionary. For a dictionary,
@@ -7010,6 +7041,9 @@ mkdir({name} [, {path} [, {prot}]])
70107041

70117042
Not available on all systems. To check use: >
70127043
:if exists("*mkdir")
7044+
7045+
< Can also be used as a |method|: >
7046+
GetName()->mkdir()
70137047
<
70147048
*mode()*
70157049
mode([expr]) Return a string that indicates the current mode.
@@ -7055,6 +7089,9 @@ mode([expr]) Return a string that indicates the current mode.
70557089
the leading character(s).
70567090
Also see |visualmode()|.
70577091

7092+
Can also be used as a |method|: >
7093+
DoFull()->mode()
7094+
70587095
mzeval({expr}) *mzeval()*
70597096
Evaluate MzScheme expression {expr} and return its result
70607097
converted to Vim data structures.
@@ -7069,6 +7106,9 @@ mzeval({expr}) *mzeval()*
70697106
:mz (define h (make-hash)) (hash-set! h "list" l)
70707107
:echo mzeval("l")
70717108
:echo mzeval("h")
7109+
<
7110+
Can also be used as a |method|: >
7111+
GetExpr()->mzeval()
70727112
<
70737113
{only available when compiled with the |+mzscheme| feature}
70747114

src/evalfunc.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -655,23 +655,23 @@ static funcentry_T global_functions[] =
655655
{"luaeval", 1, 2, FEARG_1, f_luaeval},
656656
#endif
657657
{"map", 2, 2, FEARG_1, f_map},
658-
{"maparg", 1, 4, 0, f_maparg},
659-
{"mapcheck", 1, 3, 0, f_mapcheck},
660-
{"match", 2, 4, 0, f_match},
661-
{"matchadd", 2, 5, 0, f_matchadd},
662-
{"matchaddpos", 2, 5, 0, f_matchaddpos},
663-
{"matcharg", 1, 1, 0, f_matcharg},
664-
{"matchdelete", 1, 2, 0, f_matchdelete},
665-
{"matchend", 2, 4, 0, f_matchend},
666-
{"matchlist", 2, 4, 0, f_matchlist},
667-
{"matchstr", 2, 4, 0, f_matchstr},
668-
{"matchstrpos", 2, 4, 0, f_matchstrpos},
658+
{"maparg", 1, 4, FEARG_1, f_maparg},
659+
{"mapcheck", 1, 3, FEARG_1, f_mapcheck},
660+
{"match", 2, 4, FEARG_1, f_match},
661+
{"matchadd", 2, 5, FEARG_1, f_matchadd},
662+
{"matchaddpos", 2, 5, FEARG_1, f_matchaddpos},
663+
{"matcharg", 1, 1, FEARG_1, f_matcharg},
664+
{"matchdelete", 1, 2, FEARG_1, f_matchdelete},
665+
{"matchend", 2, 4, FEARG_1, f_matchend},
666+
{"matchlist", 2, 4, FEARG_1, f_matchlist},
667+
{"matchstr", 2, 4, FEARG_1, f_matchstr},
668+
{"matchstrpos", 2, 4, FEARG_1, f_matchstrpos},
669669
{"max", 1, 1, FEARG_1, f_max},
670670
{"min", 1, 1, FEARG_1, f_min},
671-
{"mkdir", 1, 3, 0, f_mkdir},
672-
{"mode", 0, 1, 0, f_mode},
671+
{"mkdir", 1, 3, FEARG_1, f_mkdir},
672+
{"mode", 0, 1, FEARG_1, f_mode},
673673
#ifdef FEAT_MZSCHEME
674-
{"mzeval", 1, 1, 0, f_mzeval},
674+
{"mzeval", 1, 1, FEARG_1, f_mzeval},
675675
#endif
676676
{"nextnonblank", 1, 1, 0, f_nextnonblank},
677677
{"nr2char", 1, 2, 0, f_nr2char},

src/testdir/test70.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ STARTTEST
2525
:mz (vim-set-buff-line (vim-eval "line('.')") "1 changed line 1")
2626
:" scalar test
2727
:let tmp_string = mzeval('"string"')
28-
:let tmp_1000 = mzeval('1000')
28+
:let tmp_1000 = '1000'->mzeval()
2929
:if tmp_string . tmp_1000 == "string1000"
3030
:let scalar_res = "OK"
3131
:else

src/testdir/test_functions.vim

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -655,8 +655,8 @@ func Test_mode()
655655
exe "normal Rabc\<C-X>\<C-L>\<F2>\<Esc>u"
656656
call assert_equal('R-Rc', g:current_modes)
657657

658-
call assert_equal('n', mode(0))
659-
call assert_equal('n', mode(1))
658+
call assert_equal('n', 0->mode())
659+
call assert_equal('n', 1->mode())
660660

661661
" i_CTRL-O
662662
exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>"
@@ -793,7 +793,7 @@ endfunc
793793

794794
func Test_match_func()
795795
call assert_equal(4, match('testing', 'ing'))
796-
call assert_equal(4, match('testing', 'ing', 2))
796+
call assert_equal(4, 'testing'->match('ing', 2))
797797
call assert_equal(-1, match('testing', 'ing', 5))
798798
call assert_equal(-1, match('testing', 'ing', 8))
799799
call assert_equal(1, match(['vim', 'testing', 'execute'], 'ing'))
@@ -802,7 +802,7 @@ endfunc
802802

803803
func Test_matchend()
804804
call assert_equal(7, matchend('testing', 'ing'))
805-
call assert_equal(7, matchend('testing', 'ing', 2))
805+
call assert_equal(7, 'testing'->matchend('ing', 2))
806806
call assert_equal(-1, matchend('testing', 'ing', 5))
807807
call assert_equal(-1, matchend('testing', 'ing', 8))
808808
call assert_equal(match(['vim', 'testing', 'execute'], 'ing'), matchend(['vim', 'testing', 'execute'], 'ing'))
@@ -811,13 +811,13 @@ endfunc
811811

812812
func Test_matchlist()
813813
call assert_equal(['acd', 'a', '', 'c', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)'))
814-
call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2))
814+
call assert_equal(['d', '', '', '', 'd', '', '', '', '', ''], 'acd'->matchlist('\(a\)\?\(b\)\?\(c\)\?\(.*\)', 2))
815815
call assert_equal([], matchlist('acd', '\(a\)\?\(b\)\?\(c\)\?\(.*\)', 4))
816816
endfunc
817817

818818
func Test_matchstr()
819819
call assert_equal('ing', matchstr('testing', 'ing'))
820-
call assert_equal('ing', matchstr('testing', 'ing', 2))
820+
call assert_equal('ing', 'testing'->matchstr('ing', 2))
821821
call assert_equal('', matchstr('testing', 'ing', 5))
822822
call assert_equal('', matchstr('testing', 'ing', 8))
823823
call assert_equal('testing', matchstr(['vim', 'testing', 'execute'], 'ing'))
@@ -826,7 +826,7 @@ endfunc
826826

827827
func Test_matchstrpos()
828828
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing'))
829-
call assert_equal(['ing', 4, 7], matchstrpos('testing', 'ing', 2))
829+
call assert_equal(['ing', 4, 7], 'testing'->matchstrpos('ing', 2))
830830
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 5))
831831
call assert_equal(['', -1, -1], matchstrpos('testing', 'ing', 8))
832832
call assert_equal(['ing', 1, 4, 7], matchstrpos(['vim', 'testing', 'execute'], 'ing'))

src/testdir/test_getcwd.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function SetUp()
3535
" we start from a clean state.
3636
call delete("Xtopdir", "rf")
3737
new
38-
call mkdir('Xtopdir')
38+
eval 'Xtopdir'->mkdir()
3939
cd Xtopdir
4040
let g:topdir = getcwd()
4141
call mkdir('Xdir1')

src/testdir/test_maparg.vim

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
" Tests for maparg().
22
" Also test utf8 map with a 0x80 byte.
3+
" Also test mapcheck()
34

45
function s:SID()
56
return str2nr(matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$'))
@@ -22,7 +23,7 @@ function Test_maparg()
2223
call assert_equal({'silent': 1, 'noremap': 1, 'lhs': 'bar', 'mode': 'v',
2324
\ 'nowait': 0, 'expr': 1, 'sid': sid, 'lnum': lnum + 2,
2425
\ 'rhs': 'isbar', 'buffer': 1},
25-
\ maparg('bar', '', 0, 1))
26+
\ 'bar'->maparg('', 0, 1))
2627
let lnum = expand('<sflnum>')
2728
map <buffer> <nowait> foo bar
2829
call assert_equal({'silent': 0, 'noremap': 0, 'lhs': 'foo', 'mode': ' ',
@@ -46,6 +47,45 @@ function Test_maparg()
4647
unmap abc
4748
endfunction
4849

50+
func Test_mapcheck()
51+
call assert_equal('', mapcheck('a'))
52+
call assert_equal('', mapcheck('abc'))
53+
call assert_equal('', mapcheck('ax'))
54+
call assert_equal('', mapcheck('b'))
55+
56+
map a something
57+
call assert_equal('something', mapcheck('a'))
58+
call assert_equal('something', mapcheck('a', 'n'))
59+
call assert_equal('', mapcheck('a', 'c'))
60+
call assert_equal('', mapcheck('a', 'i'))
61+
call assert_equal('something', 'abc'->mapcheck())
62+
call assert_equal('something', 'ax'->mapcheck())
63+
call assert_equal('', mapcheck('b'))
64+
unmap a
65+
66+
map ab foobar
67+
call assert_equal('foobar', mapcheck('a'))
68+
call assert_equal('foobar', mapcheck('abc'))
69+
call assert_equal('', mapcheck('ax'))
70+
call assert_equal('', mapcheck('b'))
71+
unmap ab
72+
73+
map abc barfoo
74+
call assert_equal('barfoo', mapcheck('a'))
75+
call assert_equal('barfoo', mapcheck('a', 'n', 0))
76+
call assert_equal('', mapcheck('a', 'n', 1))
77+
call assert_equal('barfoo', mapcheck('abc'))
78+
call assert_equal('', mapcheck('ax'))
79+
call assert_equal('', mapcheck('b'))
80+
unmap abc
81+
82+
abbr ab abbrev
83+
call assert_equal('abbrev', mapcheck('a', 'i', 1))
84+
call assert_equal('', mapcheck('a', 'n', 1))
85+
call assert_equal('', mapcheck('a', 'i', 0))
86+
unabbr ab
87+
endfunc
88+
4989
function Test_range_map()
5090
new
5191
" Outside of the range, minimum

src/testdir/test_match.vim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function Test_match()
1515
2match MyGroup2 /FIXME/
1616
3match MyGroup3 /XXX/
1717
call assert_equal(['MyGroup1', 'TODO'], matcharg(1))
18-
call assert_equal(['MyGroup2', 'FIXME'], matcharg(2))
18+
call assert_equal(['MyGroup2', 'FIXME'], 2->matcharg())
1919
call assert_equal(['MyGroup3', 'XXX'], matcharg(3))
2020

2121
" --- Check that "matcharg()" returns an empty list if the argument is not 1,
@@ -44,7 +44,7 @@ function Test_match()
4444
" --- Check that "matchdelete()" deletes the matches defined in the previous
4545
" --- test correctly.
4646
call matchdelete(m1)
47-
call matchdelete(m2)
47+
eval m2->matchdelete()
4848
call matchdelete(m3)
4949
call assert_equal([], getmatches())
5050

@@ -56,7 +56,7 @@ function Test_match()
5656
" --- Check that "clearmatches()" clears all matches defined by ":match" and
5757
" --- "matchadd()".
5858
let m1 = matchadd("MyGroup1", "TODO")
59-
let m2 = matchadd("MyGroup2", "FIXME", 42)
59+
let m2 = "MyGroup2"->matchadd("FIXME", 42)
6060
let m3 = matchadd("MyGroup3", "XXX", 60, 17)
6161
match MyGroup1 /COFFEE/
6262
2match MyGroup2 /HUMPPA/
@@ -118,7 +118,7 @@ function Test_match()
118118
call clearmatches()
119119

120120
call setline(1, 'abcdΣabcdef')
121-
call matchaddpos("MyGroup1", [[1, 4, 2], [1, 9, 2]])
121+
eval "MyGroup1"->matchaddpos([[1, 4, 2], [1, 9, 2]])
122122
1
123123
redraw!
124124
let v1 = screenattr(1, 1)

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1961,
764766
/**/
765767
1960,
766768
/**/

0 commit comments

Comments
 (0)