   "Initialize merlin."
   (add-hook 'kill-buffer-hook 'merlin-kill-buffer-hook))
                                       
-(defun merlin-kill-all-buffers ()
+(defun merlin-kill-all-processes ()
   "Kill all the remaining buffers containing merlin processes"
   (interactive)
-  (merlin-kill-process))
+  (mapc '(lambda (p)
+           (with-current-buffer (process-buffer p)
+             (merlin-kill-process)))))
 
 (provide 'merlin)


(defun merlin-wait-for-answer ()
  "Waits for merlin to answer"
  (let ((times 0))
    (while
        (and (< times 20)
             (or
              (not (accept-process-output (merlin-get-process) 0.1 nil nil))
              (not merlin-ready)))
      (setq times (+ times 1)))
    (setq merlin-buffer nil)
    (setq merlin-ready nil)))

(defun merlin-start-process ()
  "Start the merlin process for the current buffer"

    (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)
      (merlin-wait-for-answer)
      merlin-result
      )
))


