I want to be able to color lines differently based on the starting character.
eg.:
- This is line 1
- This is line 2
x This is line 3
- This is line 4
x This is line 5
So lines 1,2,4 (starting with ‘-‘) should be blue while lines 3,5 (starting with ‘x’) should be red.
Is this possible? How would you do it?
Thanks.
You can define the color by defining a new grammar. My grammar contains the following:
I created the scope text.todo and assigned this grammar to an file which is named “foo.todo”.
The first pattern says “any amount of whitespaces, followed by a dash and anything after it”. This match is called “constant”, thus TextMate will use the color which is defined for this scope in “Preferences” > “Fonts & Colors”. Constants are blue in my theme.
The second pattern requires an “x” instead of a dash and calls the match “variable.other.constant”, which happen to be red in my theme. It should be easy for you to extend from here. If you need help, just press the question mark below your grammar definition.