Mixing PHP and JavaScript in TextMate

Peter Rukavina

About six months ago I switched to using TextMate as my text editor, after using BBEdit for as long as I can remember. For those of you in civilian life this might seem like a trivial thing; it isn’t. I spend 95% of my working life inside a text editor, so switching is something like trading in a Ford pick-up for a Dodge.

A text editor is a text editor is a text editor. All pick-up trucks have a cab, and a bed, and wheels and an engine. But the cup-holders are in different places, and the tailgate works differently, and the way your program you favourite stations into the radio changes. And so it is with text editors. In other words, when you switch there’s a “getting used to it” period that lasts for months. I’m there, and TextMate feels like home now.

But I’m still learning.

One important thing I learned today is that TextMate and its “bundles” — the language-specific add-ons that make TextMate “know” about PHP, HTML, JavaScript, etc. — are smart enough to understand that a single PHP file can intermix CSS, HTML, PHP and JavaScript code and react accordingly.

The key to all this, which is, alas, buried deep within the TextMate documentation, is to set the language to HTML:

Screen Shot of Language Setting in TextMate

Once you do this, you’ll find that the syntax highlighting, function lookup, and other language-specific features of TextMate work in a language-appropriate way depending on where you are in the document. It’s all really rather magical.

Comments

Add new comment

Plain text

  • Allowed HTML tags: <b> <i> <em> <strong> <blockquote> <code> <ul> <ol> <li>
  • Lines and paragraphs break automatically.

About This Blog

Photo of Peter RukavinaI am . I am a writer, letterpress printer, and a curious person.

To learn more about me, read my /nowlook at my bio, listen to audio I’ve posted, read presentations and speeches I’ve written, or get in touch (peter@rukavina.net is the quickest way). 

You can subscribe to an RSS feed of posts, an RSS feed of comments, or a podcast RSS feed that just contains audio posts. You can also receive a daily digests of posts by email.

Search