 
 (defvar merlin-result nil
   "Temporary variables to store command results.")
-
-(defvar merlin-buffer nil "Buffer for merlin input.")
-
-(defvar merlin-ready nil "If non-nil, the reception is done.")
+(make-variable-buffer-local 'merlin-result)
+
+(defvar merlin-buffer nil
+  "Buffer for merlin input.")
+(make-variable-buffer-local 'merlin-buffer)
+
+(defvar merlin-ready nil
+  "If non-nil, the reception is done.")
+(make-variable-buffer-local 'merlin-ready)
 
 ;; Overlays
 (defvar merlin-lock-zone-highlight-overlay nil
   "Overlay used for the lock zone highlighting.")
+(make-variable-buffer-local 'merlin-lock-zone-highlight-overlay)
 (defvar merlin-lock-zone-margin-overlay nil
   "Overlay used for the margin indicator of the lock zone.")
+(make-variable-buffer-local 'merlin-lock-zone-margin-overlay)
 
 ;; Errors related variables
 (defvar merlin-pending-errors nil
   "Pending errors.")
+(make-variable-buffer-local 'merlin-pending-errors)
 (defvar merlin-lock-point 0
   "Position up to which merlin knows about.")
 (defvar merlin-pending-errors-overlays nil
   "Overlays for the pending errors.")
-(defvar merlin-highlight-overlay nil "Merlin overlay used for highlights.")
+(make-variable-buffer-local 'merlin-pending-errors-overlays)
+(defvar merlin-highlight-overlay nil
+  "Merlin overlay used for highlights.")
 
 ;; Completion related variables
 (defvar merlin-completion-point nil
   "Stores the point of last completion (beginning of the prefix).")
+(make-variable-buffer-local 'merlin-completion-point)
 
 ; Vars from auto-complete
 (defvar ac-point)

;; Type related variables
(defvar merlin-enclosing-types nil
  "List containing the enclosing type.")
(defvar merlin-enclosing-offset nil
  "Current offset in `merlin-enclosing-types'.")

;; Locate
(defvar merlin-position-stack nil)

;; Misc
(defvar merlin-project-file nil "The .merlin file for current buffer.")


;;;;;;;;;;;

  "Set up a buffer for use with merlin."
  (interactive)
  (set (make-local-variable 'merlin-lock-point) (point-min))
  ; if there is not yet a buffer for the current buffer, create one
  (when (not (merlin-process-started-p))
    (merlin-start-process merlin-current-flags))
