Hello, I'm trying to enable spell checking for the contents of some tags in a (custom dialect of) XML, e.g. I have something like this:
<?xml version="1.0"?>
<foo>
<bar>notatext</bar>
<text>Some text I'd like to spell check</text>
</foo>
and would like spelling mistakes be highlighted inside <text> but not
inside <bar> (and not anywhere else, so e.g. "syn spell toplevel" is not a
solution).
My first attempt to do it was
syn region xmlString start="<text>\zs" end="\ze</text>" \
contains=xmlEntity,@Spell
but for some reason this doesn't work and I just can't understand why. It
seems to be somehow related to the definition of xmlTagName in
$VIMRUNTIME/syntax/xml.vim because the above does work in non-XML files.
I also tried
syn match xmlString "<text>\zs\_[^<]\+\ze</text>"\
contains=xmlEntity,@Spell
but this failed to work too. Does anybody have any idea why?
My second attempt was
syn region xmlString start="\(<text>\)\@<=" end="\(</text>\)\...@=" \
contains=xmlEntity,@Spell
which does work, i.e. it correctly highlights the tags contents as strings
and does detect spelling errors. Unfortunately it also makes Vim unusably
slow, presumably because it tries to match "" following \@<= everywhere.
So my final version is
syn region xmlString start="\(<text>\)\@<=[A-Z]" \
end="\(</text>\)\...@=" contains=xmlEntity,@Spell
which relies on the fact that text in my XML files usually starts with a
upper-case letter and, as there are not that many upper-case letters in XML
file, this works reasonably fast -- although still noticeably slower than
without this definition.
Can anyone suggest a better way of doing this? It looks like "\zs" is
exactly what I need here but I just can't make it work unfortunately
(tested in Vim 7.0 and 7.2 under Windows and 7.1 under Linux, the behaviour
is the same everywhere).
Thanks in advance for any hints!
VZ
pgpmEuuRoVxR0.pgp
Description: PGP signature
