   (concat "merlin-" (merlin-get-buffer-instance-name))
   )
 
-
+(defvar merlin--counter 0)
 (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)))))
+  (setq merlin--counter 0)
+  (if (> (length merlin-buffer) 1000)
+      (message "Loading answer %dk" (/ (length merlin-buffer) 1000)))
+  (when (or
+         (equal (elt merlin-buffer (1- (length merlin-buffer))) ?\n)
+         (< (length merlin-buffer) 1000))
+    (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)))
+            (if (> (length merlin-buffer) 1000)
+                (message "Loading answer %dk...done" 
+                         (/ (length merlin-buffer) 1000)))
+            (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)
+          (and (< merlin--counter 20)
                (or
                 (not (accept-process-output (merlin-get-process) 0.1 nil nil))
                 (not merlin-ready)))
-        (setq times (+ times 1)))
+        (setq merlin--counter (+ merlin--counter 1)))
       (setq merlin-buffer nil)
-      (setq merlin-ready nil))))
+      (setq merlin-ready nil)
+      (not (equal merlin--counter 20))))
 
 (defun merlin-start-process (flags &optional users)
   "Start the merlin process for the current buffer. FLAGS are a list of strings

    (if merlin-debug (merlin-debug (format "Sending:\n%s\n---\n" string)))
    (with-current-buffer (merlin-get-process-buffer-name)
      (setq merlin-process-last-user name)
      (merlin-wait-for-answer)
      merlin-result
      )
))


(defun merlin-is-long (s)

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

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

