       0
 
     (if (equal first "def")
-	(if (string-match "\\<def\\>" line)
-	    (match-beginning 0)
-	  (if (string-match "\\<passive\\>" line)
-	      (+ (match-beginning 0) encore-tab-width)
-	    (if (string-match "\\<class\\>" line)
-		(+ (match-beginning 0) encore-tab-width))))
+        (if (string-match "\\<def\\>" line)
+            (match-beginning 0)
+          (if (string-match "\\<passive\\>" line)
+              (+ (match-beginning 0) encore-tab-width)
+            (if (string-match "\\<class\\>" line)
+                (+ (match-beginning 0) encore-tab-width))))
 
       (if (string-match "\\<passive\\> .*" line)
-	  (+ (match-beginning 0) encore-tab-width)
-
-	(if (string-match "\\<class\\> .*" line)
-	    (+ (match-beginning 0) encore-tab-width)
-
-	  (if (string-match "\\<if\\>.*\\<then\\>.*\\<else\\>" line)
-	      (match-beginning 0)
-	    (if (string-match "\\<if\\>.*\\<then\\>" line)
-		(if (equal first "else")
-		    (match-beginning 0)
-		  (+ (match-beginning 0) encore-tab-width))
-	      (if (string-match "\\<then\\>" line)
-		  (if (equal first "else")
-		      (match-beginning 0)
-		    (+ (match-beginning 0) encore-tab-width))
-		(if (string-match "\\<if\\>.*" line)
-		    (if (or (equal first "then") (equal first "else"))
-			(match-beginning 0)
-		      (let ((indent (string-match "[^ \t]" line (+ (match-beginning 0) 2)))) (if indent indent (+ (match-beginning 0) encore-tab-width))))
-		  (if (string-match "\\<else\\>.*" line)
-		      (+ (match-beginning 0) encore-tab-width)
-
-		    (if (string-match "\\<while\\>" line)
-			(+ (match-beginning 0) encore-tab-width)
-
-		      (if (string-match "\\<let\\>.*\\<in\\>$" line)
-			  (+ (match-beginning 0) encore-tab-width)
-
-			(if (string-match "\\<embed\\>.*\\<end\\>" line)
-			    (match-beginning 0)
-			  (if (string-match "\\<embed\\>" line)
-			      (if (equal first "end")
-				  (match-beginning 0)
-				(+ (match-beginning 0) encore-tab-width))
-
-			    (if (string-match "\\<let\\>\\W*\\(\\w+\\)" line)
-				(if (equal "in" first)
-				    (match-beginning 0)
-				  (match-beginning 1))
-			      (if (string-match "\\<let\\>" line)
-				  (if (equal "in" first)
-				      (match-beginning 0)
-				    (+ (match-beginning 0) encore-tab-width))
-				(if (string-match "\\<in\\>[ \t]*$" line)
-				    (+ (match-beginning 0) encore-tab-width)
-
-				  (if (string-match "\\<def\\>" line)
-				      (+ (match-beginning 0) encore-tab-width)
-
-				    (if (string-match "\\W*\\([^;]*\\);" line)
-					(match-beginning 1)
-				      (if (bobp)
-					  0))))))))))))))))))))
+          (+ (match-beginning 0) encore-tab-width)
+
+        (if (string-match "\\<class\\> .*" line)
+            (+ (match-beginning 0) encore-tab-width)
+
+          (if (string-match "\\<if\\>.*\\<then\\>.*\\<else\\>" line)
+              (match-beginning 0)
+            (if (string-match "\\<if\\>.*\\<then\\>" line)
+                (if (equal first "else")
+                    (match-beginning 0)
+                  (+ (match-beginning 0) encore-tab-width))
+              (if (string-match "\\<then\\>" line)
+                  (if (equal first "else")
+                      (match-beginning 0)
+                    (+ (match-beginning 0) encore-tab-width))
+                (if (string-match "\\<if\\>.*" line)
+                    (if (or (equal first "then") (equal first "else"))
+                        (match-beginning 0)
+                      (let ((indent (string-match "[^ \t]" line (+ (match-beginning 0) 2)))) (if indent indent (+ (match-beginning 0) encore-tab-width))))
+                  (if (string-match "\\<else\\>.*" line)
+                      (+ (match-beginning 0) encore-tab-width)
+
+                    (if (string-match "\\<while\\>" line)
+                        (+ (match-beginning 0) encore-tab-width)
+
+                      (if (string-match "\\<let\\>.*\\<in\\>$" line)
+                          (+ (match-beginning 0) encore-tab-width)
+
+                        (if (string-match "\\<embed\\>.*\\<end\\>" line)
+                            (match-beginning 0)
+                          (if (string-match "\\<embed\\>" line)
+                              (if (equal first "end")
+                                  (match-beginning 0)
+                                (+ (match-beginning 0) encore-tab-width))
+
+                            (if (string-match "\\<let\\>\\W*\\(\\w+\\)" line)
+                                (if (equal "in" first)
+                                    (match-beginning 0)
+                                  (match-beginning 1))
+                              (if (string-match "\\<let\\>" line)
+                                  (if (equal "in" first)
+                                      (match-beginning 0)
+                                    (+ (match-beginning 0) encore-tab-width))
+                                (if (string-match "\\<in\\>[ \t]*$" line)
+                                    (+ (match-beginning 0) encore-tab-width)
+
+                                  (if (string-match "\\<def\\>" line)
+                                      (+ (match-beginning 0) encore-tab-width)
+
+                                    (if (string-match "\\W*\\([^;]*\\);" line)
+                                        (match-beginning 1)
+                                      (if (bobp)
+                                          0))))))))))))))))))))
 
 (setq encore-checked-line nil)
 (make-local-variable 'encore-checked-line)

;(dtrt-indent-mode 1)

(add-hook 'encore-mode-hook
	  (lambda ()
	    (setq imenu-generic-expression (encore-imenu-configure))))

;; compilation-mode
(add-hook 'encore-mode-hook
	  (lambda ()
            (set (make-local-variable 'compile-command)
                 (concat "encorec " (buffer-name)))))


(defun first-word ()
  ""
  (let* ((current-line (current-line))
         (word-start (string-match "[^ \t]" current-line))
         (word-end (string-match "[^a-zA-Z]" current-line word-start)))
    (substring-no-properties current-line word-start word-end)))

(defun classify-indent (line first)
