 
 (defun merlin-tell-piece (mode start end)
   "Tell part of the current buffer to merlin using `mode'"
-  (merlin-tell-string mode 
-		      (buffer-substring start end)))
-
-
-(defvar merlin-cache nil "Merlin cache for completion")
-(defvar merlin-prefix nil "Merlin prefix")
-(defvar merlin-name nil "Merlin name")
-(defvar merlin-overlay nil "Merlin overlay used for errors")
-
-(defun merlin-remove-overlay ()
-  (delete-overlay merlin-overlay))
-
-(defun merlin-highlight (msg start end)
+  (merlin-tell-string mode (buffer-substring start end)))
+
+
+;; ERRORS
+(defun merlin-remove-error-overlay ()
+  "Remove the error overlay"
+  (delete-overlay merlin-error-overlay))
+
+(defun merlin-error-highlight (start end)
+  "Add an overlay between `start' and `end' for errors"
   (setq merlin-overlay
 	(make-overlay start end))
   (overlay-put merlin-overlay 'face 'next-error)
   (run-at-time "5 sec" nil 'merlin-remove-overlay)
   )
 (defun merlin-handle-errors (errors)
+  "Goes to the location of the first error and adds an overlay"
   (let ((message (cdr (assoc 'message errors)))
 	(lbeginning (cdr (assoc 'line (cdr (assoc 'start errors)))))
 	(cbeginning (cdr (assoc 'col (cdr (assoc 'start errors)))))

;; Mode for Merlin



(defvar merlin-command "ocamlmerlin"
  "Merlin's command")

(defvar merlin-process nil
  "The process associated to the current buffer")
(defvar merlin-continuation nil
  "The callback to be called with the result of the next command")
(defvar merlin-point nil
  "Stores the point of last completion")

(defvar merlin-debug t)
(defvar merlin-type-buffer (get-buffer-create "*merlin types*"))

(defun merlin-make-buffer-name ()
  "The buffer name of the process for merlin"
  (concat "*"
	  (buffer-file-name nil)
	  " merlin *"))

(defun merlin-make-process-name ()
  "The process name of a buffer"
  (concat "merlin-" (buffer-file-name nil)))

(defun merlin-get-process ()
  merlin-process)
;  (get-process (merlin-make-process-name)))

(defun merlin-filter (process output)
  "The filter on merlin's output"

	  (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)
	      (forward-line))))
	(switch-to-buffer buf))))
    
;; Mode definition
(defun merlin-setup ()
