 
 (defun ycmd--on-window-configuration-change ()
   "Function to run by `window-configuration-change-hook'."
-  (when (and ycmd-mode
-             (eq ycmd--last-status-change 'unparsed)
-             (memq 'buffer-focus ycmd-parse-conditions))
-    (ycmd--kill-timer ycmd--on-focus-timer)
-    (let ((on-buffer-focus-fn
-           (apply-partially 'ycmd--on-unparsed-buffer-focus
-                            (current-buffer))))
-      (setq ycmd--on-focus-timer
-            (run-at-time 1.0 nil on-buffer-focus-fn)))))
+  (if (ycmd--deferred-parse?)
+      (ycmd--perform-deferred-parse)
+    (when (and ycmd-mode
+               (pcase ycmd--last-status-change
+                 ((or `unparsed `starting) t))
+               (memq 'buffer-focus ycmd-parse-conditions))
+      (ycmd--kill-timer ycmd--on-focus-timer)
+      (let ((on-buffer-focus-fn
+             (apply-partially 'ycmd--on-unparsed-buffer-focus
+                              (current-buffer))))
+        (setq ycmd--on-focus-timer
+              (run-at-time 1.0 nil on-buffer-focus-fn))))))
 
 (defmacro ycmd--with-all-ycmd-buffers (&rest body)
   "Execute BODY with each `ycmd-mode' enabled buffer."

    (window-configuration-change-hook . ycmd--on-window-configuration-change)
    (kill-buffer-hook                 . ycmd--on-close-buffer)
    (before-revert-hook               . ycmd--teardown)
    (window-configuration-change-hook . ycmd--perform-deferred-parse)
    (post-command-hook                . ycmd--perform-deferred-parse))
  "Hooks which ycmd hooks in.")


      (ycmd-parsing-in-progress-p)
      revert-buffer-in-progress-p))

(defun ycmd--deferred-parse? ()
  "Return non-nil if current buffer has a deferred parse."
  ycmd--deferred-parse)

(defun ycmd--parse-deferred ()
  "Defer parse notification for current buffer."
  (setq ycmd--deferred-parse t))

(defun ycmd--perform-deferred-parse ()
  "Perform the deferred parse."
  (when (ycmd--deferred-parse?)
    (setq ycmd--deferred-parse nil)
    (ycmd--conditional-parse)))

