A Cheetah Template Mode Definition for jEdit

I decided to spend my Friday working on a small side-project for work; as mentioned in a few earlier posts, I wanted to learn a bit of CherryPy and Cheetah, so it looks like this is my chance.

Since jEdit is my favourite text editor, and I couldn’t find an existing mode definition out there for Cheetah’s template (*.tmpl) format, I made one myself. Not exactly rocket science, but it might save someone a few minutes.

To install it:

  • Copy the XML source below to a new file, cheetah.xml, in your $home/.jedit/modes/ directory.
  • Edit the catalog file in the same directory. Add an entry somewhere that looks something like this:<MODE NAME="Cheetah Template" FILE="cheetah.xml" FILE_NAME_GLOB="*.tmpl" />
  • Restart jEdit then load a Cheetah template file. Hopefully everything looks pretty.
<?xml version="1.0"?>

<!DOCTYPE MODE SYSTEM "xmode.dtd">

<MODE>
	<PROPS>
		<PROPERTY NAME="commentStart" VALUE="<!--" />
		<PROPERTY NAME="commentEnd" VALUE="-->" />
		<PROPERTY NAME="lineComment" VALUE="##" />
	</PROPS>
	<RULES>
		<!-- Everything else is an XML tag -->
		<IMPORT DELEGATE="html::MAIN"/>

		<!-- Get Python rules -->
		<IMPORT DELEGATE="python::MAIN"/>

		<!-- Full-line comments -->
		<EOL_SPAN TYPE="COMMENT1">##</EOL_SPAN>

		<!-- Embedded python functions -->
		<EOL_SPAN DELEGATE="python::MAIN">#</EOL_SPAN>

		<!-- In-line Variable definitions -->
		<IMPORT DELEGATE="CHEETAH_VAR" />
	</RULES>
	<RULES SET="CHEETAH_VAR">
		<!-- These were stolen from php.xml -->
		<!-- (Class-)Variables -->
		<SEQ_REGEXP TYPE="KEYWORD3" HASH_CHAR="$" DELEGATE="OBJECT_PHP">$w+(?=([[sw'"]+])?->)</SEQ_REGEXP>
		<MARK_PREVIOUS TYPE="KEYWORD3">::</MARK_PREVIOUS>

		<SEQ_REGEXP HASH_CHAR="$" TYPE="KEYWORD3">$w+(?=s*=s*(&s*)?new)</SEQ_REGEXP>

		<!-- Normal variables -->
		<MARK_FOLLOWING TYPE="KEYWORD3">$</MARK_FOLLOWING>
	</RULES>
</MODE>

Please let me know if you find it helpful.

4 Responses to “A Cheetah Template Mode Definition for jEdit”

  1. Arturo Says:

    I found one error on line 33: “expected character (found ‘*’) (expected ‘;’)”

    My jEdit version is 1.42 final.

    Please, can you help me and solve this problem?

    Regards,
    Arturo.

  2. Kevin Williams Says:

    Hi Arturo,

    1.42 is a mighty old version of jEdit, are you sure that’s accurate? I have 4.3pre8 installed here, using Java 1.6.0_01. If your version of jEdit is truly that old and you can upgrade I would advise doing so—if on the other hand you can’t upgrade, you could try commenting that line out of the xml file and see if it works better then.

  3. Arturo Says:

    Hi, Kevin:

    That’s right!!
    I have commented this line and works fine for my jEdit version.
    Thank you very much!

  4. Kevin Williams Says:

    No problem, glad I could help you out, Arturo. What you’ll unfortunately be missing out on is some of the additional markup, which I guess you can either opt to write yourself or live without. In any event I’m glad you can at least get part-functionality out of it, for now.

Leave a Reply