On Monday, October 1, 2012 9:10:58 AM UTC-5, Silas Silva wrote:
> On Fri, Sep 28, 2012 at 03:52:40PM -0300, Silas Silva wrote:
>
> > One of my needs was to highlight tags that don't match its closing tag.
>
> > For example:
>
> >
>
> > <foo> text <bar> text </foo> text </bar>
>
> >
>
> > It should highlight the first <foo></bar> pair, since they don't match.
>
>
>
> A not complete workable way I found is having the following syntax
>
> rules:
>
>
>
> syn match wrongTag "</[a-z]*>" contained
>
> syn region myRegion start='<\z(\w*\)>' end='</\(\z1\)>' contains=wrongTag keepend
>
>
>
> hi def link wrongTag Error
>
>
>
> The problem is that it doesn't only matches wrong tags inside myRegion
>
> but also the closing tag of the region. How to make it not match the
>
> closing tag?
>
>
>
I don't think you're going to have much success with this exercise.
Handling an arbitrary level of balanced matched pairs with regular expressions is not a solvable problem, which is why I haven't responded before. Handling a limited level is solvable but extremely ugly.
That said, you're not necessarily trying to do arbitrary matched-pair matching.
I don't know enough about how your updates handle the highlighting of the tags themselves, but perhaps you can adjust the end of the match using pattern offsets, or the \ze item in the pattern? :he :syn-pattern-offset, :he /\ze
If you do something like "end='\ze</\z1>'" then your myRegion match will end just before the final closing tag, and wrongTag can then not possibly match it. Then you can use a nextgroup (:he :syn-nextgroup) if needed to highlight the correct end-tag.
But I'm not convinced your method will work. At the very least, you're going to need to use the "extend" keyword to allow nesting:
<div> <!-- start of first myRegion -->
<p>blah blah blah</p>
<div> <!-- start of second myRegion -->
<p>blah blah blah</p>
<p>blah blah blah</p>
</div> <!-- end of both myRegions if you don't use "extend" -->
<p>blah blah blah</p>
</div> <!-- intended end of first myRegion -->
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Monday, October 1, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment