Sublime Forum

Compile CoffeeScript selection to Javascript

#1

Hi there, I am a recent convert to Sublime Text, and I’m loving it. One of the features of my setup on TextMate that I miss the most is the ability to compile a snippet of coffeescript, and see how it looks in Javascript. This is not a compilation of the entire coffeescript file, but the currently selected text. I got ST2 to compile the entire file and output it to the build console, but I cannot get a selection of text to do so. Any ideas on how to get there?

THanks!

0 Likes

#2

I’d love to find a way to have it compile in real time to another window. But the closest I’ve seen is the CoffeeScript build command that will save a .js… if you have that open in another window you can tab back and forth after each save/build. But that’s not good enough for me.

What I really like is what the CoffeeScript website has where you can edit and see real time compilation. So, using that as a basis, I wrote up a full screen version of that that also includes syntax highlighting. You can see it working here:

w.illia.ms/coffeescript-scratchpad/

Please keep in mind that this is far from professional. I got fed up one afternoon while using the little editor on CoffeeScript’s website and decided to do something a tiny bit better. Using the CodeMirror library for an editor I was able to add syntax highlighting and make it “full screen.” It could probably be improved a ton, so feel free to download my code and make it better. I have it in a public repo here:

bitbucket.org/seanwcom/coffeescript-scratchpad

0 Likes

#3

I just started in CoffeeScript the past few weeks and I find that I go back to the CoffeeScript website frequently to work out something I’m trying to do. The default style of the editor hurt my eyes, so I put something into Chrome’s default CSS override to mute it a bit. I’ll use your scratchpad for a while and see how it goes. Other than the styling, I don’t have any real complaints with the coffeescript.org scratchpad, so I don’t know what I’d be looking for in your’s. But if I run into anything, I’ll let you know.

0 Likes

#4

Wonder if you could hook up the compiler to that python/v8 bridge interpreter and have it running in Sublime window splits?

0 Likes

#5

Have you tried using Live Reload (livereload.com/)?

I find it’s a solid compliment to Sublime Text.

0 Likes

#6

I once wrote a plugin for Cloud9 that did this (github.com/akira-cn/sublime-v8) and running it into a view - like a two column view showing a live version of the current code being typed in.

In the client side it’s fast enough to be in real time, the compile window, nodes and tokens views all update on keystroke, so Sublime’s event system could probably handle it.

0 Likes

#7

Unfortunately Sublime-v8 doesn’t have a 64bit version of pyv8… only 32 bit. I started to get into compiling my own version and realized it was going to take more setup than I anticipated. If I can find more time this week, I’ll try and get a 64bit version compiled and hope that sublime-v8 will work with it. Assuming all that goes well (cross your fingers), then I’ll see what I can cook up.

0 Likes

#8

This would be really cool! Any progress on this?

0 Likes

#9

I haven’t been able to get Sublime-v8 working because my compile-fu is weak. :smile: I’m waiting for there to be a working 64-bit pyv8 that we can use with Sublime-v8.

0 Likes