          (merlin-get-process-variable 'merlin-local-process)))
   (merlin-process-add-user)
 
-  (when (featurep 'auto-complete)
-    (auto-complete-mode)
+  (when (and (fboundp 'auto-complete-mode)
+             merlin-use-auto-complete-mode)
+    (auto-complete-mode) 
     (add-to-list 'ac-sources 'merlin-ac-source))
+  (add-hook 'completion-at-point-functions
+            #'merlin-completion-at-point nil 'local)
   (set (make-local-variable 'merlin-lock-point) (point-min))
   (set (make-local-variable 'merlin-buffer) nil)
   (set (make-local-variable 'merlin-result) nil)

              (merlin-display-errors-in-margin errors)))
	  nil)
      (progn
	(message "ok")
	t))))
 


	(merlin-extract-complete (merlin-compute-prefix ident) 
			   (elt (merlin-get-completion ident) 1)))
  )
(defun merlin-get-completion-data (ident)
  "Return the completion data for IDENT, that is a list of pairs (COMPLETION . TYPE)"
  (let* ((prefix (merlin-compute-prefix ident))
         (data (elt (merlin-get-completion ident) 1)))
    (mapcar (lambda (c)
            (cons
             (concat prefix (cdr (assoc 'name c)))
             (if (member (cdr (assoc 'kind c)) '("Module" "module"))
                 ": <module>"
               (replace-regexp-in-string "^[^:]+: " ": " (cdr (assoc 'desc c))))))
            data)))
                 
;; Vars from auto-complete
(defvar ac-point)
(defvar ac-prefix)
