0
votes

I am trying to color different levels of parentheses differently in vim -like rainbow parentheses. But I couldn't do it without breaking, for example, css highlighting.

Problem is that: syntax of whatever text goes into curly braces for a css file, very reasonably defined as "contained", like:

syn keyword cssColor contained aqua
syn region cssDefinition transparent start='{' end='}' contains=cssColor

With this definition, "aqua" keyword is highlighted if it's in the braces , but not otherwise.

Now, when I define regions for braces like:

syn region brace1 transparent contains=brace2
syn region brace2 transparent contained contains=brace3
syn region brace3 transparent contained contains=brace1

to be able to color them differently, I am breaking containment of cssColor by cssDefinition. saying contains ALL obviously not working.

So the question is, is it possible to write a code to get the elements that original syntax group for braces contain, and add them to freshly defined syntax groups? I know this doesn't make real sense for css files, but it does in general.

1

1 Answers

1
votes

When you integrate into an existing (filetype-) syntax, you have to consider its structure; you can't just put your definitions "on top" and hope all works. Of course, this is difficult when writing general plugin functionality like rainbow parentheses.

I think you have to incorporate all sorts of "exceptions" and special cases into your plugin, or move to the other mechanism that is available for highlighting, the matchadd() / matchdelete() functions. Unfortunately, there you don't have the automatic nesting functionality of :syn region, so it might be very difficult to implement.