   "Sets up a buffer for use with merlin"
   (interactive)
   ; if there is not yet a buffer for the current buffer, create one
-  (if (not (merlin-get-process))
-      (merlin-start-process))
+  (if (not (get-buffer (merlin-get-process-buffer-name)))
+      (merlin-start-process)
+    (set (make-local-variable 'merlin-local-process)
+         (merlin-get-process-variable 'merlin-local-process)))
+  (merlin-process-add-user)
+
   (when (featurep 'auto-complete)
     (auto-complete-mode)
     (add-to-list 'ac-sources 'merlin-ac-source))

  (let ((name (buffer-name)))
    (merlin-debug (format "Adding user: %s\n" name))
    (with-current-buffer (merlin-get-process-buffer-name)
      (push 'merlin-process-users name))
    )
)

(defun merlin-is-last-user-p ()
  "Returns whether the current buffer was the current user of its merlin process"
  (let ((name (buffer-name)))
    (with-current-buffer (merlin-get-process-buffer-name)
      (equal merlin-process-last-user name))
)
)
(defun merlin-kill-process ()
  "Kills the merlin process inside the buffer"
  (merlin-debug "Killing process ...")
  (setq merlin-process nil)
  (process-send-eof (merlin-get-process))
  (delete-process (merlin-get-process))
  (kill-buffer (merlin-get-process-buffer-name))
)
(defun merlin-process-remove-user ()
  "Remove the current buffer as an user for the merlin process"
  (let ((name (buffer-name)))
    (merlin-debug (format "Remove user: %s.\n" name))
    (with-current-buffer (merlin-get-process-buffer-name)
      (merlin-debug (format "Remaining: %s.\n" merlin-process-users))
      (setq merlin-process-users (delete name merlin-process-users))
      (if (and (not merlin-process-users)
               merlin-automatically-garbage-processes)
          (merlin-kill-process))
      )
    )
)
(defun merlin-send-command (name args)
  "Send a command to merlin. Returns the result"



; Process / Reception related variables
(defvar merlin-processes nil
  "The global merlin process table. It lists the active instances of merlin")
(defvar merlin-local-process nil
  "The local merlin process (buffer local in every process buffer)"
)
