Giter VIP home page Giter VIP logo

coffee-mode's Introduction

CoffeeScript Major Mode melpa badge melpa stable badge

An Emacs major mode for CoffeeScript and IcedCoffeeScript.

Provides syntax highlighting, indentation support, imenu support, a menu bar, and a few cute commands.

Screenshot

Requirement

  • Emacs 24.1 or higher

Installation

You can install coffee-mode from MELPA with package.el.

Please do not install GNU Emacs Lisp Package Archive version. It's too old and many features(triple quote etc) are not implemented.

Whitespace

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 whitespace-mode, or global-whitespace-mode.

Indentation

To set the number of spaces used with each additional indentation, add this to your .emacs or 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 File Variables.

# Local variables:
# coffee-tab-width: 4
# End:

Using TAB

Set coffee-indent-tabs-mode t if you want to use TAB instead of spaces.

Move to corresponding point in JavaScript file after compiling

You can archive this with sourcemap and following configuration. You can install sourcemap package from MELPA.

(setq coffee-args-compile '("-c" "-m")) ;; generating sourcemap
(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)

imenu

If you're using imenu, coffee-mode should work just fine. This means users of textmate.el will find that โ‡งโŒ˜T (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

Key Command
C-m, Return Insert newline and indent line
C-c C-<, backtab Indent line or region to left
C-c C-> Indent line or region to right
C-M-a Move to beginning of defun
C-M-e Move to end of defun
C-M-h Mark this defun
A-r, C-c C-k Compile buffer to JavaScript
A-R Compile content of region to JavaScript
A-M-r, C-c C-z Run CoffeeScript REPL
C-c C-l Send this line to REPL buffer
C-c C-r Send content of region to REPL buffer
C-c C-b Send content of buffer to REPL buffer
C-c C-o C-s Enable coffee-cos-mode

Commands

easymenu

If you have easymenu you can get to any of these commands from the menu bar:

coffee-mode menu bar

coffee-repl

Launch a CoffeeScript REPL

coffee-compile-file

Compile buffer to JavaScript.

coffee-compile-buffer

Compile region to JavaScript

coffee-watch

Run coffee with the --watch flag on a directory or file.

coffee-cos-mode

Minor mode for compiling to JavaScript at save file.

Sample Configuration

;; coffeescript
(custom-set-variables
 '(coffee-tab-width 2)
 '(coffee-args-compile '("-c" "--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)))

Bugs

Please file bugs at http://github.com/defunkt/coffee-mode/issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.