     (set (make-local-variable 'merlin-idle-point) nil)
     (set (make-local-variable 'merlin-completion-point) nil)
     (set (make-local-variable 'merlin-ready) nil)
+    (set (make-local-variable 'merlin-pending-errors) nil)
+    (set (make-local-variable 'merlin-pending-errors-overlay) nil)
     (set (make-local-variable 'merlin-overlay) nil)
     (set (make-local-variable 'merlin-prefix) nil)
     (set (make-local-variable 'merlin-error-prefix) nil)

(defvar merlin-continuous-feed nil
  "If set to t, each time you hit RET, the line is fed to merlin")

(defvar merlin-completion-point nil
  "Stores the point of last completion (beginning of the prefix)")
(defvar merlin-idle-point nil

  (overlay-put merlin-error-overlay 'face 'next-error)
  (run-at-time "1 sec" nil 'merlin-remove-error-overlay)
  )
;; (defun merlin-handle-errors (errors)
;;   "Goes to the location of the first error and adds an overlay"
;;   (let ((message (cdr (assoc 'message errors)))
;; 	(beg (cdr (assoc 'start errors)))
;; 	(end (cdr (assoc 'end errors)))
;; 	(type (cdr (assoc 'type errors))))
;;     (goto-char (merlin-make-point beg))
;;     ;; make the idle thread shut up
;;     (setq merlin-idle-point (point))
;;     (merlin-error-highlight (merlin-make-point beg)
;; 		      (merlin-make-point end))
;;     (message "%s: %s" type message)
;; ))

(defun merlin-delete-error-overlays ()
  "Removes error overlays"
  (mapc '(lambda (over) (delete-overlay over)) merlin-pending-errors-overlay)
  (setq merlin-pending-errors-overlay nil))

(defun merlin-handle-errors (errors)
;  (setq merlin-error-overlay (make-overlay start end))
;  (overlay-put merlin-error-overlay 'face 'next-error)
  (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))))))
                     (overlay-put overlay 'face 'next-error)
                     overlay)) errors))
  (message "(pending error, use C-c C-x to jump)"))

(defun merlin-view-errors ()
  "View the errors of the data that have been fed to merlin"
  (let ((output (merlin-send-command "errors" nil)))
    (if (> (length (elt output 1)) 0)
	(progn
	  (merlin-handle-errors (elt output 1))
	  nil)
      (progn
	(message "ok")
