                 (message "%s: %s" candidate (popup-item-summary item))))
             merlin-ac-cache))))
 
+(defun merlin-auto-complete-candidates ()
+  "Return the candidates for auto-completion with
+  auto-complete. If the cache is wrong then recompute it."
+  (if (not (equal (merlin-completion-prefix ac-prefix)
+                  merlin-ac-prefix))
+      (merlin-ac-source-refresh-cache))
+  merlin-ac-cache)
+      
 (defvar merlin-ac-source
   (if merlin-ac-prefix-size
   `((init . merlin-ac-source-init)
-    (candidates . (lambda () merlin-ac-cache))
+    (candidates . merlin-auto-complete-candidates)
     (action . merlin-ac-fetch-type)
     (prefix . ,merlin-ac-prefix-size))
   '((init . merlin-ac-source-init)
-    (candidates . (lambda () merlin-ac-cache))
+    (candidates . merlin-auto-complete-candidates)
     (action . merlin-ac-fetch-type)
     (prefix . merlin-ac-prefix))))
 
 (when (featurep 'auto-complete)
-  (ac-define-source "merlin" merlin-ac-source))
+  (eval '(ac-define-source "merlin" merlin-ac-source)))
 
 ;;;;;;;;;;;;;;;;;;;;;;;
 ;; EXPRESSION TYPING ;;

                        "\n"))
       (buffer (current-buffer))
       (name (buffer-name)))
    (if (not (equal (process-status merlin-process) 'run))
        (progn
          (error "Merlin process not running (try restarting with %s)"
                 (substitute-command-keys "\\[merlin-restart-process]"))
          nil)
      (progn
        (if merlin-debug (merlin-debug (format ">%s" string)))
        (setq merlin-process-last-user name)
        (tq-enqueue merlin-process-queue string "\n"

    (goto-char (point-min)))))

(defun merlin-type-display (bounds type &optional quiet)
  "Display the type TYPE of the expression occuring at BOUNDS.
If QUIET is non nil, then an overlay and the merlin types can be used."
  (if (not type)
      (if (not quiet)
