Hi -
New to TextMate and this list and very impressed so far with both.
I am experimenting with extending existing Language Grammars, and I've run into a problem. I wonder if this is my problem or not, or simply a problem in understanding the system:
It appears that some pattern definitions override or erase others. For instance, I've added a feature to grab a reference to a particular email in Mail.app and create a tag called "emaillink" in my GTDalt document. Specifically, I want to add these emaillinks to the notes fields in my GTDalt document (I mention this as it becomes important below). I decided to make a new Language Grammar, based on GTDalt, and wrote the following:
{ scopeName = 'text.gtdalt.jb'; fileTypes = ( 'gtd', 'gtdlog' ); foldingStartMarker = '^\s*project'; foldingStopMarker = '^\s*end\s*$'; patterns = ( { name = 'meta.jb'; match = '\bmy_emailllnk_tag\b'; }, { include = 'text.gtdalt'; }, ); }
Seems like it should work, but it doesn't. This appears to be because the definition of the notes field (in the text.gtdalt Language Grammar) erases my scope tag.
I see this, too, when I try to extend the C Language Grammar to include color markup of the API I am using. In many cases, wherever the text was in Scope source.c, it works. But as soon as the term in question appears within a function declaration or a similar parsed structure, my scope tag is eliminated in favor of the parsed one. The position of the "include" line doesn't appear to make a difference.
It seems like there should be a way to have persistent scope tags, for exactly this purpose -- color-coding particular terms or rendering particular strings a certain way, potentially regardless of local context. But if not, could someone suggest a workaround?
Thanks very much jb
Grammars include begin/end rules, when inside those rules the only thing that is active is the rules listed in it's patterns list. So if your trying to include something inside there it's not going to work.
The other possibility is that your trying to include something inside a match rule, there your match rule will win because it is the highest in the language file. However that is only if the matches start at the same place. If a match in the main grammar matches in an earlier column your match is never even seen.
For the first problem there is a solution coming at some point; but it won't be very soon. (Search the archives for scope injection) For the second nothing can really be done except duplicating that rule yourself.