[TxMt] Setting up syntax highlighting for python scripts embedded in xml files

Pedja pedjany at fastmail.fm
Sat Jun 14 23:25:03 UTC 2008


The project I am currently working on requires me to write xml
configuration files for a custom application for experience sampling.
The files contain embedded python scripts, contained in the following

<script event="OnLoad">
python script

I know that TextMate is able to deal with embedded regions that have a
different language deffinition than the main file (like php and
javascript sections in HTML) so I was trying to set this up for XML so I
can have proper syntax highlighting for python. So far, though, I have
not had any luck with this. I tried adding the following in the xml
language definition, both right after the section for embedded java and,
when that didn't work, right after the section for CDATA comments, but
it doesn't seem to work:

{ name = 'source.python.embedded.xml';
			begin = '<script.*?}>\s*?<!\[CDATA\[';
			end = ']]>\s*?<script/>';
			beginCaptures = { 0 = { name = 'punctuation.section.embedded.begin.xml'; }; };
			endCaptures = { 0 = { name = 'punctuation.section.embedded.end.xml'; }; };
			patterns = ( { include = 'source.python'; } );

This was based on the example for embedded java, but obviously I either
didn't understand what the java example does, or I didn't specify the
begin and end strings correctly. I also suspect that since there is
already a definition for CDATA comments, this needs to be in a specific
place to override that definition. 

Any help with getting this to work would be greatly appreciated. The
scripts can be quite long, so having proper syntax highlighting would
make things much easier. 

Thanks so much,

http://www.fastmail.fm - Faster than the air-speed velocity of an
                          unladen european swallow

More information about the textmate mailing list