searchpair and multiline patterns

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

searchpair and multiline patterns

Doug Kearns
Hello folks,

:echo searchpair('\<start\>', '', '\%(\.\_s*\)\@<!\<end\>', 'W', 'getline(".") =~ "#.*"')

Doesn't work on this file:

----------
start
# skip me.
end
----------

since, I think, the '.' at the end of the skip me line is actually being
matched.

Any ideas? I suspect I'm missing something obvious given the hour but...

Thanks,
Doug
Reply | Threaded
Open this post in threaded view
|

Re: searchpair and multiline patterns

Tim Chase-2
> :echo searchpair('\<start\>', '', '\%(\.\_s*\)\@<!\<end\>', 'W', 'getline(".") =~ "#.*"')
[cut]
 > since, I think, the '.' at the end of the skip me line is
actually being
 > matched.

I tried your example, and by removing the period, it works fine.
  Putting it in causes the behavior you describe.

Your regexp:

        \%(\.\_s*\)\@<!

is explicitly prohibiting this "end" from being found.  My
understanding is that vim *first* looks for the else/end match,
and *then* attempts to disqualify it based on the "skip"
parameter (if at first you don't succeed, try, try again).  Thus,
vim is not finding the "end" in the first place because it
doesn't match your regexp.  The filter/skip is never checked
because the "end" match isn't found.

As for a work-around, I'm not sure.  I suspect you'd either have
to stop ensuring that your end-regexp checks for periods, or you
allow it, and then filter it out after the fact in the "skip"
portion.

Something like

echo searchpair('\<start\>', '', '\<end\>', 'nW', 'getline(".")
=~ "^\\s*#\\|\\.\\_s*end\\>"')

might do the trick for you.  It still has trouble with something
like:

___________

start
# fine fine fine
end # .end
___________

with both the "end" and the ".end" on the same line.

It would take a bit more munging of the regexps to get that to work.

-tim







Reply | Threaded
Open this post in threaded view
|

Re: searchpair and multiline patterns

Doug Kearns
On Thu, Sep 08, 2005 at 12:09:41PM -0500, Tim Chase wrote:

<snip>
 

> I tried your example, and by removing the period, it works fine.
>  Putting it in causes the behavior you describe.
>
> Your regexp:
>
> \%(\.\_s*\)\@<!
>
> is explicitly prohibiting this "end" from being found.  My
> understanding is that vim *first* looks for the else/end match,
> and *then* attempts to disqualify it based on the "skip"
> parameter (if at first you don't succeed, try, try again).  Thus,
> vim is not finding the "end" in the first place because it
> doesn't match your regexp.  The filter/skip is never checked
> because the "end" match isn't found.

I suspected I was misreading the documentation. Thanks very much for the
clarification.
 
<snip - useful workaround>

Thanks,
Doug