branch: externals/diff-hl
commit 77ee4ef7e159cf7f15d9bc84f2648edd3f0be3e4
Author: Dmitry Gutov <[email protected]>
Commit: Dmitry Gutov <[email protected]>
diff-hl--when-done: New function
Internal version of vc-run-delayed, to avoid erroring out when the process
is
deleted by the next update in vc-setup-buffer (e.g. due to being slow).
---
diff-hl.el | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)
diff --git a/diff-hl.el b/diff-hl.el
index 097f0db835..c032ef41b9 100644
--- a/diff-hl.el
+++ b/diff-hl.el
@@ -713,9 +713,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)
+ (let ((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))))
+ ;; 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))))