views:

60

answers:

1

I'm trying to extend some CSS highlighting in Textmate. My approach is like so...

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

The problem is "include = 'source.css';". If I remove that line. My custom matcher hits and applies the expected highlighting. But then I lose all the predefined css highlighting that I want.

I'm puzzled as to how I can override the existing css highlighting that I am including. Ideas?

+1  A: 

I had a similar issue. I banged my head against it, then someone in the TextMate IRC channel set me straight: for some reason (which I forget) you need to reinclude your language grammer.

My patterns section now looks like

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

To add more information to this example, here is my language grammer for the bundle I was creating (in the part of the file I was interested in, everything was in the scope meta.rails.model. Maybe you don't have that in your CSS bundle.

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'; },
);

}

But you see that the $self declaration pulls in the other patterns into the meta.rails.model pattern (which is, I think, why that was important).

RyanWilcox
Perfect, exactly what I was looking for.
Roy Kolak