【问题标题】:Textmate syntax highlighting, extending highlighting from another languageTextmate 语法高亮,从另一种语言扩展高亮
【发布时间】:2011-03-09 17:34:46
【问题描述】:

我正在尝试在 Textmate 中扩展一些 CSS 突出显示。我的做法是这样的……

{ 
    ....
    patterns = (
        { include = 'source.css'; },
        { 
            name = 'support.function';
            match = '\..*\);';
        },
    );
}

问题是“include = 'source.css';”。如果我删除那条线。我的自定义匹配器点击并应用了预期的突出显示。但后来我失去了我想要的所有预定义的 CSS 突出显示。

我对如何覆盖我所包含的现有 CSS 突出显示感到困惑。想法?

【问题讨论】:

    标签: css syntax-highlighting textmate highlighting


    【解决方案1】:

    我遇到了类似的问题。我用头撞了一下,然后 TextMate IRC 频道中的某个人直截了当:出于某种原因(我忘记了),您需要重新包含您的语言语法。

    我的模式部分现在看起来像

    patterns = (
    {   include = 'source.ruby'; },
    {   include = '$self'; },
    );
    

    要为这个示例添加更多信息,这是我为 I 创建的包的语言语法(在我感兴趣的文件部分,所有内容都在 meta.rails 范围内。模型。也许你的 CSS 包中没有它。

    patterns = (
        {   name = 'meta.rails.model';
            comment = "Uses lookahead to match classes that (may) inherit from ActiveRecord::Base; includes 'source.ruby' to avoid infinite recursion";
            begin = '(^\s*)(?=class\s+.+ActiveRecord::Base)';
            end = '^\1(?=end)\b';
            patterns = (
                {   include = 'source.ruby'; },
                {   include = '$self'; },
            );
        },
        {   name = 'source.ruby.rails.aasm.event';
            match = '(aasm_event\W*:\w+)';
            captures = { 1 = { name = 'keyword.other.context.ruby.rails.aasm.event'; }; };
        },
        {   include = 'source.ruby.rails'; },
    );
    

    }

    但是您会看到 $self 声明将其他模式引入了 meta.rails.model 模式(我认为这就是为什么这很重要)。

    【讨论】:

    • 完美,正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-17
    • 1970-01-01
    • 2011-02-18
    相关资源
    最近更新 更多