 (defvar merlin-position-stack nil)
 
 ;; Misc
-(defvar merlin-last-project-failures nil
+(defvar merlin--project-cache nil "Cache for merlin--project-get")
+(make-variable-buffer-local 'merlin--project-cache)
+(defvar merlin--project-failures nil
   "When loading .merlin, list of errors reported. Only update error messages if
   error list changes")
-(make-variable-buffer-local 'merlin-last-project-failures)
+(make-variable-buffer-local 'merlin--project-failures)
 
 ;;;;;;;;;;;
 ;; UTILS ;;

    (progn
      (merlin--acquire-buffer)
      (let* ((messages nil)
             (project (merlin--project-get)))
        (when merlin-report-dot-merlin-in-lighter
          (cond ((cdr project) (add-to-list 'messages "errors in .merlin"))
                ((not (car project)) (add-to-list 'messages "no .merlin"))))

loading"
  (let* ((r (merlin-send-command '(project get)))
         (failed (cdr (assoc 'failures r)))
         (result (cdr (assoc 'result r)))
         (ret (cons result failed)))
    (setq merlin--project-cache (cons (float-time) ret))
    ret))

(defun merlin--project-get-cached ()
  "Like `merlin--project-get' but use a cache to prevent to limit number of
calls (lighter can be updated at a high frequency)"
  (if (and merlin--project-cache
           (< (abs (- (float-time) (car merlin--project-cache)) 4.)))
      (cdr merlin--project-cache)
    (merlin--project-get)))

(defun merlin-goto-project-file ()
  "Goto the merlin file corresponding to the current file."
