Sunday July 03, 2011 at 20:17

adding extra CoffeeScript goodies to Sublime Text 2

I started playing around with CoffeeScript this weekend and I quickly realized that switching back and forth between text editor and terminal was not a good workflow (especially when first learning the language and figuring out what is compiled to what). So, after looking around a bit, I found that there is an existing CoffeeScript TextMate bundle and since Sublime Text 2 is compatible with some of the elements inside of TextMate bundles it’s fairly easy to set up Sublime Text to use them. All you need to do is:

cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/
git clone git://github.com/jashkenas/coffee-script-tmbundle CoffeeScript

Once you have this in place you will have CoffeeScript syntax highlighting and snippets available. Now all you need is a build system, so:

  1. Create a file called CoffeeScript.sublime-build in ~/Library/Application Support/Sublime Text 2/Packages/User/
  2. Add this to the file:
    {
    	"cmd": ["coffee", "-c", "$file"],
    	"selector" : "source.coffee",
    	"path" : "/usr/local/bin"
    }
    
  3. Close any .coffee files open and restart Sublime Text 2

This will run a simple compile on the current file when you Build (Command+B). If your CoffeeScript file has the “.coffee” extension then you can set the Build System option to Automatic and Sublime Text 2 will know to your custom CoffeeScript build system.

Make sure “path” is pointing to where the “coffee” executable is in your system (I installed CoffeeScript using npm by running "npm install -g coffee-script" which installed it to /usr/local/bin).

You can customize the CoffeeScript.sublime-build to do much more. See these links for more information on Sublime’s build system.

Comments (View)
blog comments powered by Disqus