CoffeeScript syntax definitions build system and snippets for Sublime Text.
This package is for Sublime Text 3+.
An old version for Sublime Text 2 is accessible via the st2 branch.
Installation
Package Control
The easiest way to install is using Package Control. It's listed as CoffeeScript.
- Open
Command Paletteusing ctrl+shift+P or menu itemTools → Command Palette... - Choose
Package Control: Install Package - Find
CoffeeScriptand hit Enter
Manual Install
- Download appropriate CoffeeScript.sublime-package for your Sublime Text build.
- Copy it into Installed Packages directory
Note
To find Installed Packages...
- call Menu > Preferences > Browse Packages..
- Navigate to parent folder
Warning
Manually installed packages are not automatically updated by Package Control.
Source Control
Tip
Only recommended, if contributions to this package are planned.
Sublime stores packages in the following locations:
Nix: ~/.config/sublime-text/packages Mac: ~/Library/Application\ Support/Sublime\ Text/Packages Win: %APPDATA%\Sublime Text\Packages
As a repository within the packages directory
Open a Terminal/Console and run the following commands, replacing PACKAGE_PATH with the path corresponding to your OS above.
cd PACKAGE_PATH git clone https://github.com/SublimeText/BetterCoffeeScript.git "CoffeeScript"
As a repository outside of the packages directory
If you use Github for Mac/Windows which store repositories in a specific location, or if you just don't want a repository in your packages directory, then instead you can use a link.
-
Clone the repository via GUI program or command line:
cd WHEREVER_YOU_WANT git clone https://github.com/SublimeText/BetterCoffeeScript.git -
Once that is done, create the link:
Windows:
cd PACKAGE_PATH mklink /D "CoffeeScript" ABSOLUTE_PATH_TO_REPOSITORY
Nix/Mac:
cd PACKAGE_PATH ln -s ABSOLUTE_PATH_TO_REPOSITORY "CoffeeScript"
Commands/Shortcuts
You can access the commands either using the command palette (ctrl+shift+P or cmd+shift+P) or via shortcuts.
alt+shift+t - Run a Cake task alt+shift+r - Run some CoffeeScript (prints output to a panel on the bottom) alt+shift+s - Run a syntax check alt+shift+c - Compile a file alt+shift+d - Display compiled JavaScript alt+shift+l - Display lexer tokens alt+shift+n - Display parser nodes alt+shift+w - Toggle watch mode alt+shift+p - Toggle output panel
Context menu has Compile Output that compiles the current CoffeeScript and outputs the javascript code that is run, in a panel.
Note: Some of the commands use the Status Bar for output, so you'll probably want to enable it (View » Show Status Bar).
Snippets
- Use
TABto run a snippet after typing the trigger. - Use
TABandshift+TABto cycle forward/backward through fields. - Use
ESCto exit snippet mode.
Snippet Triggers
Comprehension
Array: forin Object: forof Range: fori (inclusive) Range: forx (exclusive)
Statements
If: if Else: el If Else: ifel Else If: elif Switch: swi Ternary: ter Try Catch: try Unless: unl
Classes
Class - cla Class extends SuperClass - clx
Other
Function: - Function: = (bound) Interpolation: #
Building
When using the build system, it is assumed that your
.sublime-projectfile lives in your project's base directory (due to limitations with the build system).
Hitting F7 (Tools » Build) will run the Cake task 'sbuild'.
If you're not quite sure what the point of this is then read on.
Let's say before distributing your project that you would like to combine all of your .js files into one and then minify them them using UglifyJS or something.
That's what this is for! You would create a Cakefile and inside it you would write a task:
task 'sbuild', 'Prepare project for distribution.', -> # ...
Settings
Go to Preferences > Package Settings > CoffeeScript > Settings - User to change settings.
Project settings
Go to Project > Edit Project to change project settings.
{
"folders": [
"."
],
"settings": {
"CoffeeScript": {
"noWrapper": true,
"compileOnSave": true,
"compileDir": "out"
}
}
}FAQ
Most of the linux terminal commands written here can be run via cygwin - aka Linux Terminal in Windows.
-
Most of the problems are related to configurations. Remember to configure
binDirafter you install! -
Do I have coffee-script installed?
Try finding coffee-script in your global npm list with npm ls -g | grep coffee which will output something like:
npm ls -g | grep coffee # will output: #├── coffee-script@1.6.3 #├─┬ coffeelint@0.5.6 #│ ├── coffee-script@1.6.3 #├── UNMET DEPENDENCY generator-coffee * #│ │ ├── coffee-script@1.3.3
- Where can I find out the path to coffee binary?
In Linux which command will tell you where a command originates from. In terminal type:
which coffee
# /usr/bin/coffeeThis path will go into the binDir setting.
- I'm getting the error message
'coffee' is not recognized as an internal or external command,when saving.
The coffee-script binary probably is not installed. Either install coffee-script or set checkSyntaxOnSave and compileOnSave to false in Preferences > Package Settings > CoffeeScript > Settings - User.
