Reputation: 20437
I have a custom syntax highligher I use in TextMate. It works great in TextMate 1, but in Textmate 2, it treats the entire line as a single word.
This impacts:
Textmate 1 used to have a "word boundary" option in general preferences and I think that's why this worked.
I understand that Textmate 2 refactored word boundary handling, but I don't understand how to make my syntax package work in the new paradigm.
My language grammar is very simple, it has entries like this:
{ patterns = (
{
name = 'constant.language.toStart.todo';
match = '^\s*o\s.*';
// ^ Starting at the beginning of the line,
// \s* Preceded by any number of spaces
// o\s Match any "o "
// .* Then match all chars after it
}
}
Is there a way for me to modify the matcher so that the editor respects word boundaries inside these matched patterns?
Upvotes: 2
Views: 403
Reputation: 553
As you pointed to the blog post we now treat certain syntax matched areas as a 'word' for selection purposes. The region you highlight is all a constant so it gets treated as one really long word.
You need to give each part a different scope to correct this, they can both be constant even but must be otherwise unique. The other option is to give them different scopes, perhaps matching the todo part as a string?
If you give them a constant and string scope the work will be done. If you give them different constant scopes you will need to create a preference item for each giving them different characterClass
values. (The value isn't important, just needs to be unique.)
You can also give the entire line a meta
wrapper scope which is what we generally do with regions of code like this if you want to keep the line scoped as something singular to perform actions etc.
eg:
{ patterns = (
{ name = 'meta.preprocessor';
match = '^\s*\o\s.*';
},
{ name = 'entity.name.class';
match = '^\s*\.\s.*';
},
{ name = 'meta.class.ruby';
match = '^\s*x\s.*';
},
}
Upvotes: 2
Reputation: 558
.* is greedy so regex matches as much as it can to the end of line, .*? is what you are looking for as far as I could see; if you'd like the pattern above to match 'o ' from the line 'o oopps'.
Upvotes: 0