CoffeeScript

From WikEmacs
Revision as of 14:54, 8 April 2014 by Elvince (talk | contribs) (coffee script)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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