Sublime Text - 修改tmTheme文件

Jai*_*nez 1 color-scheme themes sublimetext3

.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>
Run Code Online (Sandbox Code Playgroud)

下一个范围字符串:

<string>entity.name - (entity.name.filename | entity.name.section | entity.name.tag | entity.name.label)</string>
Run Code Online (Sandbox Code Playgroud)

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

<string>variable.parameter - (source.c | source.c++ | source.objc | source.objc++)</string>
Run Code Online (Sandbox Code Playgroud)

Kei*_*all 8

这不是一个正则表达; 它是从TextMate借来的范围选择器.

可以对范围选择器进行AND,OR和减法,例如:(a | b) & c - d选择与d不匹配的范围,并与c,a或b匹配.

在Sublime Text中,您可以通过Tools菜单 - > Developer- > 找到光标右侧的字符范围Show Scope Name.


对于测试选择器,您可以使用Sublime Text控制台中的view.match_selectorview.find_by_selector API(View菜单 - > Show Console).

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

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

更多信息:

可以使用以下运算符:

  • -:没有,在范围内的任何地方(要清楚,这是一个由空格包围的短划线,因为短划线可以出现在范围名称的中间)
  • &:with,范围内的任何位置(在.tmTheme文件中,XML,&应该转义为&amp;,除非在CDATA节点内.)
  • (space): with, must come after (i.e. to the right of) the preceding scope
  • |,:或者,范围内的任何地方
  • (... )可用于将选择器组合在一起

笔记:

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

例:

在以下Python代码段中,使用语法测试格式,所有测试都将通过,因此它可以作为选择器如何工作的演示:

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
Run Code Online (Sandbox Code Playgroud)

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