 (defun merlin-error-next ()
   "Jump to next error."
   (interactive)
+  (if (= merlin--dirty-point (point-max))
+      (when (merlin--process-idle)
+        (merlin--error-check-async))
+    (merlin--error-check nil))
   (let ((err (merlin--error-next-cycle)))
-    (unless err
-      (merlin--acquire-buffer)
-      ;; (prin1 "ERROR CHECK")
-      (merlin--error-check nil)
-      (setq err (merlin--error-next-cycle)))
     (unless (or err merlin-erroneous-buffer) (message "No errors"))
-    (when (and err (tq-queue-empty
-                     (buffer-local-value 'merlin-process-queue (merlin-process-buffer))))
-      (merlin--error-check-async))
     (when err
       (goto-char (car err))
       (message "%s" (cdr (assoc 'message (cdr err))))

(defun merlin-transform-display-errors (errors)
  "Populate the error list with ERRORS, transformed into an emacs-friendly
form. Do display of error list."
  (let* ((err-point
          (lambda (err)
            (let ((bounds (merlin-make-bounds err)))
              (when merlin-error-on-single-line
                (setq bounds (cons (car bounds)
                                   (min (cdr bounds)
                                        (save-excursion
                                          (goto-char (car bounds))
                                          (line-end-position))))))
              (when (= (car bounds) (cdr bounds))
                (setq bounds (if (> (car bounds) (point-min))
                               (cons (1- (car bounds)) (cdr bounds))
                               (cons (car bounds) (1+ (cdr bounds))))))
              (setq bounds (cons (copy-marker (car bounds))
                                 (copy-marker (cdr bounds))))
              (acons 'bounds bounds err))))
         (errors (mapcar err-point errors)))
    (dolist (err errors)
      (let* ((bounds (cdr (assoc 'bounds err)))
             (overlay (make-overlay (car bounds) (cdr bounds))))
        (overlay-put overlay 'merlin-kind 'error)
        (overlay-put overlay 'merlin-pending-error err)
        (push #'merlin--kill-error-if-edited
              (overlay-get overlay 'modification-hooks))
        (when merlin-error-in-fringe
          (if (merlin--error-warning-p (cdr (assoc 'message err)))
              (merlin-add-display-properties overlay
                                             'question-mark
                                             "?"
                                             'merlin-compilation-warning-face)
            (merlin-add-display-properties overlay
                                           'exclamation-mark
                                           "!"
                                           'merlin-compilation-error-face)))
        overlay))))

(defun merlin--error-check-async ()
  (merlin/sync-to-end)
  (merlin-send-command-async 'errors
    (lambda (errors)
      (merlin-error-reset)
      (let ((no-loc (remove-if (lambda (e) (assoc 'start e)) errors)))

(defun merlin--idle-timer ()
  (unless merlin--idle-timer
    (setq merlin--idle-timer
          (run-with-idle-timer 0.5 t 'merlin--idle-action))))

;;;;;;;;;;;;;;;;;;;;;;;;
;; COMPLETION HELPERS ;;
