主题 – Sublime Text – 修改tmTheme文件

在.tmTheme文件中:
<dict>
    <key>name</key>
    <string>Entity name</string>
    <key>scope</key>
    <string>entity.name - (entity.name.filename | entity.name.section | entity.name.tag | entity.name.label)</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string></string>
        <key>foreground</key>
        <string>#A6E22E</string>
    </dict>
</dict>

下一个范围字符串:

<string>entity.name - (entity.name.filename | entity.name.section | entity.name.tag | entity.name.label)</string>

是一种正则表达吗?什么适用于这个定义?在同一个文件的另一部分,我可以看到这样的东西:

<string>variable.parameter - (source.c | source.c++ | source.objc | source.objc++)</string>

解决方法

这不是一个正则表达;它是从TextMate借来的 scope selector.

it’s possible to AND,OR,and subtract scope selectors,e.g.: (a | b) & c - d would select the scope which is not matched by d,and matched by both c,and a or b.

在Sublime Text中,您可以通过转到“工具”菜单 – >找到光标右侧的字符范围.开发者 – >显示范围名称.

对于测试选择器,您可以在Sublime Text控制台(View菜单 – > Show Console)中使用view.match_selector或view.find_by_selector APIs.

查看第一个游标的范围是否与第一个示例中的选择器匹配的示例:

view.match_selector(view.sel()[0].begin(),'entity.name - (entity.name.filename | entity.name.section | entity.name.tag | entity.name.label)')

更多信息:

可以使用以下运算符:

> – :没有,范围内的任何地方(要清楚,这是一个由空格包围的短划线,因为短划线可以出现在范围名称的中间)
>&amp ;: with,范围内的任何地方(在.tmTheme文件中,为XML,&应该转义为& amp;,除非在CDATA节点内.)
>(空格):必须在前面的范围之后(即右边)
> |和,或者,范围内的任何地方
>(…)可用于将选择器组合在一起

笔记:

>范围应该只包含字母数字字符和点(.),因此永远不会发生与运算符的冲突.
>范围由单个空格分隔.
>操作符周围的空白区域不是必需的. (在评估之前修剪/剥离空白).即字符串|注释与字符串|注释相同.
>在评估范围选择器之前,前导点和尾随点也会被剥离
>连续的空格被视为单个空格.
>所有范围从一开始就匹配.范围选择器中没有通配符运算符.因此,您无法使用.python或* .python等匹配范围source.python.
>完全空的选择器匹配所有内容.但是当运算符跟着时却没有.即|它本身就会失败,因为它将会失败.源|然而,工作. – 和来源 – 将失败.
>如果您不确定运算符优先级,请将表达式的部分括在括号中,以使其清晰.但是,在分组后,您似乎需要使用除空格之外的运算符,否则将忽略分组后直接的范围.

例:

在下面的Python片段中,使用syntax test format,将通过所有测试,因此它可以作为选择器如何工作的演示:

a = "hello world" # comment
#   ^^^^^^^^^^^^^ string.quoted.double
#   ^^^^^^^^^^^^^ string
#   ^^^^^^^^^^^^^ string.quoted
#   ^^^^^^^^^^^^^ string.quoted.
#   ^^^^^^^^^^^^^ - quoted.double
#   ^^^^^^^^^^^^^ string - comment
#   ^^^^^^^^^^^^^ string,comment
#   ^^^^^^^^^^^^^ string | comment
#   ^^^^^^^^^^^^^ string & - comment
#   ^^^^^^^^^^^^^ string & - comment
#   ^^^^^^^^^^^^^ source string
#   ^^^^^^^^^^^^^ source & (string - comment)
#   ^^^^^^^^^^^^^ source - (string & comment)
#   ^^^^^^^^^^^^^ string & source
#   ^ source.python string.quoted.double.block.python punctuation.definition.string.begin.python
#   ^ source & string & punctuation.definition.string.begin.python
#   ^ string & punctuation & source
#   ^ string punctuation & source
#   ^ source punctuation & string
#   ^ source string punctuation - (punctuation string)
#   ^ string - source comment - punctuation source
#   ^ string - source comment - comment
#   ^ source - python
#   ^ source - (source & python)
#   ^ source - (source python)
#   ^ source.python - source.python.string
#   ^ source.python.. ..string..
#                 ^ comment - string
#                 ^ comment
#                 ^ comment,string
#   ^^^^^^^^^^^^^^^^^^^ comment,string | source
#   ^ (punctuation | string) & source.python - comment
#   ^ (punctuation & string) & source.python - comment

请注意,由于scope selector specificity似乎忽略了一些更高级的结构,您可能会发现使用范围选择器创建的.tmTheme规则适用或不适用于您可能不期望的情况.

相关文章

HTML代码中要想改变字体颜色,常常需要使用CSS样式表。CSS是...
HTML代码如何让字体盖住图片呢?需要使用CSS的position属性及...
HTML代码字体设置 在HTML中,我们可以使用标签来设置网页中的...
在网页设计中,HTML代码的字体和字号选择是非常重要的一个环...
HTML(Hypertext Markup Language,超文本标记语言)是一种用...
外链是指在一个网页中添加一个指向其他网站的链接,用户可以...