 (defvar merlin-idle-timer nil
   "The timer used to print the type of the expression under point.")
 
+(defvar merlin-use-auto-complete-mode nil
+  "If non nil, use `auto-complete-mode' in any buffer")
 
 
 

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



(when (featurep 'auto-complete)
  (ac-define-source "merlin" merlin-ac-source))

;; Usual completion
(defun merlin-completion-at-point ()
  (save-excursion
    (merlin-check-synchronize))
  (save-excursion
    (skip-syntax-backward "w_.")
    (let ((start (point)))
      (skip-syntax-forward "w_.")
      (list start (point)
            (apply-partially #'merlin--completion-table start)))))

(defvar merlin--completion-cache-state nil)
(defvar merlin--completion-annotation-table nil
  "Hold a table mapping completion candidates to their types")
(make-variable-buffer-local 'merlin--completion-cache-state)
(make-variable-buffer-local 'merlin--completion-annotation-table)


(defun merlin-completion-annotate (s)
  (cdr (assoc s merlin--completion-annotation-table)))
(defun merlin--completion-table (start string pred action)
  (message "We are called with action: %s" action)
  (if (eq 'metadata action)
      (when merlin-completion-types
        '(metadata (annotation-function . merlin-completion-annotate)))
    (unless (and merlin--completion-annotation-table
                 (eq (car merlin--completion-cache-state) start)
                 (string-prefix-p (cdr merlin--completion-cache-state)
                                  string completion-ignore-case)
                 (string-equal (merlin-compute-prefix string)
                               (merlin-compute-prefix (cdr merlin--completion-cache-state))))
      (message "Working..")
      (save-excursion
        (goto-char start)
        (setq merlin--completion-annotation-table 
              (merlin-get-completion-data string)))
      (setq merlin--completion-cache-state (cons start string)))
    (complete-with-action action merlin--completion-annotation-table string pred)))


;; Get the type of an element

