branch: externals/diff-hl
commit 685ea2d50607a9902f1c6c141ee6268d759b9b25
Merge: 6b22baee87 dee6a72412
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>

    Merge branch 'specialized-run-delayed'
---
 diff-hl.el | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/diff-hl.el b/diff-hl.el
index 72a325f368..e61c40f483 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -740,9 +740,31 @@ Return a list of line overlays used."
 (defun diff-hl--resolve (value-or-buffer cb)
   (if (listp value-or-buffer)
       (funcall cb value-or-buffer)
-    (with-current-buffer value-or-buffer
-      (vc-run-delayed
-        (funcall cb (diff-hl-changes-from-buffer (current-buffer)))))))
+    (diff-hl--when-done value-or-buffer
+                        #'diff-hl-changes-from-buffer
+                        cb)))
+
+(defun diff-hl--when-done (buffer get-value callback &optional proc)
+  (let ((proc (or proc (get-buffer-process buffer))))
+    (cond
+     ;; If there's no background process, just execute the code.
+     ((or (null proc) (eq (process-status proc) 'exit))
+      ;; Make sure we've read the process's output before going further.
+      (when proc (accept-process-output proc))
+      (when (get-buffer buffer)
+        (with-current-buffer buffer
+          (funcall callback (funcall get-value buffer)))))
+     ;; If process was deleted, we ignore it.
+     ((eq (process-status proc) 'signal))
+     ;; If a process is running, set the sentinel.
+     ((eq (process-status proc) 'run)
+      (set-process-sentinel
+       proc
+       (lambda (proc _status)
+         ;; Delegate to the parent cond for decision logic.
+         (diff-hl--when-done buffer get-value callback proc))))
+     ;; Maybe we should ignore all other states as well.
+     (t (error "Unexpected process state")))))
 
 (defun diff-hl--autohide-margin ()
   (let ((width-var (intern (format "%s-margin-width" diff-hl-side))))

Reply via email to