Home Download Buy Blog Forum Support

Compile CoffeeScript selection to Javascript

Compile CoffeeScript selection to Javascript

Postby blahblahblah on Sat Feb 25, 2012 1:12 am

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!
blahblahblah
 
Posts: 1
Joined: Sat Feb 25, 2012 1:04 am

Re: Compile CoffeeScript selection to Javascript

Postby SeanWcom on Sat Feb 25, 2012 3:40 am

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:

http://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:

https://bitbucket.org/seanwcom/coffeescript-scratchpad
Multiple selections... one of my favorite ST2 features. View some noob-friendly screen casts here.
SeanWcom
 
Posts: 101
Joined: Wed Aug 03, 2011 1:31 am
Location: Georgia

Re: Compile CoffeeScript selection to Javascript

Postby phillip.koebbe on Sat Feb 25, 2012 11:34 am

SeanWcom wrote: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:

http://w.illia.ms/coffeescript-scratchpad/


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.
-- Phillip

Code: Select all
while self.living? do
    mistake = Mistake.new
    self.learn_from!(mistake) unless mistake.fatal?
end
phillip.koebbe
 
Posts: 208
Joined: Tue Dec 20, 2011 4:58 pm

Re: Compile CoffeeScript selection to Javascript

Postby sublimator on Sat Feb 25, 2012 11:47 am

Wonder if you could hook up the compiler to that python/v8 bridge interpreter and have it running in Sublime window splits?
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Compile CoffeeScript selection to Javascript

Postby suter on Sat Feb 25, 2012 12:55 pm

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

I find it's a solid compliment to Sublime Text.
suter
 
Posts: 6
Joined: Sat Feb 25, 2012 12:54 pm

Re: Compile CoffeeScript selection to Javascript

Postby tanepiper on Sun Feb 26, 2012 12:38 am

I once wrote a plugin for Cloud9 that did this (https://github.com/tanepiper/cloud9-livecoffee-ext) - I think the same thing could be achieved with SublimeV8 (https://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.
tanepiper
 
Posts: 68
Joined: Sun Nov 06, 2011 6:40 am

Re: Compile CoffeeScript selection to Javascript

Postby SeanWcom on Sun Feb 26, 2012 4:13 am

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.
Multiple selections... one of my favorite ST2 features. View some noob-friendly screen casts here.
SeanWcom
 
Posts: 101
Joined: Wed Aug 03, 2011 1:31 am
Location: Georgia

Re: Compile CoffeeScript selection to Javascript

Postby wprater on Wed Feb 29, 2012 12:38 am

This would be really cool! Any progress on this?
wprater
 
Posts: 8
Joined: Wed Feb 22, 2012 11:54 pm

Re: Compile CoffeeScript selection to Javascript

Postby SeanWcom on Thu Mar 01, 2012 3:18 pm

I haven't been able to get Sublime-v8 working because my compile-fu is weak. :) I'm waiting for there to be a working 64-bit pyv8 that we can use with Sublime-v8.
Multiple selections... one of my favorite ST2 features. View some noob-friendly screen casts here.
SeanWcom
 
Posts: 101
Joined: Wed Aug 03, 2011 1:31 am
Location: Georgia


Return to General Discussion

Who is online

Users browsing this forum: Google [Bot] and 19 guests