Another form of Format Strings allows you to change the case of a variable reference. If you combine that with the fact that scope name
elements in TextMate 2's Language Grammars are now Format Strings, this allows for nice dynamic scoping tricks.
For example, say we rework Ruby's "here-document" (heredoc) syntax rule to look something like this (simplified) example:
begin = '<<-?(\w+)'; name = 'string.unquoted.${1:/downcase}.ruby'; …
That would mean that a heredoc definition like this:
<<-CSS body { margin: 10px auto; } CSS
would be scoped as meta.here-doc.css.ruby
. This allows the injection of the CSS Grammar and automations into the scope meta.here-doc.css
. That would mean that you get the proper syntax highlighting of these heredocs and you could trigger CSS Bundle commands while editing them.
As I write this, the ruby grammar still has a dozen rules with a dozen different tokens that include a dozen different languages, so the above is a planned simplification that would allow us to avoid having to upgrade the ruby grammar for new potential here-doc tokens.
The supported case transformations are /upcase
, /downcase
, and/capitalize
. There's also a special /asciify
transformation that will transliterate things like "æ" and "ø" into "ae" and "o" respectively as well as remove any remaining non-ASCII characters. The latter is particularly useful when deriving an identifier or label, that needs to be accepted by a language parser, from a heading or comment, which is free-form prose. These transformations can be combined.
I'm updating my Markdown bundle to better handle GitHub-style fenced code blocks like so:
```ruby
foo = { bar: true }
```
The grammar is simple enough for one language:
ruby_block = {
begin = '^```ruby.*$';
end = '^```.*$';
patterns = ( { include = 'source.ruby'; } );
};
However, I'd like to support any language. I tried the following, but it doesn't appear to work (and I'm not sure why):
code_block = {
begin = '^```(\w+).*$';
end = '^```.*$';
patterns = ( { include = 'source.\1'; } );
};
Is something similar possible / supported?
Thanks!
-Tyson
_______________________________________________
textmate mailing list
textmate@lists.macromates.com
http://lists.macromates.com/listinfo/textmate