【问题标题】:.tmLanguage -- how to include / exclude a variable.tmLanguage -- 如何包含/排除变量
【发布时间】:2013-04-08 22:40:51
【问题描述】:

我正在寻找包含/排除 .tmLanguage 文件中定义的几个变量的示例。

示例 1 -- 突出显示整个辣酱玉米饼馅,包括两个变量:

{\code_one*[variable_one]{variable_two}}

示例 2 -- 突出显示整个辣酱玉米饼馅,少一个或两个变量:

{\code_two*[variable_three]{variable_four}}

【问题讨论】:

  • 我知道你可以想出一个更好的标题。
  • 谢谢 -- 标题被修改为不那么像代码了。
  • 那么你尝试了什么?
  • 我发现最好的学习方法是浏览其他 .tmLanguage 文件,看看它们是如何做到的,同时保持对正则表达式的良好参考,以解决您可能遇到的任何问题。范围的全部意义在于突出文本的特定部分,因此您所要做的就是在开始和结束之间添加一个排除语句......

标签: sublimetext2 tmlanguage


【解决方案1】:

include_variable_text——例如,\hspace*{3.45in}\begin{singlespace*}; \end{document}.

.tmLanguage

<!-- BEGIN include_variable_text -->
<dict>
    <key>begin</key>
    <string>\\makebox\[|\\hspace\*\{|\\begin\{|\\end\{</string>
    <key>beginCaptures</key>
    <dict>
        <key>0</key>
        <dict>
            <key>name</key>
            <string>lawlist.include_variable_text.begin.latex</string>
        </dict>
    </dict>
    <key>end</key>
    <string>\}|\]</string>
    <key>endCaptures</key>
    <dict>
        <key>0</key>
        <dict>
            <key>name</key>
            <string>lawlist.include_variable_text.end.latex</string>
        </dict>
    </dict>
    <key>name</key>
    <string>lawlist.include_variable_text.latex</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>$base</string>
        </dict>
    </array>
</dict>
<!-- END -->

tm.主题

<!-- BEGIN lawlist.include_variable_text -->
<dict>
<key>name</key>
<string>Grayed-Out</string>
<key>scope</key>
<string>lawlist.include_variable_text.latex</string>
<key>settings</key>
    <dict>
    <key>fontStyle</key>
    <string>italic</string>
    <key>foreground</key>
    <string>#E3E3E3</string>
    <key>background</key>
    <string>#FFFFFF</string>
    </dict>
</dict>
<!-- END -->

exclude_variable_text

{\bf\uline{excluded_variable_text}}

.tmLanguage -- 此代码包含额外的三 (3) 个键以供将来使用 -- 例如,[anything]

<!-- BEGIN exclude_text -->
<dict>
    <key>match</key>
    <string>(?=\s)(?&lt;=\\[\w@]|\\[\w@]{2}|\\[\w@]{3}|\\[\w@]{4}|\\[\w@]{5}|\\[\w@]{6})\s</string>
    <key>name</key>
    <string>meta.space-after-command.latex</string>
</dict>
<dict>
    <key>begin</key>
    <string>((\{\\bf)(?:\\uline|code_two|code_three))(?:(\[)([^\]]*)(\]))?(\{)</string>
    <key>beginCaptures</key>
    <dict>
        <key>1</key>
        <dict>
            <key>name</key>
            <string>lawlist.base.latex</string>
        </dict>
        <key>2</key>
        <dict>
            <key>name</key>
            <string>lawlist.prefix.latex</string>
        </dict>
        <key>3</key>
        <dict>
            <key>name</key>
            <string>lawlist.open_square_bracket.latex</string>
        </dict>
        <key>4</key>
        <dict>
            <key>name</key>
            <string>lawlist.first_variable.latex</string>
        </dict>
        <key>5</key>
        <dict>
            <key>name</key>
            <string>lawlist.close_square_bracket.latex</string>
        </dict>
        <key>6</key>
        <dict>
            <key>name</key>
            <string>lawlist.open_wavy_bracket.latex</string>
        </dict>
    </dict>
    <key>contentName</key>
    <string>lawlist.second_variable.latex</string>
    <key>end</key>
    <string>\}\}</string>
    <key>endCaptures</key>
    <dict>
        <key>0</key>
        <dict>
            <key>name</key>
            <string>lawlist_close_wavy_bracket.latex</string>
        </dict>
    </dict>
    <key>name</key>
    <string>lawlist.whole_enchilada.latex</string>
    <key>patterns</key>
    <array>
        <dict>
            <key>include</key>
            <string>$self</string>
        </dict>
    </array>
</dict>
<!-- END exclude_text -->

*.tm主题

<!-- BEGIN strong blue #0000FF -- uline exclude_text -->
<dict>
    <key>name</key>
    <string>Bold / Underline</string>
    <key>scope</key>
    <string>lawlist.base.latex|lawlist.open_square_bracket.latex|lawlist.first_variable.latex|lawlist.close_square_bracket.latex|lawlist.pen_wavy_bracket.latex|lawlist_close_wavy_bracket.latex</string>
    <key>settings</key>
    <dict>
        <key>fontStyle</key>
        <string></string>
        <key>foreground</key>
        <string>#E3E3E3</string>
    </dict>
</dict>
<!-- END -->

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-20
    相关资源
    最近更新 更多