Sublime Forum

CoffeeScript

#1

Hi, could I request coffeescript syntax (highligting) support?

And one other thing… When I’m saving a new coffeescript file (.coffee), the resulting filename gets an extension I don’t want (“sth.coffee” -> “sth.coffee.js”) unless I choose “All files” as the file type. It would be great if there was a “CoffeeScript” item in the file type selectbox (either as a new item or added to the JS one).

Thanks in advance.

0 Likes

#2

Looks like you can find a Coffeescript tmLanguage file here: github.com/jashkenas/coffee-scr … tmLanguage
Make a folder inside your packages directory called Coffeescript and throw the tmLanguage file in there, and you should be good to go.

0 Likes

#3

Wow, awesome. Thanks a bunch!

0 Likes

#4

Doesn’t seem to work on Sublime Text 2 on Win7. Tried putting Program Files/Sublime Text 2/Coffeescript/Coffeescript.tmLanguage and also in the Pristine Packages folder, neither works…

0 Likes

#5

Are you sure you are placing it in the right directory?

See:
http://sublimetext.info/docs/basic_concepts.html#the-data-directory
http://sublimetext.info/docs/basic_concepts.html#the-packages-directory

0 Likes

#6

Didn’t know about the %APPDATA% folder, was placing it in Sublime app’s folder in Program Files. Works now, thanks!

0 Likes

#7

I’m the author of the PragProg book on CoffeeScript (http://pragprog.com/titles/tbcoffee/coffeescript), and I’d like to migrate from TextMate to Sublime Text 2. Syntax highlighting with the tmbundle works quite well, but you don’t get any of the commands (though you can hack in a “Build” command pretty easily—see prototypef.tumblr.com/post/72110 … ime-text-2).

Things I miss most:

  1. Being able to build or run a file, or just a selection
  2. Comment toggling (ST2 can do this just fine in Ruby, so why not in CoffeeScript?)
  3. Automatic indentation (type -> or if x, for instance, and hit enter; in TextMate, you get a tab for free)

I love the sleekness, speed and stability of Sublime Text 2, but #1 and #2 on this list are must-have features for CoffeeScript devs.

0 Likes

#8

sublimetext.info/docs/en/core/build_systems.html

0 Likes

#9

[quote=“TrevorBurnham”]I’m the author of the PragProg book on CoffeeScript (http://pragprog.com/titles/tbcoffee/coffeescript), and I’d like to migrate from TextMate to Sublime Text 2. Syntax highlighting with the tmbundle works quite well, but you don’t get any of the commands (though you can hack in a “Build” command pretty easily—see prototypef.tumblr.com/post/72110 … ime-text-2).

Things I miss most:

  1. Being able to build or run a file, or just a selection
  2. Comment toggling (ST2 can do this just fine in Ruby, so why not in CoffeeScript?)
  3. Automatic indentation (type -> or if x, for instance, and hit enter; in TextMate, you get a tab for free)

I love the sleekness, speed and stability of Sublime Text 2, but #1 and #2 on this list are must-have features for CoffeeScript devs.[/quote]

Even though I own Textmate, I have to use Windows or Linux at work, so I was using Emacs for all my CoffeeScript stuff. I just started using Sublime Text 2, so I’m going to do my next project using the CoffeeScript plugin.

I wish your book was available on Amazon… I’m a “Prime” member, so I’d love to use the free shipping. Otherwise, I’ll try to make my job pay for it. I’ve been waiting for the release!!!

0 Likes

#10

These last two items are controlled by .tmPreferences files, which you’ll want to download also (github.com/jashkenas/coffee-scr … references), and place next to your .tmLanguage file - comment toggling, auto indent, and goto symbol should all work after that.

0 Likes

#11

Thanks, jps! That did indeed give me the comment toggling and indentation support that I craved. Now if only someone who’s handier with Python than I am would write a plugin to provide Build/Run functionality that works on both whole files and selected text, like in the TM bundle…

0 Likes

#12

for #1 I created a small build file

{
“cmd”: “coffee”, “-p”, “$file”],
“selector” : “source.coffee”,
“path” : “/usr/local/bin”
}

but this compile the entire file I couldn’t find a way to make it work just for highlighted text, which I find much more useful

Also, I noticed there is no syntax highlighting for variables when u use string interpolation “#{foo}bar” foo and bar are the same color

Is there a way in sublime to set the default file type to coffeescript for example so I can get syntax highlighting before saving the file ?

0 Likes

#13

Take a look here: https://forum.sublimetext.com/t/default-new-file/3069/1

You can also change the syntax highlight via the command palette. Just hit ctrl+shift+p and search for the language you want to use for syntax highlighting .

0 Likes

#14

Great, thks a lot I installed “default file type” through package control, I guess that one the one you were talking about,
Just need to find a way to compile just the highlighted text and sublime will be the perfect coffee editor for me !
One last thing is it possible to get text highlight in the build pane ?

0 Likes

#15

Thanks to all for the tips on getting Coffeescript highlighting to work. So nice to finally have this! For those coming to this topic for a how-to, I will sum it up here:

  1. Create a Coffeescript directory in the Sublime Packages directory.

  2. Download Coffeescript.tmLanguage
    and place in Coffeescript directory.

  3. Download Coffeescript.tmPreferences
    and place in Coffeescript directory.

The Sublime Packages directory can be found at:

Windows: %APPDATA%/Sublime Text 2/Packages
OS X: ~/Library/Application Support/Sublime Text 2/Package
Linux: ~/.Sublime Text 2/Packages
Portable Installation:Sublime Text 2/Data/Packages

0 Likes

#16

I know I’m late to the party, thanks phatmann for the outlined instructions.

One problem I noticed is that auto indenting doesn’t work in .coffee files. Is there something I can do to let Sublime know that the construct “->” represents a scope (as well as if, else, etc…)?

0 Likes

#17

I’ll answer my own question and address anyone else wondering how to get the entire CoffeeScript bundle working.

I extracted the entire contents of the TextMate bundle mentioned in this thread (github.com/jashkenas/coffee-script-tmbundle) into a CoffeeScript directory inside the Packages directory. This enabled all snippets and indenting issues I had.

0 Likes

#18

Trevor: were you able to transfer to Sublime? Especially ST3?

I’ve got the problem that, within HTML using the coffee-script.js inline compiler, the HTML package does not use the CS package while editing the CS.

0 Likes