fun! SPTest()
call searchpair('(','',')','bcW','Skip()')
// ^
endfun
func! Skip()
let res= synIDattr(synID(line('.'), col('.'), 0),'name') =~?
'string\|comment\|character'
echo col('.').'|'.res
return res
endfun
finish
void fun( /*)*/text())
// fp^ ^
// vim:ft=c
--------%<------------------
I don't understand the behaviour of this code. When the cursor is on 'text'
and I call SPTest() the cursor does not move. But if I remove the 'c'
flag from
searchpair(), it does so to the first paren.
As I understand it, the 'c' flag means : A match at the cursorposition
satisfies
the searchcondition. If there is no such match, act like w/o the 'c' flag.
So I would expect that this code, with the cursor on `text'
would do exactly the same with or without 'c'.
What's the problem ?
-ap
>--------%<------------------
>"source this
>
>fun! SPTest()
> call searchpair('(','',')','bcW','Skip()')
> " ^
>endfun
>func! Skip()
> let res= synIDattr(synID(line('.'), col('.'), 0),'name') =~?
>'string\|comment\|character'
> echo col('.').'|'.res
> return res
>endfun
>
>finish
>void fun( /*)*/text())
>" fp^ ^
searchpair() searches backwards until it hits the paren in
/*)*/. It skips it (because of Skip()) and then starts
searching again at that point. The `c' in your flags causes
it to match at the same position again; and because the
cursor hasn't moved since the first match searchpair() bails
out. I would have expected it to carry on searching too. --Antony
In other words, a skipped match is still a match.
Thanks Antony.
It works the same in the most simple case :
f( g() )
^p1 p2^
On position p1:
call searchpair('(','',')','c') does not move the cursor.
On position p2:
call searchpair('(','',')','cb') does not move the cursor.
-ap
Yes, searchpair() searches, moves the cursor if a match is
found, and then checks the skip function. However I wonder
if you have found a bug. I reckon that `c' in the flags
should only affect the initial cursor position. I have
neither source code nor compiler to hand, but maybe removing
`c' from the flags sometime after searchpair() first calls
searchit() would fix that. --Antony
This is the behaviour at least in this case :
:set wrapscan
f(a,b,c,d)
Cursor on a comma and
call searchpair('(',',',')','r')
-ap