CoffeeScript Major Mode
Provides syntax highlighting, indentation support, imenu support, a menu bar, and a few cute commands.
- Emacs 24.3 or higher
- CoffeeScript 1.9.3 or higher
Installation via package.el
You can install
coffee-mode with the following command.
M-x package-install [RET] coffee-mode [RET]
Please do not install GNU Emacs Lisp Package Archive version.
It's too old and many features(Block string, block comment etc) are not implemented.
coffee-mode used to offer automatic deletion of trailing whitespace.
This is now left to
whitespace-mode. See its documentation for full
details, but as a hint, configure:
;; automatically clean up bad whitespace (setq whitespace-action '(auto-cleanup)) ;; only show bad whitespace (setq whitespace-style '(trailing space-before-tab indentation empty space-after-tab))
Then turn on
To set the number of spaces used with each additional indentation, add this to your
init.el or other initialization file:
;; This gives you a tab of 2 spaces (custom-set-variables '(coffee-tab-width 2))
coffee-tab-width is buffer local variable. You can set indentation size
per buffer by using
# Local variables: # coffee-tab-width: 4 # End:
coffee-indent-tabs-mode t if you want to use TAB instead of spaces.
You can archive this with sourcemap and following configuration.
You can install
sourcemap package from MELPA.
;; generating sourcemap by '-m' option. And you must set '--no-header' option (setq coffee-args-compile '("-c" "--no-header" "-m")) (add-hook 'coffee-after-compile-hook 'sourcemap-goto-corresponding-point) ;; If you want to remove sourcemap file after jumping corresponding point (defun my/coffee-after-compile-hook (props) (sourcemap-goto-corresponding-point props) (delete-file (plist-get props :sourcemap))) (add-hook 'coffee-after-compile-hook 'my/coffee-after-compile-hook)
If you're using imenu,
coffee-mode should work just fine. This
means users of textmate.el will find that
textmate-go-to-symbol) mostly works as expected.
If you're not using imenu check out this page or textmate.el for a really awesome way to jump quickly to a function's definition in a file.
Default Key Bindings
||Insert newline and indent line|
||Indent line or region to left|
||Indent line or region to right|
||Move to beginning of defun|
||Move to end of defun|
||Mark this defun|
||Run CoffeeScript REPL|
||Send this line to REPL buffer|
||Send content of region to REPL buffer|
||Send content of buffer to REPL buffer|
Return key insert newline and indentation. If you don't want indentation please overwrite it as below.
(define-key coffee-mode-map (kbd "C-m") 'newline)
If you have
easymenu you can get to any of these commands from the
Launch a CoffeeScript REPL
coffee with the
--watch flag on a directory or file.
Minor mode for compiling buffer in real time.
Indent like python-mode
coffee-indent-like-python-mode is non-nil, indent command works like
I suppose that Evil's
works as you expect with this option.
(custom-set-variables '(coffee-indent-like-python-mode t))
;; coffeescript (custom-set-variables '(coffee-tab-width 2) '(coffee-args-compile '("-c" "--no-header" "--bare"))) (eval-after-load "coffee-mode" '(progn (define-key coffee-mode-map [(meta r)] 'coffee-compile-buffer) (define-key coffee-mode-map (kbd "C-j") 'coffee-newline-and-indent)))
Please file bugs at https://github.com/defunkt/coffee-mode/issues