Sublime Text and CoffeeScript

Tuesday, December 20 2011

I admit it. I have Text Editor compulsion. I have played around with many text editors on my Mac including vim, emacs, BBEdit and TextMate. So its no surprise I encountered Sublime Text 2 .  Its a neat little editor in its infancy.

But as all neat little editors in its infancy go, it is a little premature.  For example there is no out of the box CoffeeScript support.  Since I have been hacking some CoffeeScript, I needed to correct this.  So with some googling and the fact that Sublime Text supports TextMate bundles, I discovered how to start CoffeeScript development with Sublime Text.  The following are my findings.

Syntax Highlighting

We will make use of Jeremy Ashkenas CoffeeScript TextMate Bundle to add syntax highlighting support.

Build System

To setup the Sublime Text Build System to work with CoffeeScript you just need to create a file (CoffeeScript.sublime-build) with the following contents and place in ~/Library/Application Support/Sublime Text 2/Packages/User/

    "cmd": ["coffee", "$file"],
    "selector" : "source.coffee",
    "path" : "/usr/local/bin"

Note that I have CoffeeScript installed in /usr/local/bin on my Mac.  Edit the above path appropriately to match your system.


Obviously the above is aching to be automated so I hacked up a quick bash script and associated sublime build file.  They can be found here in my git sandbox repo.


Credit where credit is due.  Much of the info from this post was garnered from the following sources: