Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 855 lines (690 sloc) 27.856 kb
4a11c70 @defunkt documentation
authored
1 ;;; coffee-mode.el --- Major mode to edit CoffeeScript files in Emacs
2
3 ;; Copyright (C) 2010 Chris Wanstrath
4
89203e8 @rrthomas Make version consistent and bump it to 0.4.1 (Fixes #61).
rrthomas authored
5 ;; Version: 0.4.1
4a11c70 @defunkt documentation
authored
6 ;; Keywords: CoffeeScript major mode
7 ;; Author: Chris Wanstrath <chris@ozmm.org>
1d2aed3 @defunkt Use correct URL. Fixes #71
authored
8 ;; URL: http://github.com/defunkt/coffee-mode
4a11c70 @defunkt documentation
authored
9
10 ;; This file is not part of GNU Emacs.
11
12 ;; This program is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
16
17 ;; This program is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
21
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with this program; if not, write to the Free Software
24 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25
26 ;;; Commentary
27
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
28 ;; Provides syntax highlighting, indentation support, imenu support,
29 ;; a menu bar, and a few cute commands.
4a11c70 @defunkt documentation
authored
30
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
31 ;; ## Indentation
4a11c70 @defunkt documentation
authored
32
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
33 ;; ### TAB Theory
4a11c70 @defunkt documentation
authored
34
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
35 ;; It goes like this: when you press `TAB`, we indent the line unless
36 ;; doing so would make the current line more than two indentation levels
37 ;; deepers than the previous line. If that's the case, remove all
38 ;; indentation.
4a11c70 @defunkt documentation
authored
39
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
40 ;; Consider this code, with point at the position indicated by the
41 ;; caret:
4a11c70 @defunkt documentation
authored
42
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
43 ;; line1()
44 ;; line2()
45 ;; line3()
46 ;; ^
4a11c70 @defunkt documentation
authored
47
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
48 ;; Pressing `TAB` will produce the following code:
4a11c70 @defunkt documentation
authored
49
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
50 ;; line1()
51 ;; line2()
52 ;; line3()
53 ;; ^
4a11c70 @defunkt documentation
authored
54
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
55 ;; Pressing `TAB` again will produce this code:
56
57 ;; line1()
58 ;; line2()
59 ;; line3()
60 ;; ^
61
62 ;; And so on. I think this is a pretty good way of getting decent
63 ;; indentation with a whitespace-sensitive language.
64
65 ;; ### Newline and Indent
66
67 ;; We all love hitting `RET` and having the next line indented
68 ;; properly. Given this code and cursor position:
69
70 ;; line1()
71 ;; line2()
72 ;; line3()
73 ;; ^
74
75 ;; Pressing `RET` would insert a newline and place our cursor at the
76 ;; following position:
77
78 ;; line1()
79 ;; line2()
80 ;; line3()
81
82 ;; ^
83
84 ;; In other words, the level of indentation is maintained. This
85 ;; applies to comments as well. Combined with the `TAB` you should be
86 ;; able to get things where you want them pretty easily.
87
88 ;; ### Indenters
89
90 ;; `class`, `for`, `if`, and possibly other keywords cause the next line
91 ;; to be indented a level deeper automatically.
92
93 ;; For example, given this code and cursor position::
94
95 ;; class Animal
96 ;; ^
97
98 ;; Pressing enter would produce the following:
99
100 ;; class Animal
101
102 ;; ^
103
104 ;; That is, indented a column deeper.
105
106 ;; This also applies to lines ending in `->`, `=>`, `{`, `[`, and
107 ;; possibly more characters.
108
109 ;; So this code and cursor position:
110
111 ;; $('#demo').click ->
112 ;; ^
113
114 ;; On enter would produce this:
115
116 ;; $('#demo').click ->
117
118 ;; ^
119
120 ;; Pretty slick.
121
122 ;; Thanks to Jeremy Ashkenas for CoffeeScript, and to
123 ;; http://xahlee.org/emacs/elisp_syntax_coloring.html, Jason
124 ;; Blevins's markdown-mode.el and Steve Yegge's js2-mode for guidance.
38ce8da @defunkt small tweaks
authored
125
12bd5d0 @defunkt todo
authored
126 ;; TODO:
127 ;; - Make prototype accessor assignments like `String::length: -> 10` pretty.
5b00ae2 @defunkt more todo
authored
128 ;; - mirror-mode - close brackets and parens automatically
12bd5d0 @defunkt todo
authored
129
130 ;;; Code:
131
6639c36 @mkhl Silence byte-compiler warnings.
mkhl authored
132 (require 'comint)
38ce8da @defunkt small tweaks
authored
133 (require 'easymenu)
134 (require 'font-lock)
6639c36 @mkhl Silence byte-compiler warnings.
mkhl authored
135
136 (eval-when-compile
137 (require 'cl))
0480381 @defunkt mini docs
authored
138
7557530 @defunkt compilation commands
authored
139 ;;
38ce8da @defunkt small tweaks
authored
140 ;; Customizable Variables
7557530 @defunkt compilation commands
authored
141 ;;
142
89203e8 @rrthomas Make version consistent and bump it to 0.4.1 (Fixes #61).
rrthomas authored
143 (defconst coffee-mode-version "0.4.1"
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
144 "The version of `coffee-mode'.")
5f14029 @defunkt Menu
authored
145
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
146 (defgroup coffee nil
147 "A CoffeeScript major mode."
148 :group 'languages)
149
150 (defcustom coffee-tab-width tab-width
151 "The tab width to use when indenting."
152 :type 'integer
153 :group 'coffee)
154
155 (defcustom coffee-command "coffee"
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
156 "The CoffeeScript command used for evaluating code."
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
157 :type 'string
158 :group 'coffee)
7557530 @defunkt compilation commands
authored
159
2c204ef @mizchi add coffee-js2coffee-replace-region
mizchi authored
160 (defcustom js2coffee-command "js2coffee"
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
161 "The js2coffee command used for evaluating code."
2c204ef @mizchi add coffee-js2coffee-replace-region
mizchi authored
162 :type 'string
163 :group 'coffee)
164
3b0962d @defunkt Rename `args` variables to be more consistent.
authored
165 (defcustom coffee-args-repl '("-i")
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
166 "The arguments to pass to `coffee-command' to start a REPL."
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
167 :type 'list
168 :group 'coffee)
28485fa @defunkt `coffee-repl'
authored
169
227a360 @orlandohill Customize args for compiling files and display the first compiler error
orlandohill authored
170 (defcustom coffee-args-compile '("-c")
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
171 "The arguments to pass to `coffee-command' to compile a file."
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
172 :type 'list
173 :group 'coffee)
5f14029 @defunkt Menu
authored
174
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
175 (defcustom coffee-compiled-buffer-name "*coffee-compiled*"
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
176 "The name of the scratch buffer used for compiled CoffeeScript."
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
177 :type 'string
178 :group 'coffee)
7557530 @defunkt compilation commands
authored
179
14a0d56 @errge Added coffee-compile-jump-to-error.
errge authored
180 (defcustom coffee-compile-jump-to-error t
181 "Whether to jump to the first error if compilation fails.
e5f93e8 @rrthomas Improve the coffee-compile-jump-to-error docstring.
rrthomas authored
182 Since the coffee compiler does not always include a line number in
183 its error messages, this is not always possible."
14a0d56 @errge Added coffee-compile-jump-to-error.
errge authored
184 :type 'boolean
185 :group 'coffee)
186
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
187 (defcustom coffee-watch-buffer-name "*coffee-watch*"
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
188 "The name of the scratch buffer used when using the --watch flag
189 with CoffeeScript."
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
190 :type 'string
191 :group 'coffee)
192
6d1d92d @rrthomas Make coffee-mode-hook customizable.
rrthomas authored
193 (defcustom coffee-mode-hook nil
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
194 "Hook called by `coffee-mode'. Examples:
195
196 ;; CoffeeScript uses two spaces.
197 (make-local-variable 'tab-width)
198 (set 'tab-width 2)
199
200 ;; If you don't want your compiled files to be wrapped
201 (setq coffee-args-compile '(\"-c\" \"--bare\"))
202
203 ;; Emacs key binding
204 (define-key coffee-mode-map [(meta r)] 'coffee-compile-buffer)
205
206 ;; Bleeding edge.
207 (setq coffee-command \"~/dev/coffee\")
208
209 ;; Compile '.coffee' files on every save
210 (and (file-exists-p (buffer-file-name))
211 (file-exists-p (coffee-compiled-file-name))
212 (coffee-cos-mode t)))"
6d1d92d @rrthomas Make coffee-mode-hook customizable.
rrthomas authored
213 :type 'hook
214 :group 'coffee)
1b887a5 @defunkt clean whitespace on save
authored
215
677cf42 fix some really obnoxious indentation
Justine Tunney authored
216 (defvar coffee-mode-map
217 (let ((map (make-sparse-keymap)))
218 ;; key bindings
219 (define-key map (kbd "A-r") 'coffee-compile-buffer)
220 (define-key map (kbd "A-R") 'coffee-compile-region)
221 (define-key map (kbd "A-M-r") 'coffee-repl)
222 (define-key map [remap comment-dwim] 'coffee-comment-dwim)
223 (define-key map [remap newline-and-indent] 'coffee-newline-and-indent)
224 (define-key map "\C-m" 'coffee-newline-and-indent)
225 (define-key map "\C-c\C-o\C-s" 'coffee-cos-mode)
67e8727 backspace now de-indents instead of just going back a space.
Shawn Krisman authored
226 (define-key map "\177" 'coffee-dedent-line-backspace)
e45ce09 @akheron Add functions for shifting blocks of code left and right
akheron authored
227 (define-key map (kbd "C-c C-<") 'coffee-indent-shift-left)
228 (define-key map (kbd "C-c C->") 'coffee-indent-shift-right)
677cf42 fix some really obnoxious indentation
Justine Tunney authored
229 map)
eee29e0 @defunkt defvar the keymap
authored
230 "Keymap for CoffeeScript major mode.")
231
38ce8da @defunkt small tweaks
authored
232 ;;
233 ;; Commands
234 ;;
235
28485fa @defunkt `coffee-repl'
authored
236 (defun coffee-repl ()
237 "Launch a CoffeeScript REPL using `coffee-command' as an inferior mode."
238 (interactive)
239
17150cf @defunkt docs and starting to implement indenters
authored
240 (unless (comint-check-proc "*CoffeeREPL*")
28485fa @defunkt `coffee-repl'
authored
241 (set-buffer
17150cf @defunkt docs and starting to implement indenters
authored
242 (apply 'make-comint "CoffeeREPL"
d06825b @fred-o Workaround to avoid getting garbage chars in the comint buffer.
fred-o authored
243 "env"
244 nil (append (list "NODE_NO_READLINE=1" coffee-command) coffee-args-repl))))
28485fa @defunkt `coffee-repl'
authored
245
8a3d6f5 Updating coffee-repl to pop-to-buffer using the name '*CoffeeREPL*' inst...
Nick Parker authored
246 (pop-to-buffer "*CoffeeREPL*"))
38ce8da @defunkt small tweaks
authored
247
62c84fb @knu Add a function coffee-compiled-file-name for ease of scripting.
knu authored
248 (defun coffee-compiled-file-name (&optional filename)
249 "Returns the name of the JavaScript file compiled from a CoffeeScript file.
250 If FILENAME is omitted, the current buffer's file name is used."
251 (concat (file-name-sans-extension (or filename (buffer-file-name))) ".js"))
252
cbd31f9 @defunkt coffee-compile-file
authored
253 (defun coffee-compile-file ()
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
254 "Compiles and saves the current file to disk in a file of the same
255 base name, with extension `.js'. Subsequent runs will overwrite the
256 file.
257
258 If there are compilation errors, point is moved to the first
259 (see `coffee-compile-jump-to-error')."
cbd31f9 @defunkt coffee-compile-file
authored
260 (interactive)
227a360 @orlandohill Customize args for compiling files and display the first compiler error
orlandohill authored
261 (let ((compiler-output (shell-command-to-string (coffee-command-compile (buffer-file-name)))))
262 (if (string= compiler-output "")
62c84fb @knu Add a function coffee-compiled-file-name for ease of scripting.
knu authored
263 (message "Compiled and saved %s" (coffee-compiled-file-name))
14a0d56 @errge Added coffee-compile-jump-to-error.
errge authored
264 (let* ((msg (car (split-string compiler-output "[\n\r]+")))
66c326b @rrthomas Remove custom debug code; should use the standard Emacs debugging tools ...
rrthomas authored
265 (line (and (string-match "on line \\([0-9]+\\)" msg)
266 (string-to-number (match-string 1 msg)))))
267 (message msg)
268 (when (and coffee-compile-jump-to-error line (> line 0))
269 (goto-char (point-min))
270 (forward-line (1- line)))))))
cbd31f9 @defunkt coffee-compile-file
authored
271
7557530 @defunkt compilation commands
authored
272 (defun coffee-compile-buffer ()
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
273 "Compiles the current buffer and displays the JavaScript in a buffer
274 called `coffee-compiled-buffer-name'."
7557530 @defunkt compilation commands
authored
275 (interactive)
276 (save-excursion
277 (coffee-compile-region (point-min) (point-max))))
278
279 (defun coffee-compile-region (start end)
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
280 "Compiles a region and displays the JavaScript in a buffer called
281 `coffee-compiled-buffer-name'."
7557530 @defunkt compilation commands
authored
282 (interactive "r")
283
284 (let ((buffer (get-buffer coffee-compiled-buffer-name)))
285 (when buffer
286 (kill-buffer buffer)))
287
b4270de @semperos Allow existing `coffee-args-compile` to be used for `coffee-compile-regi...
semperos authored
288 (apply (apply-partially 'call-process-region start end coffee-command nil
289 (get-buffer-create coffee-compiled-buffer-name)
290 nil)
291 (append coffee-args-compile (list "-s" "-p")))
e3c21f8 @tav Change so that the compiled buffer doesn't open in a new frame.
tav authored
292 (switch-to-buffer (get-buffer coffee-compiled-buffer-name))
eb912a1 @bretthoerner Fix let paren placement in let form.
bretthoerner authored
293 (let ((buffer-file-name "tmp.js")) (set-auto-mode))
6639c36 @mkhl Silence byte-compiler warnings.
mkhl authored
294 (goto-char (point-min)))
3a47b28 @defunkt docs
authored
295
2c204ef @mizchi add coffee-js2coffee-replace-region
mizchi authored
296 (defun coffee-js2coffee-replace-region (start end)
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
297 "Convert JavaScript in the region into CoffeeScript."
2c204ef @mizchi add coffee-js2coffee-replace-region
mizchi authored
298 (interactive "r")
299
300 (let ((buffer (get-buffer coffee-compiled-buffer-name)))
301 (when buffer
302 (kill-buffer buffer)))
303
66c326b @rrthomas Remove custom debug code; should use the standard Emacs debugging tools ...
rrthomas authored
304 (call-process-region start end
2c204ef @mizchi add coffee-js2coffee-replace-region
mizchi authored
305 js2coffee-command nil
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
306 (current-buffer))
307 (delete-region start end))
2c204ef @mizchi add coffee-js2coffee-replace-region
mizchi authored
308
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
309 (defun coffee-version ()
310 "Show the `coffee-mode' version in the echo area."
5f14029 @defunkt Menu
authored
311 (interactive)
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
312 (message (concat "coffee-mode version " coffee-mode-version)))
5f14029 @defunkt Menu
authored
313
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
314 (defun coffee-watch (dir-or-file)
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
315 "Run `coffee-run-cmd' with the --watch flag on a directory or file."
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
316 (interactive "fDirectory or File: ")
317 (let ((coffee-compiled-buffer-name coffee-watch-buffer-name)
66c326b @rrthomas Remove custom debug code; should use the standard Emacs debugging tools ...
rrthomas authored
318 (args (mapconcat 'identity (append coffee-args-compile (list "--watch" (expand-file-name dir-or-file))) " ")))
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
319 (coffee-run-cmd args)))
320
5f14029 @defunkt Menu
authored
321 ;;
322 ;; Menubar
323 ;;
324
325 (easy-menu-define coffee-mode-menu coffee-mode-map
326 "Menu for CoffeeScript mode"
327 '("CoffeeScript"
cbd31f9 @defunkt coffee-compile-file
authored
328 ["Compile File" coffee-compile-file]
5f14029 @defunkt Menu
authored
329 ["Compile Buffer" coffee-compile-buffer]
330 ["Compile Region" coffee-compile-region]
5256afd @defunkt tweaks
authored
331 ["REPL" coffee-repl]
5f14029 @defunkt Menu
authored
332 "---"
333 ["Version" coffee-show-version]
334 ))
335
3a47b28 @defunkt docs
authored
336 ;;
337 ;; Define Language Syntax
338 ;;
339
c5831bb @sstephenson Fix for string literals with escaped quotes
sstephenson authored
340 ;; String literals
341 (defvar coffee-string-regexp "\"\\([^\\]\\|\\\\.\\)*?\"\\|'\\([^\\]\\|\\\\.\\)*?'")
342
3a47b28 @defunkt docs
authored
343 ;; Instance variables (implicit this)
2bb69be Regex for "this" variable includes underscore.
Ryan Koopmans authored
344 (defvar coffee-this-regexp "@\\(\\w\\|_\\)*\\|this")
3a47b28 @defunkt docs
authored
345
dc85f42 @tav Added support for the shorthand::syntax for .prototype.
tav authored
346 ;; Prototype::access
347 (defvar coffee-prototype-regexp "\\(\\(\\w\\|\\.\\|_\\| \\|$\\)+?\\)::\\(\\(\\w\\|\\.\\|_\\| \\|$\\)+?\\):")
348
88e7b95 @defunkt better regexps, @blah: and {blah: true, blah2:true}
authored
349 ;; Assignment
37b481e @defunkt Better assignment highlighting for `:`
authored
350 (defvar coffee-assign-regexp "\\(\\(\\w\\|\\.\\|_\\|$\\)+?\s*\\):")
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
351
7c5b19b local variable assignment is now highlighted.
Shawn Krisman authored
352 ;; Local Assignment
279bd3c allow member assignment to be highlighted just like local vars.
Shawn Krisman authored
353 (defvar coffee-local-assign-regexp "\\(\\(_\\|\\w\\|\\$\\)+\\)\s+=")
7c5b19b local variable assignment is now highlighted.
Shawn Krisman authored
354
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
355 ;; Lambda
00c197b @defunkt elisp regexps are fun
authored
356 (defvar coffee-lambda-regexp "\\((.+)\\)?\\s *\\(->\\|=>\\)")
88e7b95 @defunkt better regexps, @blah: and {blah: true, blah2:true}
authored
357
76ed341 @defunkt class support in imenu
authored
358 ;; Namespaces
359 (defvar coffee-namespace-regexp "\\b\\(class\\s +\\(\\S +\\)\\)\\b")
360
af34f91 @defunkt Booleans, better colors
authored
361 ;; Booleans
3900a8c @Wilfred adding undefined to reserved words as part of coffee-boolean-regexp (not...
Wilfred authored
362 (defvar coffee-boolean-regexp "\\b\\(true\\|false\\|yes\\|no\\|on\\|off\\|null\\|undefined\\)\\b")
3a47b28 @defunkt docs
authored
363
dbb4ec5 @defunkt comment tweaks
authored
364 ;; Regular Expressions
1fb4956 @levskaya small fix of coffee-regexp-regexp so it doesn't cause massive hangs when...
levskaya authored
365 (defvar coffee-regexp-regexp "\\/\\(\\\\.\\|\\[\\(\\\\.\\|.\\)+?\\]\\|[^/
366 ]\\)+?\\/")
3a47b28 @defunkt docs
authored
367
cf028f8 @defunkt basics
authored
368 ;; JavaScript Keywords
d6b78ed @defunkt defvars and basic indentation
authored
369 (defvar coffee-js-keywords
af34f91 @defunkt Booleans, better colors
authored
370 '("if" "else" "new" "return" "try" "catch"
cf028f8 @defunkt basics
authored
371 "finally" "throw" "break" "continue" "for" "in" "while"
372 "delete" "instanceof" "typeof" "switch" "super" "extends"
7803688 Until and loop are keywords.
Ryan Koopmans authored
373 "class" "until" "loop"))
cf028f8 @defunkt basics
authored
374
375 ;; Reserved keywords either by JS or CS.
d6b78ed @defunkt defvars and basic indentation
authored
376 (defvar coffee-js-reserved
cf028f8 @defunkt basics
authored
377 '("case" "default" "do" "function" "var" "void" "with"
378 "const" "let" "debugger" "enum" "export" "import" "native"
379 "__extends" "__hasProp"))
380
381 ;; CoffeeScript keywords.
d6b78ed @defunkt defvars and basic indentation
authored
382 (defvar coffee-cs-keywords
0a39a40 add support for the "own" keyword (for own k, v of obj ...)
Justine Tunney authored
383 '("then" "unless" "and" "or" "is" "own"
134d8a8 "where" isn't a coffeescript keyword
Justine Tunney authored
384 "isnt" "not" "of" "by" "when"))
cf028f8 @defunkt basics
authored
385
80ebae6 Added support for iced coffeescript await and defer keywords.
Marius Kjeldahl authored
386 ;; Iced CoffeeScript keywords
387 (defvar iced-coffee-cs-keywords
388 '("await" "defer"))
389
0480381 @defunkt mini docs
authored
390 ;; Regular expression combining the above three lists.
fad39cc keywords can now be member names.
Shawn Krisman authored
391 (defvar coffee-keywords-regexp
392 ;; keywords can be member names.
0686a8a only the keywords are highlighted instead of text before them.
Shawn Krisman authored
393 (concat "[^.]"
394 (regexp-opt (append coffee-js-reserved
395 coffee-js-keywords
396 coffee-cs-keywords
397 iced-coffee-cs-keywords) 'words)))
cf028f8 @defunkt basics
authored
398
399
ff61700 @defunkt that was bothering me
authored
400 ;; Create the list for font-lock. Each class of keyword is given a
401 ;; particular face.
5256afd @defunkt tweaks
authored
402 (defvar coffee-font-lock-keywords
ff61700 @defunkt that was bothering me
authored
403 ;; *Note*: order below matters. `coffee-keywords-regexp' goes last
404 ;; because otherwise the keyword "state" in the function
405 ;; "state_entry" would be highlighted.
c5831bb @sstephenson Fix for string literals with escaped quotes
sstephenson authored
406 `((,coffee-string-regexp . font-lock-string-face)
407 (,coffee-this-regexp . font-lock-variable-name-face)
dc85f42 @tav Added support for the shorthand::syntax for .prototype.
tav authored
408 (,coffee-prototype-regexp . font-lock-variable-name-face)
ff61700 @defunkt that was bothering me
authored
409 (,coffee-assign-regexp . font-lock-type-face)
279bd3c allow member assignment to be highlighted just like local vars.
Shawn Krisman authored
410 (,coffee-local-assign-regexp 1 font-lock-variable-name-face)
ff61700 @defunkt that was bothering me
authored
411 (,coffee-regexp-regexp . font-lock-constant-face)
412 (,coffee-boolean-regexp . font-lock-constant-face)
bdb258b color -> and => as functions.
Shawn Krisman authored
413 (,coffee-lambda-regexp . (2 font-lock-function-name-face))
0686a8a only the keywords are highlighted instead of text before them.
Shawn Krisman authored
414 (,coffee-keywords-regexp 1 font-lock-keyword-face)))
cf028f8 @defunkt basics
authored
415
3a47b28 @defunkt docs
authored
416 ;;
417 ;; Helper Functions
418 ;;
419
9ff612a @defunkt single quotes
authored
420 (defun coffee-comment-dwim (arg)
421 "Comment or uncomment current line or region in a smart way.
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
422 For details, see `comment-dwim'."
9ff612a @defunkt single quotes
authored
423 (interactive "*P")
424 (require 'newcomment)
425 (let ((deactivate-mark nil) (comment-start "#") (comment-end ""))
426 (comment-dwim arg)))
84ab684 @defunkt comments
authored
427
227a360 @orlandohill Customize args for compiling files and display the first compiler error
orlandohill authored
428 (defun coffee-command-compile (file-name)
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
429 "Run `coffee-command' to compile FILE."
66c326b @rrthomas Remove custom debug code; should use the standard Emacs debugging tools ...
rrthomas authored
430 (let ((full-file-name (expand-file-name file-name)))
2d489a8 @semperos Add support for Cygwin-style absolute paths, which makes using the file ...
semperos authored
431 (mapconcat 'identity (append (list coffee-command) coffee-args-compile (list full-file-name)) " ")))
5b00ae2 @defunkt more todo
authored
432
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
433 (defun coffee-run-cmd (args)
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
434 "Run `coffee-command' with the given arguments, and display the
435 output in a compilation buffer."
0b06b86 @semperos Add support for coffee --watch, and in process also add function for run...
semperos authored
436 (interactive "sArguments: ")
437 (let ((compilation-buffer-name-function (lambda (this-mode)
438 (generate-new-buffer-name coffee-compiled-buffer-name))))
439 (compile (concat coffee-command " " args))))
440
2504ebe @defunkt explain indentation plan
authored
441 ;;
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
442 ;; imenu support
443 ;;
444
445 ;; This is a pretty naive but workable way of doing it. First we look
446 ;; for any lines that starting with `coffee-assign-regexp' that include
447 ;; `coffee-lambda-regexp' then add those tokens to the list.
448 ;;
449 ;; Should cover cases like these:
450 ;;
451 ;; minus: (x, y) -> x - y
452 ;; String::length: -> 10
453 ;; block: ->
454 ;; print('potion')
455 ;;
456 ;; Next we look for any line that starts with `class' or
457 ;; `coffee-assign-regexp' followed by `{` and drop into a
458 ;; namespace. This means we search one indentation level deeper for
459 ;; more assignments and add them to the alist prefixed with the
460 ;; namespace name.
461 ;;
462 ;; Should cover cases like these:
463 ;;
464 ;; class Person
465 ;; print: ->
466 ;; print 'My name is ' + this.name + '.'
467 ;;
468 ;; class Policeman extends Person
469 ;; constructor: (rank) ->
470 ;; @rank: rank
471 ;; print: ->
472 ;; print 'My name is ' + this.name + " and I'm a " + this.rank + '.'
473 ;;
76ed341 @defunkt class support in imenu
authored
474 ;; TODO:
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
475 ;; app = {
476 ;; window: {width: 200, height: 200}
477 ;; para: -> 'Welcome.'
478 ;; button: -> 'OK'
479 ;; }
480
481 (defun coffee-imenu-create-index ()
482 "Create an imenu index of all methods in the buffer."
483 (interactive)
484
485 ;; This function is called within a `save-excursion' so we're safe.
6639c36 @mkhl Silence byte-compiler warnings.
mkhl authored
486 (goto-char (point-min))
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
487
76ed341 @defunkt class support in imenu
authored
488 (let ((index-alist '()) assign pos indent ns-name ns-indent)
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
489 ;; Go through every assignment that includes -> or => on the same
c6562af @defunkt Make `coffee-debug' a macro
authored
490 ;; line or starts with `class'.
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
491 (while (re-search-forward
76ed341 @defunkt class support in imenu
authored
492 (concat "^\\(\\s *\\)"
493 "\\("
494 coffee-assign-regexp
495 ".+?"
496 coffee-lambda-regexp
497 "\\|"
498 coffee-namespace-regexp
499 "\\)")
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
500 (point-max)
501 t)
502
76ed341 @defunkt class support in imenu
authored
503 ;; If this is the start of a new namespace, save the namespace's
504 ;; indentation level and name.
7f5e1b3 @defunkt Bugfix: Clear old namespace when a new one is found
authored
505 (when (match-string 8)
506 ;; Set the name.
507 (setq ns-name (match-string 8))
508
76ed341 @defunkt class support in imenu
authored
509 ;; If this is a class declaration, add :: to the namespace.
510 (setq ns-name (concat ns-name "::"))
511
512 ;; Save the indentation level.
66c326b @rrthomas Remove custom debug code; should use the standard Emacs debugging tools ...
rrthomas authored
513 (setq ns-indent (length (match-string 1))))
76ed341 @defunkt class support in imenu
authored
514
515 ;; If this is an assignment, save the token being
516 ;; assigned. `Please.print:` will be `Please.print`, `block:`
517 ;; will be `block`, etc.
518 (when (setq assign (match-string 3))
519 ;; The position of the match in the buffer.
520 (setq pos (match-beginning 3))
521
522 ;; The indent level of this match
523 (setq indent (length (match-string 1)))
524
525 ;; If we're within the context of a namespace, add that to the
526 ;; front of the assign, e.g.
527 ;; constructor: => Policeman::constructor
528 (when (and ns-name (> indent ns-indent))
529 (setq assign (concat ns-name assign)))
530
531 ;; Clear the namespace if we're no longer indented deeper
532 ;; than it.
533 (when (and ns-name (<= indent ns-indent))
534 (setq ns-name nil)
535 (setq ns-indent nil))
536
537 ;; Add this to the alist. Done.
538 (push (cons assign pos) index-alist)))
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
539
540 ;; Return the alist.
541 index-alist))
542
543 ;;
d6b78ed @defunkt defvars and basic indentation
authored
544 ;; Indentation
2504ebe @defunkt explain indentation plan
authored
545 ;;
546
dbb4ec5 @defunkt comment tweaks
authored
547 ;;; The theory is explained in the README.
97a1001 @defunkt basic indentation with TAB
authored
548
d6b78ed @defunkt defvars and basic indentation
authored
549 (defun coffee-indent-line ()
7b03a71 @defunkt indentation theory
authored
550 "Indent current line as CoffeeScript."
d6b78ed @defunkt defvars and basic indentation
authored
551 (interactive)
552
df7ae3b @defunkt Bugfix: Indenting blank lines with TAB
authored
553 (if (= (point) (point-at-bol))
554 (insert-tab)
555 (save-excursion
3f4271f @rrthomas Simplify coffee-indent-line and coffee-previous-indent.
rrthomas authored
556 (let ((prev-indent (coffee-previous-indent))
557 (cur-indent (current-indentation)))
df7ae3b @defunkt Bugfix: Indenting blank lines with TAB
authored
558 ;; Shift one column to the left
559 (beginning-of-line)
560 (insert-tab)
561
562 (when (= (point-at-bol) (point))
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
563 (forward-char coffee-tab-width))
df7ae3b @defunkt Bugfix: Indenting blank lines with TAB
authored
564
565 ;; We're too far, remove all indentation.
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
566 (when (> (- (current-indentation) prev-indent) coffee-tab-width)
df7ae3b @defunkt Bugfix: Indenting blank lines with TAB
authored
567 (backward-to-indentation 0)
568 (delete-region (point-at-bol) (point)))))))
b7ee8b8 @defunkt start cleaning up indentation code
authored
569
570 (defun coffee-previous-indent ()
571 "Return the indentation level of the previous non-blank line."
572 (save-excursion
573 (forward-line -1)
d063614 @superbobry Fix hanging of `coffee-previous-indent` at start of buffer.
superbobry authored
574 (if (bobp)
575 0
576 (progn
3f4271f @rrthomas Simplify coffee-indent-line and coffee-previous-indent.
rrthomas authored
577 (while (and (looking-at "^[ \t]*$") (not (bobp))) (forward-line -1))
d063614 @superbobry Fix hanging of `coffee-previous-indent` at start of buffer.
superbobry authored
578 (current-indentation)))))
b7ee8b8 @defunkt start cleaning up indentation code
authored
579
17150cf @defunkt docs and starting to implement indenters
authored
580 (defun coffee-newline-and-indent ()
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
581 "Insert a newline and indent it to the same level as the previous line."
17150cf @defunkt docs and starting to implement indenters
authored
582 (interactive)
583
584 ;; Remember the current line indentation level,
585 ;; insert a newline, and indent the newline to the same
586 ;; level as the previous line.
587 (let ((prev-indent (current-indentation)) (indent-next nil))
74a9135 @piranha do not leave trailing whitespaces on newline
piranha authored
588 (delete-horizontal-space t)
17150cf @defunkt docs and starting to implement indenters
authored
589 (newline)
7976bc4 @defunkt Make config options available from `customize-group`, document in README
authored
590 (insert-tab (/ prev-indent coffee-tab-width))
3a47b28 @defunkt docs
authored
591
17150cf @defunkt docs and starting to implement indenters
authored
592 ;; We need to insert an additional tab because the last line was special.
593 (when (coffee-line-wants-indent)
594 (insert-tab)))
595
596 ;; Last line was a comment so this one should probably be,
597 ;; too. Makes it easy to write multi-line comments (like the one I'm
598 ;; writing right now).
599 (when (coffee-previous-line-is-comment)
600 (insert "# ")))
601
67e8727 backspace now de-indents instead of just going back a space.
Shawn Krisman authored
602 (defun coffee-dedent-line-backspace ()
603 "We want to be backspacing full tabs not just single characters."
604 (interactive)
605 (if (and (<= (point-marker) (save-excursion
606 (back-to-indentation)
607 (point-marker)))
608 (> (current-column) 0))
609 (backward-delete-char-untabify coffee-tab-width)
610 (backward-delete-char-untabify 1)))
611
17150cf @defunkt docs and starting to implement indenters
authored
612 ;; Indenters help determine whether the current line should be
613 ;; indented further based on the content of the previous line. If a
614 ;; line starts with `class', for instance, you're probably going to
615 ;; want to indent the next line.
616
9eca4aa @theJohnnyBrown indent following while statement
theJohnnyBrown authored
617 (defvar coffee-indenters-bol '("class" "for" "if" "try" "while")
7d338d1 @defunkt coffee-indenters
authored
618 "Keywords or syntax whose presence at the start of a line means the
619 next line should probably be indented.")
620
621 (defun coffee-indenters-bol-regexp ()
622 "Builds a regexp out of `coffee-indenters-bol' words."
27df14a @defunkt Fix coffee-indenters-bol-regexp. Closes #36
authored
623 (regexp-opt coffee-indenters-bol 'words))
7d338d1 @defunkt coffee-indenters
authored
624
5e170be @defunkt get it working (with a fake function though)
authored
625 (defvar coffee-indenters-eol '(?> ?{ ?\[)
626 "Single characters at the end of a line that mean the next line
627 should probably be indented.")
7d338d1 @defunkt coffee-indenters
authored
628
17150cf @defunkt docs and starting to implement indenters
authored
629 (defun coffee-line-wants-indent ()
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
630 "Return t if the current line should be indented relative to the
631 previous line."
8bfb7ed @defunkt Keep same indentation of last line when creating a new line
authored
632 (interactive)
633
17150cf @defunkt docs and starting to implement indenters
authored
634 (save-excursion
635 (let ((indenter-at-bol) (indenter-at-eol))
636 ;; Go back a line and to the first character.
637 (forward-line -1)
638 (backward-to-indentation 0)
8bfb7ed @defunkt Keep same indentation of last line when creating a new line
authored
639
17150cf @defunkt docs and starting to implement indenters
authored
640 ;; If the next few characters match one of our magic indenter
641 ;; keywords, we want to indent the line we were on originally.
642 (when (looking-at (coffee-indenters-bol-regexp))
66c326b @rrthomas Remove custom debug code; should use the standard Emacs debugging tools ...
rrthomas authored
643 (setq indenter-at-bol t))
17150cf @defunkt docs and starting to implement indenters
authored
644
645 ;; If that didn't match, go to the back of the line and check to
5e170be @defunkt get it working (with a fake function though)
authored
646 ;; see if the last character matches one of our indenter
647 ;; characters.
17150cf @defunkt docs and starting to implement indenters
authored
648 (when (not indenter-at-bol)
649 (end-of-line)
650
5e170be @defunkt get it working (with a fake function though)
authored
651 ;; Optimized for speed - checks only the last character.
65797fa @jaeyeom Fix missing function `some' issue when loading compiled elisp.
jaeyeom authored
652 (let ((indenters coffee-indenters-eol))
653 (while indenters
df0dfbc resolved issue #63. Fixed inspired by tzeskimo 6c5eb29.
Keith Simmons authored
654 (if (and (char-before) (/= (char-before) (car indenters)))
65797fa @jaeyeom Fix missing function `some' issue when loading compiled elisp.
jaeyeom authored
655 (setq indenters (cdr indenters))
656 (setq indenter-at-eol t)
657 (setq indenters nil)))))
17150cf @defunkt docs and starting to implement indenters
authored
658
659 ;; If we found an indenter, return `t'.
660 (or indenter-at-bol indenter-at-eol))))
661
8bfb7ed @defunkt Keep same indentation of last line when creating a new line
authored
662 (defun coffee-previous-line-is-comment ()
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
663 "Return t if the previous line is a CoffeeScript comment."
8bfb7ed @defunkt Keep same indentation of last line when creating a new line
authored
664 (save-excursion
665 (forward-line -1)
666 (coffee-line-is-comment)))
667
668 (defun coffee-line-is-comment ()
579e270 @rrthomas Overhaul the docstrings.
rrthomas authored
669 "Return t if the current line is a CoffeeScript comment."
8bfb7ed @defunkt Keep same indentation of last line when creating a new line
authored
670 (save-excursion
671 (backward-to-indentation 0)
672 (= (char-after) (string-to-char "#"))))
673
168b32d @disnet fixing triple quoted strings issue with code from python-mode
disnet authored
674
c5fb056 remove triple quotes, seems to be doing strange things to python-mode
Justine Tunney authored
675 ;; (defun coffee-quote-syntax (n)
676 ;; "Put `syntax-table' property correctly on triple quote.
677 ;; Used for syntactic keywords. N is the match number (1, 2 or 3)."
678 ;; ;; From python-mode...
679 ;; ;;
680 ;; ;; Given a triple quote, we have to check the context to know
681 ;; ;; whether this is an opening or closing triple or whether it's
682 ;; ;; quoted anyhow, and should be ignored. (For that we need to do
683 ;; ;; the same job as `syntax-ppss' to be correct and it seems to be OK
684 ;; ;; to use it here despite initial worries.) We also have to sort
685 ;; ;; out a possible prefix -- well, we don't _have_ to, but I think it
686 ;; ;; should be treated as part of the string.
687
688 ;; ;; Test cases:
689 ;; ;; ur"""ar""" x='"' # """
690 ;; ;; x = ''' """ ' a
691 ;; ;; '''
692 ;; ;; x '"""' x """ \"""" x
693 ;; (save-excursion
694 ;; (goto-char (match-beginning 0))
695 ;; (cond
696 ;; ;; Consider property for the last char if in a fenced string.
697 ;; ((= n 3)
698 ;; (let* ((font-lock-syntactic-keywords nil)
699 ;; (syntax (syntax-ppss)))
700 ;; (when (eq t (nth 3 syntax)) ; after unclosed fence
701 ;; (goto-char (nth 8 syntax)) ; fence position
702 ;; ;; (skip-chars-forward "uUrR") ; skip any prefix
703 ;; ;; Is it a matching sequence?
704 ;; (if (eq (char-after) (char-after (match-beginning 2)))
705 ;; (eval-when-compile (string-to-syntax "|"))))))
706 ;; ;; Consider property for initial char, accounting for prefixes.
707 ;; ((or (and (= n 2) ; leading quote (not prefix)
708 ;; (not (match-end 1))) ; prefix is null
709 ;; (and (= n 1) ; prefix
710 ;; (match-end 1))) ; non-empty
711 ;; (let ((font-lock-syntactic-keywords nil))
712 ;; (unless (eq 'string (syntax-ppss-context (syntax-ppss)))
713 ;; (eval-when-compile (string-to-syntax "|")))))
714 ;; ;; Otherwise (we're in a non-matching string) the property is
715 ;; ;; nil, which is OK.
716 ;; )))
168b32d @disnet fixing triple quoted strings issue with code from python-mode
disnet authored
717
ae2875f @akheron coffee-indent-shift-*: Indent to the closest increment of coffee-tab-wid...
akheron authored
718 (defun coffee-indent-shift-amount (start end dir)
719 "Compute distance to the closest increment of `coffee-tab-width'."
720 (let ((min most-positive-fixnum) rem)
721 (save-excursion
722 (goto-char start)
723 (while (< (point) end)
724 (let ((current (current-indentation)))
725 (when (< current min) (setq min current)))
726 (forward-line))
727 (setq rem (% min coffee-tab-width))
728 (if (zerop rem)
729 coffee-tab-width
730 (cond ((eq dir 'left) rem)
731 ((eq dir 'right) (- coffee-tab-width rem))
732 (t 0))))))
733
e45ce09 @akheron Add functions for shifting blocks of code left and right
akheron authored
734 (defun coffee-indent-shift-left (start end &optional count)
735 "Shift lines contained in region START END by COUNT columns to the left.
ae2875f @akheron coffee-indent-shift-*: Indent to the closest increment of coffee-tab-wid...
akheron authored
736 If COUNT is not given, indents to the closest increment of
737 `coffee-tab-width'. If region isn't active, the current line is
738 shifted. The shifted region includes the lines in which START and
739 END lie. An error is signaled if any lines in the region are
740 indented less than COUNT columns."
e45ce09 @akheron Add functions for shifting blocks of code left and right
akheron authored
741 (interactive
742 (if mark-active
743 (list (region-beginning) (region-end) current-prefix-arg)
744 (list (line-beginning-position) (line-end-position) current-prefix-arg)))
ae2875f @akheron coffee-indent-shift-*: Indent to the closest increment of coffee-tab-wid...
akheron authored
745 (let ((amount (if count (prefix-numeric-value count)
746 (coffee-indent-shift-amount start end 'left))))
747 (when (> amount 0)
748 (let (deactivate-mark)
749 (save-excursion
750 (goto-char start)
751 ;; Check that all lines can be shifted enough
752 (while (< (point) end)
753 (if (and (< (current-indentation) amount)
754 (not (looking-at "[ \t]*$")))
755 (error "Can't shift all lines enough"))
756 (forward-line))
757 (indent-rigidly start end (- amount)))))))
e45ce09 @akheron Add functions for shifting blocks of code left and right
akheron authored
758
759 (add-to-list 'debug-ignored-errors "^Can't shift all lines enough")
760
761 (defun coffee-indent-shift-right (start end &optional count)
ae2875f @akheron coffee-indent-shift-*: Indent to the closest increment of coffee-tab-wid...
akheron authored
762 "Shift lines contained in region START END by COUNT columns to the right.
763 if COUNT is not given, indents to the closest increment of
764 `coffee-tab-width'. If region isn't active, the current line is
765 shifted. The shifted region includes the lines in which START and
766 END lie."
e45ce09 @akheron Add functions for shifting blocks of code left and right
akheron authored
767 (interactive
768 (if mark-active
769 (list (region-beginning) (region-end) current-prefix-arg)
770 (list (line-beginning-position) (line-end-position) current-prefix-arg)))
ae2875f @akheron coffee-indent-shift-*: Indent to the closest increment of coffee-tab-wid...
akheron authored
771 (let (deactivate-mark
772 (amount (if count (prefix-numeric-value count)
773 (coffee-indent-shift-amount start end 'right))))
774 (indent-rigidly start end amount)))
e45ce09 @akheron Add functions for shifting blocks of code left and right
akheron authored
775
3a47b28 @defunkt docs
authored
776 ;;
777 ;; Define Major Mode
778 ;;
779
af021a5 @josh magic autoload comments
josh authored
780 ;;;###autoload
cf028f8 @defunkt basics
authored
781 (define-derived-mode coffee-mode fundamental-mode
4631aa1 Use "Coffee" as mode name rather than the idiosynchratic "coffee-mode".
Daniel Brockman authored
782 "Coffee"
783 "Major mode for editing CoffeeScript."
cf028f8 @defunkt basics
authored
784
785 ;; code for syntax highlighting
786 (setq font-lock-defaults '((coffee-font-lock-keywords)))
787
1c8aea3 @chellmuth Fix syntax highlighting for variables containing keywords bounded by
chellmuth authored
788 ;; treat "_" as part of a word
789 (modify-syntax-entry ?_ "w" coffee-mode-syntax-table)
790
84ab684 @defunkt comments
authored
791 ;; perl style comment: "# ..."
792 (modify-syntax-entry ?# "< b" coffee-mode-syntax-table)
793 (modify-syntax-entry ?\n "> b" coffee-mode-syntax-table)
40a5bf1 @defunkt comment-start is buffer local. fixes #10
authored
794 (make-local-variable 'comment-start)
0480381 @defunkt mini docs
authored
795 (setq comment-start "#")
84ab684 @defunkt comments
authored
796
9ff612a @defunkt single quotes
authored
797 ;; single quote strings
798 (modify-syntax-entry ?' "\"" coffee-mode-syntax-table)
799
c5fb056 remove triple quotes, seems to be doing strange things to python-mode
Justine Tunney authored
800 ;; (setq font-lock-syntactic-keywords
801 ;; ;; Make outer chars of matching triple-quote sequences into generic
802 ;; ;; string delimiters.
803 ;; ;; First avoid a sequence preceded by an odd number of backslashes.
804 ;; `((,(concat "\\(?:^\\|[^\\]\\(?:\\\\.\\)*\\)" ;Prefix.
805 ;; "\\(?:\\('\\)\\('\\)\\('\\)\\|\\(?1:\"\\)\\(?2:\"\\)\\(?3:\"\\)\\)")
806 ;; (1 (coffee-quote-syntax 1) nil lax)
807 ;; (2 (coffee-quote-syntax 2))
808 ;; (3 (coffee-quote-syntax 3)))))
168b32d @disnet fixing triple quoted strings issue with code from python-mode
disnet authored
809
d6b78ed @defunkt defvars and basic indentation
authored
810 ;; indentation
811 (make-local-variable 'indent-line-function)
812 (setq indent-line-function 'coffee-indent-line)
b4b2a53 @kelleyk Small patch to fix indentation behavior; before, the global tab-width se...
kelleyk authored
813 (set (make-local-variable 'tab-width) coffee-tab-width)
d6b78ed @defunkt defvars and basic indentation
authored
814
30d2af5 @defunkt Basic imenu support - makes things like `textmate-goto-symbol' work!
authored
815 ;; imenu
816 (make-local-variable 'imenu-create-index-function)
817 (setq imenu-create-index-function 'coffee-imenu-create-index)
818
d6b78ed @defunkt defvars and basic indentation
authored
819 ;; no tabs
be2305f @rrthomas Remove support for removing trailing whitespace: whitepace-mode does tha...
rrthomas authored
820 (setq indent-tabs-mode nil))
eaf28ab @defunkt register as .coffee handler
authored
821
6eb6d99 @knu Introduce a minor mode `coffee-cos-mode'.
knu authored
822 ;;
823 ;; Compile-on-Save minor mode
824 ;;
825
826 (defvar coffee-cos-mode-line " CoS")
827 (make-variable-buffer-local 'coffee-cos-mode-line)
828
829 (define-minor-mode coffee-cos-mode
20c919a @rrthomas Change installation instructions to advise use of ELPA.
rrthomas authored
830 "Toggle compile-on-save for coffee-mode.
831
832 Add `'(lambda () (coffee-cos-mode t))' to `coffee-mode-hook' to turn
833 it on by default."
6eb6d99 @knu Introduce a minor mode `coffee-cos-mode'.
knu authored
834 :group 'coffee-cos :lighter coffee-cos-mode-line
835 (cond
836 (coffee-cos-mode
837 (add-hook 'after-save-hook 'coffee-compile-file nil t))
838 (t
839 (remove-hook 'after-save-hook 'coffee-compile-file t))))
840
27ffada @defunkt provide something
authored
841 (provide 'coffee-mode)
842
eaf28ab @defunkt register as .coffee handler
authored
843 ;;
844 ;; On Load
845 ;;
846
847 ;; Run coffee-mode for files ending in .coffee.
af021a5 @josh magic autoload comments
josh authored
848 ;;;###autoload
eaf28ab @defunkt register as .coffee handler
authored
849 (add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode))
af021a5 @josh magic autoload comments
josh authored
850 ;;;###autoload
95bbfe3 autoload coffee-mode for .iced files (IcedCoffeeScript)
Justine Tunney authored
851 (add-to-list 'auto-mode-alist '("\\.iced$" . coffee-mode))
852 ;;;###autoload
605a330 @defunkt highlight Cakefile too
authored
853 (add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode))
a9c8f48 Formatting changes for complians with elp/Marmalade
Scott Barron authored
854 ;;; coffee-mode.el ends here
Something went wrong with that request. Please try again.