 (defun merlin-check-for-errors (view-errors-p)
   "Check for errors. Return t if there were not any or nil if there were.
 Moreover if `view-errors-p' is not nil, it will display them in the margin."
-  (let ((output (merlin-send-command "errors" nil)))
-    (if (> (length (elt output 1)) 0)
+  (let ((raw-errors (merlin-send-command "errors" nil)))
+    (if (> (length raw-errors) 0)
 	(progn
           (when view-errors-p
             (let ((errors (delete-if (lambda (e) (not (assoc 'start e)))
-                                     (append (elt output 1) nil))))
+                                     (append raw-errors nil))))
               (if (not merlin-report-warnings)
                   (delete-if (lambda (e) (merlin-warning-p (cdr (assoc 'message e)))) errors))
               (merlin-display-errors-in-margin errors)))

  (process-send-eof (merlin-get-process))
  (ignore-errors (delete-process (merlin-get-process)))
  (kill-buffer (merlin-get-process-buffer-name))
)
(defun merlin-send-command (name args)
  "Send a command to merlin. Return the result."
  (let ((string
	 (concat 
	  (json-encode (if args (append (list name) args) (list name)))
	  "\n"))
        (name (buffer-name)))
    (process-send-string (merlin-get-process) string)
    (setq merlin-result nil)
    (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)
      (when (merlin-wait-for-answer)
          merlin-result))))


(defun merlin-is-long (s)
  "Return true if its parameter is long, ie. contains a new line."
  (string-match "sig" s))
;; SPECIAL CASE OF COMMANDS
(defun merlin-get-return-field (data)
  "Return the actual data of a response or nil if there was an error."
  (if (string-equal (elt data 0) "return")
      (elt data 1)
    nil))
		    
(defun merlin-rewind ()
  "Rewind the knowledge of merlin of the current buffer to zero."
  (interactive)

  "Load the .merlin file corresponding to the current file."
  (interactive)
  (merlin-rewind)
  (let ((r (merlin-send-command "project" (list "find" (buffer-file-name)))))
    (if (and r (listp r))
        (setq merlin--project-file (car r)))))

