【问题标题】:Sublime Text - Modifying tmTheme fileSublime Text - 修改 tmTheme 文件
【发布时间】:2016-05-24 06:53:17
【问题描述】:

.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>

【问题讨论】:

    标签: themes sublimetext3 color-scheme


    【解决方案1】:

    这不是正则表达式;这是一个scope selector,它是borrowed from TextMate

    可以对范围选择器进行 AND、OR 和减法,例如:(a | b) &amp; c - d 将选择 d 不匹配的范围,但 c、a 或 b 都匹配。

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


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

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

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

    运营商

    这些是布尔逻辑运算符:

    • -: "not" 在选择器中的任何位置使用(要清楚,这是一个由空格包围的破折号,因为破折号可以出现在范围名称的中间)
    • &amp;amp;:“和”,在范围内的任何位置使用(在 .tmTheme 文件中,即 XML,&amp;amp; 应转义为 &amp;amp;,除非在 CDATA 节点内。)
    • |,:“或”在范围内的任何位置使用
    • () 可用于将选择器组合在一起

    还有一个层次运算符:

    • (space): "after," 必须出现在前面的作用域之后(即右边)。
      • 这在(grouping) 之后不起作用。

    注意事项

    • 范围只能由字母数字字符和点 (.) 组成,因此不会发生与运算符的冲突。
    • 范围由一个空格分隔。
    • 运算符周围的空格不是必需的。 (空白在评估之前被修剪/去除。)即 string | comment string|comment 相同。
    • 在对范围选择器进行评估之前,前导点和尾随点也会从范围选择器中去除
    • 连续的空格被视为一个空格。
    • 所有范围都由. 分割,并从一开始就匹配您的选择器拥有的尽可能多的级别。 a.b 将匹配 a.b.c.d
    • 范围选择器中没有通配符运算符。因此,您无法使用 .python*.python 等匹配范围 source.python
    • 完全为空的选择器匹配所有内容。但不是在操作员之后。即| 本身会失败,|source 也会失败。但是,source| 有效。 -source - 将失败。
    • 如果您不确定运算符的优先级,请将表达式的部分内容括在括号中以使其清楚。分组后记得使用空格以外的运算符,否则分组后的范围会被忽略。

    示例

    在下面的 Python sn-p 中,使用 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 规则适用于或不适用于您可能未预料到的情况。

    【讨论】:

    • 感谢您的链接,以便标记我的问题的含义:“更新:从 1.1b17 开始,还可以对范围选择器进行 AND、OR 和减去范围选择器,例如:(a | b) & c - d 会选择 d 不匹配的范围,而 c 和 a 或 b 都匹配。"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多