EB - Elliot Betancourt
Published on

How I Use TextMate

Authors
  • avatar
    Name
    Elliot Betancourt
    Twitter
    @ebetan

All Programmers swear by their editor. Its like a religion. You only need to think about the ongoing joke of emacs vs vi in the Unix world to get a sense of the fact that its not something we take lightly.

One very popular choice of editor on Mac is Macromates’ TextMate. Just like the two iconic Unix editors, the power of TextMate lies not within the application itself, although, it IS an incredible application, it fits in just seemlessly with the rest of the User Experience in OS X, and it integrates pretty nicely with popular Mac FTP client Transmit . No, the REAL power of TextMate lies in its plugin architecture. These plugins are called “Bundles”. And TextMate comes with a million of these right out of the box. This leads to people having different methodologies for how they like to use TextMate.

My career is in Web Development, so that is going to be the workflow I describe here. I also plan to use TextMate more for Cocoa / Objective-C as I learn the language, but for now I code that mostly in XCode.

I typically program in a very web-centric list of languages: PHP, Javascript, HTML, CSS, XML, SQL. The syntax highlighting for all of these is very good, its even smart enough to notice if I have SQL being set into a PHP variable and highlight that string appropriately. For example:

Picture 6

I would like drop-down autocompletion like what you see in alot of bloated IDE’s, but really, I know all these languages so well, that would just be indulging a lazy typist. For Javascript, YUI is typically my framework of choice, I have installed a Bundle for it that offers parameter help, tons of macros / code snippets whatever you want to call them, and highlighting of built-in YUI classes / methods.

I almost always work in “project mode”, not sure if thats the real name, but its what I call it. Its what happens when you open a folder with TextMate, you can do this by dragging the folder to the icon, through the command line utility (mate foldername/ ) or through Quicksiver (my personal favorite)

Picture 11

this will give you the “Project Drawer” which is the file browser type thing you are used to seeing in a lot of desktop text editors / IDEs:

Picture 10

If its a folder you work with frequently, you can save this as a project through File > Save Project As… , and then just open that file whenever you want the same folders loaded in your project drawer. You can use this project trick to get all your Transmit (FTP client) files to open in TextMate with tabs (instead of each file in its own window.)

I like to use the TextMate TODO Bundle to track points in my code where I have something to do(as the name implies), I can also flag code to fix with “FIXME” and mark any of these items as done with the keyword “CHANGED” in my comments. (I actually modified the plugin to use the word DONE instead, but CHANGED is the default) . The bundle works by placing specially formatted comments like so (either manually or by triggering the code snippet by typing “todo” followed by a TAB):

Picture 1

also works in HTML:

Picture 2

the bundle is smart enough to know the appropriate kind of comments for the language you cursor is currently sitting in.

you can then get a list of all your outstanding action items (or “Next Actions” for you GTDers out there) with a simple CTRL+SHIFT+T:

Picture 3

This methodology allows me to track what I need to do WHERE I need to do it. And the filenames you see on the left with the line numbers next to them are links that will jump right to that line in the file, and put your cursor there. (for the image above, note that I added my own “DELETE” comment and renamed “CHANGED” to “DONE” as I mentioned above..its amazing how easy this is to do if you go to Bundles > TODO > Preferences )

Picture 12

The only down side to this integrated work environment is that I’m not the only one using it. This way of working is also quite popular at Yahoo! (and apparently so is TextMate). The guys working on Ruby on Rails are also fans of TextMate, and its TODO Bundle. Especially its creator David Heinemeier Hansson and his team at 37 signals, if you have ever seen any of their rails screen-casts, you will notice they are working in TextMate. Cool, its a popular way to work, what’s wrong with that? Well, whenever I work in a project where I use YUI or Rails, and hit CTRL+SHIFT+T I not only get MY to-dos I also get all of the to-dos from those projects! Luckily I found the solution in this blog post:

Ex dolo with intent: exdolo.com

if you’re too lazy to click through to the post:

Go to Preferences > Advanced > Folder References and change the Folder Pattern from:

!.\*/(.[^/]\*|CVS|\_darcs|{arch}|blib|.\*~.nib|.\*.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))\\\\\\\\\\$

to:

!.\*/(.[^/]\*|rails|CVS|\_darcs|{arch}|blib|.\*~.nib|.\*.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))\\\\\\\\\\$

the equivalent expression I use for YUI:

!.\*/(.[^/]\*|yui|CVS|\_darcs|{arch}|blib|.\*~.nib|.\*.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))\\\\\\\\\\$

Your milage may vary, I put all the YUI modules in the /js/yui/… directory of my projects, so filtering for the yui folder works for me.

The final piece of the puzzle is, of course, source control. I have a Subversion repository hosted at DreamHost. I simply followed these instructions for setting up a subversion repository, and just for kicks set up a Trac server. I really recommend using the HowTo and script posted here.

I then import / checkout my subversion repository from the command-line. It is very important to do your first checkout with username and password. A lot of Mac GUI clients try to make life too easy for you, and they will use the authentication credentials used to create the repository. I then install the Subversion plugin for Finder, and use the Subversion Bundle for TextMate (you knew that was coming, didn’t you).

Also, the subversion plugin for finder adds a little badge overlay to the icons in finder. Which is nice, because that same badge shows up in your title area in TextMate. see the little green dot with a check mark in the lower left corner of the html icon that tells me this is the latest working version of the file, a red dot with an “X” means my file has been locally modified, Yellow dot with questionmark means it doesn’t exist in the repository (needs to be added), and so on.

Picture 8

The subversion TextMate bundle has alot of advantages. For instance, I tend to work in a lot of different files in just a couple of hours. MVC development and Ajax work quickly increase the number of files you are touching. One Ajax call can involve the HTML page its its made from, a separate Javascript file, the PHP page receiving your Ajax call, and the controller underlying that page (hopefully you don’t need to touch the model.) After 3 or 4 hours of this, I have probably modified at least 10 files. This is where TextMate and the Subversion bundle make my life very easy. I can get the subversion status, which tells me what is modified, what files are not in the repository ( have a ? ), are added to the repository, but not had their first commit, etc. I can pull this status at the root of my project. With the project drawer open select the top-level folder and hit CTRL+SHIFT+A to get a context-type menu:

Picture 7

from this hit “0”…thats a zero, not a letter “o”. TextMate will generate a nice little report like this for you. And as an added bonus, its a completely interactive HTML form, you can add, diff, revert your files directly from the report, and then hit the commit button to commit all your work to the Subversion server!

Picture 4

Working with TextMate is absolutely the best experience I have had with a text editor / IDE. And I have tried more than a few, was actually quite happy with Zend Studio, and use it for its debugging, remote debugging capability, but I look forward to the day I can do this from within TextMate as well! If you are trying out TextMate, I recommend taking a look at the bundle it includes for the language you typically work in, by going to Bundles in the Menu, there are all sorts of cool stuff, for instance, PHP can execute the files and show you the output, or verify the file for syntax errors. Every couple of months I try a new editor (Alot of Ajax IDEs are coming out now a days!) but always find myself coming back.

Love TextMate? Hate it? Think I’m an idiot and should use BBEdit instead? Tell me in the comments!