0

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.

4

1 回答 1

1

当您集成到现有的(文件类型)语法中时,您必须考虑其结构;你不能只是把你的定义“放在首位”,并希望一切正常。当然,在编写像彩虹括号这样的通用插件功能时,这很困难。

我认为您必须将各种“异常”和特殊情况合并到您的插件中,或者转移到可用于突出显示的其他机制,即matchadd()/matchdelete()函数。不幸的是,您没有 的自动嵌套功能:syn region,因此可能很难实现。

于 2013-03-14T07:46:13.940 回答