CoffeeScript

From WikEmacs
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

CoffeeScript is a little language that compiles to JavaScript.

Coffee mode

There is a major mode to edit Coffee and it is available in ELPA: coffee-mode. Its installation is then straightforward: M-x package-install RET coffee-mode RET.

See its documentation: https://github.com/defunkt/coffee-mode/

Flymake

A flymake handler for syntax-checking Coffeescript source code using coffeelint or coffee: https://github.com/purcell/flymake-coffee

Tips and tricks

Convert snippet from JavaScript to Coffee

Coffee-mode comes with a nice function which is not documented. If you copy a JS snippet from the web you'll want to convert it to coffee. While there are online tools, you can do the following:

  • install `js2coffee` with `npm`:
   npm install -g js2coffee  # npm comes with nodejs
  • now select a region and call M-x coffee-js2coffee-replace-region