SublimeText / CoffeeScript

Syntax highlighting and checking, commands, shortcuts, snippets, watched compilation and more.
440 stars 64 forks source link

Support for compiling CS snippets in JS #112

Closed franklin-ross closed 11 years ago

franklin-ross commented 11 years ago

Hey guys, great work with this. Here's something I'd love to see in it: The ability to write a line or 2 of Coffeescript in a JS file, then select just the Coffeescript and hit a command to have it replaced with the equivalent JS.

I have to use JS at work unfortunately, and I'm fine doing so most of the time, but it often comes up that I'm about to write out a for loop or something, and I stop and think about how much easier it would be in CS. Being able to just write that out inline as a kind of super snippet without having to drop to another buffer, compile, then copy to my JS would make me so happy.

zakdances commented 11 years ago

+1

lavrton commented 11 years ago
  1. Update plugin.
  2. Go to js file.
  3. Write some coffee.
  4. Select coffee code.
  5. Try "fast compile" command.
  6. See results.
  7. Go to this page.
  8. Write feedback.
franklin-ross commented 11 years ago

Fantastic! I've only been using it for 10 minutes but so far so good!

My only small quibble thus far is with indentation. There seems to be some extra indentation added with closing braces in the resulting Javascript. I'll copy some code below to try and highlight.

Given this CoffeeScript snipped

eat food for food in meal when food?

I expect the resulting Javascript to be (this is what the 'Display Javascript' command does)

var food, _i, _len;

for (_i = 0, _len = meal.length; _i < _len; _i++) {
  food = meal[_i];
  if (food != null) {
    eat(food);
  }
}

This is what is actually printed by the 'Fast Compile' command

var food, _i, _len;

for (_i = 0, _len = meal.length; _i < _len; _i++) {
  food = meal[_i];
    if (food != null) {
        eat(food);
          }
          }

I guess it could be something to do with Sublime's indentation settings or something when the text is replaced, I'm not sure. It's not a big deal anyway because the code is perfectly valid and not hard to just reindent manually.

I'll let you know if I see anything else in the future.

lavrton commented 11 years ago

Fixed via https://github.com/aponxi/sublime-better-coffeescript/commit/d101a6e3b2cd9ab57c2f4f5dc01ea574935520e8