Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

defvars and basic indentation

  • Loading branch information...
commit d6b78ed7025c79d77e78dccae9fa7ac3a08c0dbc 1 parent af34f91
Chris Wanstrath authored March 06, 2010

Showing 1 changed file with 31 additions and 9 deletions. Show diff stats Hide diff stats

  1. 40  coffee-mode.el
40  coffee-mode.el
@@ -7,37 +7,37 @@
7 7
 ;;
8 8
 
9 9
 ;; Assignment
10  
-(setq coffee-type-regexp ".+?:")
  10
+(defvar coffee-type-regexp ".+?:")
11 11
 
12 12
 ;; Instance variables (implicit this)
13  
-(setq coffee-constant-regexp "@\\w*\\|this")
  13
+(defvar coffee-constant-regexp "@\\w*\\|this")
14 14
 
15 15
 ;; Booleans
16  
-(setq coffee-functions-regexp "\\b\\(true\\|false\\|yes\\|no\\|on\\|off\\)\\b")
  16
+(defvar coffee-functions-regexp "\\b\\(true\\|false\\|yes\\|no\\|on\\|off\\)\\b")
17 17
 
18 18
 ;; Unused
19  
-(setq coffee-event-regexp "")
  19
+(defvar coffee-event-regexp "")
20 20
 
21 21
 ;; JavaScript Keywords
22  
-(setq coffee-js-keywords
  22
+(defvar coffee-js-keywords
23 23
       '("if" "else" "new" "return" "try" "catch"
24 24
         "finally" "throw" "break" "continue" "for" "in" "while"
25 25
         "delete" "instanceof" "typeof" "switch" "super" "extends"
26 26
         "class"))
27 27
 
28 28
 ;; Reserved keywords either by JS or CS.
29  
-(setq coffee-js-reserved
  29
+(defvar coffee-js-reserved
30 30
       '("case" "default" "do" "function" "var" "void" "with"
31 31
         "const" "let" "debugger" "enum" "export" "import" "native"
32 32
         "__extends" "__hasProp"))
33 33
 
34 34
 ;; CoffeeScript keywords.
35  
-(setq coffee-cs-keywords
  35
+(defvar coffee-cs-keywords
36 36
       '("then" "unless" "and" "or" "is"
37 37
         "isnt" "not" "of" "by" "where" "when"))
38 38
 
39 39
 ;; Regular expression combining the above three lists.
40  
-(setq coffee-keywords-regexp (regexp-opt
  40
+(defvar coffee-keywords-regexp (regexp-opt
41 41
                                 (append
42 42
                                  coffee-js-reserved
43 43
                                  coffee-js-keywords
@@ -46,7 +46,7 @@
46 46
 
47 47
 ;; Create the list for font-lock.
48 48
 ;; Each class of keyword is given a particular face
49  
-(setq coffee-font-lock-keywords
  49
+(defvar coffee-font-lock-keywords
50 50
       `(
51 51
         (,coffee-type-regexp . font-lock-type-face)
52 52
         (,coffee-constant-regexp . font-lock-variable-name-face)
@@ -73,6 +73,21 @@ For detail, see `comment-dwim'."
73 73
   (let ((deactivate-mark nil) (comment-start "#") (comment-end ""))
74 74
     (comment-dwim arg)))
75 75
 
  76
+;; Indentation
  77
+(defun coffee-indent-line ()
  78
+  "Indent current line as CoffeeScript"
  79
+  (interactive)
  80
+
  81
+  (save-excursion
  82
+    (let ((prev-indent 0) (cur-indent 0))
  83
+      (beginning-of-line)
  84
+      (forward-line -1)
  85
+      (setq prev-indent (current-indentation))
  86
+      (forward-line 1)
  87
+      (setq cur-indent (current-indentation))
  88
+
  89
+      (backward-to-indentation 0)
  90
+      (insert-tab))))
76 91
 
77 92
 ;;
78 93
 ;; Define Major Mode
@@ -101,6 +116,13 @@ For detail, see `comment-dwim'."
101 116
   (modify-syntax-entry ?/ "\"" coffee-mode-syntax-table)
102 117
   (modify-syntax-entry ?/ "\"" coffee-mode-syntax-table)
103 118
 
  119
+  ;; indentation
  120
+  (make-local-variable 'indent-line-function)
  121
+  (setq indent-line-function 'coffee-indent-line)
  122
+
  123
+  ;; no tabs
  124
+  (setq indent-tabs-mode nil)
  125
+
104 126
   ;; clear memory
105 127
   (setq coffee-keywords-regexp nil)
106 128
   (setq coffee-types-regexp nil)

0 notes on commit d6b78ed

Please sign in to comment.
Something went wrong with that request. Please try again.