   (set (make-local-variable 'merlin-enclosing-types) nil)
   (set (make-local-variable 'merlin-enclosing-offset) nil)
   (set (make-local-variable 'merlin-last-point-type) nil)
+  (set (make-local-variable 'merlin-counter) 0)
   (add-to-list 'after-change-functions 'merlin-edit)
   (merlin-reload-project-file)
   (if (and (> merlin-idle-delay 0.) (not merlin-idle-timer))

  (concat "merlin-" (merlin-get-buffer-instance-name))
  )


(defun merlin-filter (process output)
  "The filter on merlin's output."
  (setq merlin-buffer (concat merlin-buffer output))
  (let ((a (ignore-errors (json-read-from-string merlin-buffer))))
  (if a
      (progn
	(if merlin-debug (merlin-debug (format "Received:\n%s\n----\n" merlin-buffer)))
	(setq merlin-result a)
	(setq merlin-ready t)))))

(defun merlin-wait-for-answer ()
  "Waits for merlin to answer."
  (with-current-buffer (merlin-get-process-buffer-name)
    (let ((times 0))
      (while
          (and (< times 20)
               (or
                (not (accept-process-output (merlin-get-process) 0.1 nil nil))
                (not merlin-ready)))
        (setq times (+ times 1)))
      (setq merlin-buffer nil)
      (setq merlin-ready nil))))

(defun merlin-start-process (flags &optional users)
  "Start the merlin process for the current buffer. FLAGS are a list of strings

          (message "%s" (cdr (assoc 'message err)))))
    (next-error)))

(defun merlin-remove-error-overlay ()
  "Remove the error overlay."
  (delete-overlay merlin-error-overlay))

