   (string-match "^Warning" msg))
 
 (defun merlin-display-errors-in-margin (errors)
-  "Given a list of errors, puts annotations in the margin corresponding to them"
+  "Given a list of ERRORS, put annotations in the margin corresponding to them."
   (merlin-delete-error-overlays)
   (setq merlin-pending-errors (append errors nil))
-  (setq merlin-pending-errors-overlay 
-        (mapcar '(lambda (err)
-                   (let ((overlay (make-overlay
-                                   (merlin-make-point (cdr (assoc 'start err)))
-                                   (merlin-make-point (cdr (assoc 'end err))))))
-                     (if (merlin-is-warning (cdr (assoc 'message err)))
-                         (merlin-put-margin-overlay overlay "?" compilation-warning-face)
-                       (merlin-put-margin-overlay overlay "!" compilation-error-face))
-                     overlay)) errors))
+  (setq merlin-pending-errors-overlays 
+        (mapcar (lambda (err)
+                  (let ((overlay (make-overlay
+                                  (merlin-make-point (cdr (assoc 'start err)))
+                                  (merlin-make-point (cdr (assoc 'end err))))))
+                    (if (merlin-warning-p (cdr (assoc 'message err)))
+                        (merlin-put-margin-overlay overlay "?" compilation-warning-face)
+                      (merlin-put-margin-overlay overlay "!" compilation-error-face))
+                     
+                    overlay)) 
+                errors))
   (message "(pending errors, use %s to jump)"
            (substitute-command-keys "\\[merlin-next-error]")))
 

     ((string-equal (elt words 0) "B") (merlin-add-path "build" (elt words 1) dirname))
     ((string-equal (elt words 0) "PKG") (merlin-use (elt words 1))))))
(defun merlin-file-parse (filename)
  "Parses a .merlin. It should exist"
  (message "Parsing .merlin file %s" filename)
  (setq lines nil)
  (setq buf (current-buffer))
  (with-current-buffer (find-file ".merlin")
    (goto-char (point-min))
    (while (not (eq (point) (point-max)))
      (let ((words (split-string (buffer-substring-no-properties (point-at-bol) (point-at-eol)))))
        (merlin-handle-line buf words (file-name-directory filename))
        (forward-line)))))

(defun merlin-parse ()
  "Parses all .merlin file lying beneath the current directory in the file system."
  (setq dir default-directory)
  (let ((buf (current-buffer)))
    (while (not (string-equal dir "/"))
      (when (file-exists-p (concat dir ".merlin") )
        (merlin-file-parse (concat dir ".merlin")))
      (setq dir (file-name-directory (directory-file-name dir))))
    (switch-to-buffer buf)))
    

;; Idle 
(defun merlin-idle-hook ()

  (add-hook 'kill-buffer-hook 'merlin-kill-buffer-hook))
                                      
(defun merlin-kill-all-processes ()
  "Kill all the remaining buffers containing merlin processes."
  (interactive)
  (mapc (lambda (p)
          (with-current-buffer (process-buffer p)
            (merlin-kill-process)))))

(provide 'merlin)
