     (if x
 	(buffer-substring-no-properties (car x) (cdr x))
       nil)))
-
+; overlay management
+(defun merlin-create-overlay (var start end face timer)
+  "Creates an overlay in the current buffer starting at `start', ending at `end',
+using `face' and storing it in `var'. If `timer' is non-nil, the overlay is to disappear after `timer' seconds
+`timer' is a string that can be understood by `run-at-time' (eg. \"1 sec\")"
+  (if (symbol-value var) (delete-overlay (symbol-value var)))
+  (set var (make-overlay start end))
+  (overlay-put (symbol-value var) 'face face)
+  (if timer
+      (run-at-time timer nil '(lambda ()
+                                (delete-overlay (symbol-value var))
+                                (set var nil)))))
+      
 ;; PROCESS MANAGEMENT
 (defun merlin-make-buffer-name ()
   "Returns the buffer name associated to the current buffer, for the merlin process"

    (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)

        (let ((start (merlin-make-point (cdr (assoc 'start ret))))
              (end (merlin-make-point (cdr (assoc 'end ret))))
              (type (cdr (assoc 'type ret))))
          (merlin-create-overlay 'merlin-type-overlay start end 'next-error "1 sec")
          type))))
          

