[TxMt] Customized syntax coloring via Scope Selectors

Steve Lianoglou lists at arachnedesign.net
Tue Feb 13 19:29:47 UTC 2007


Hi,

Although I don't really mess with themes, this should be close to  
accurate:

> I'm new to TextMate and am already recommending it to my students,  
> but I don't
> understand the conventions for Scope Selectors.

Scope selectors start from the general scope, and get more specific  
after each dot.

For the sake of example, let's look at the iPlastic theme.

The "String" element has a scope of string, and the "Regular  
Expression" has a scope of string.regexp

A regex is to be considered as a special case of a string (I guess is  
one way to think of it)

You can find out what scope is assigned to different parts of your  
document by mousing over them and hitting ctrl-shift-p

If you are writng HTML, for example, mouse over a tag (say <p>) and  
hit ctrl-shift-p
You'll see a tool tip for the scope .. for instance, I see:

text.html.basic
meta.tag.any.html
entity.name.tag.html

All three "rules" may apply to that thing (I'm not sure what the  
precedence is between them (is it in increasing or decreasing order)).

Now look again at iPlastic, you'll see that the last rule/coloring  
for "Tag" matches entity.name.tag

Since <p> is "a special case" of entity.name.tag (namely,  
entity.name.tag.html), <p> is in this scope and gets colored w/ that  
blue.

Make sense?

> Let's say I want to color all div tags in HTML red. I've tried  
> variations on
> "entity.tag.div" in Prefs > Fonts & Colors without success. I've a  
> basic
> familiarity with RegExp, and it looks like Bundle grammar supports  
> RegExp, but I
> can't see where syntax coloring might be defined in the HTML Bundle  
> either.
>
> (For the record, I also can't figure out how to duplicate a Theme-- 
> say, if I
> want to tweak a version of the default Theme but keep the original  
> too.)

Go to TextMate > Preferences > Fonts & Colors

Click on the theme list dropdown. On the bottom is "Edit Theme List ..."
You can then click on the theme you want to duplicate and hit the  
plus-plus button (the middle option on the bottom left three-button  
combo)

Hope that helps,

-steve




More information about the textmate mailing list