@@ -408,42 +408,6 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
408408(declare-function vc-hg-command " vc-hg" )
409409(declare-function vc-bzr-command " vc-bzr" )
410410
411- (cl-defstruct (diff-hl--promise
412- (:constructor diff-hl--make-promise (&optional result)))
413- " Object containing the result of computation."
414- (result 'none )
415- callbacks)
416-
417- (defun diff-hl--promise-resolve (promise value )
418- (setf (diff-hl--promise-result promise) value)
419- (dolist (cb (diff-hl--promise-callbacks promise))
420- (funcall cb value)))
421-
422- (defun diff-hl--promise-then (promise function )
423- (if (eq (diff-hl--promise-result promise) 'none )
424- (push
425- function
426- (diff-hl--promise-callbacks promise))
427- (funcall function (diff-hl--promise-result promise))))
428-
429- (defun diff-hl--promise-map (&rest args )
430- (let* ((function (car (last args)))
431- (promises (butlast args 1 ))
432- (count (cl-count-if #'diff-hl--promise-p promises))
433- (res (diff-hl--make-promise)))
434- (when (zerop count)
435- (diff-hl--promise-resolve res (apply function promises)))
436- (dolist (p promises)
437- (when (diff-hl--promise-p p)
438- (diff-hl--promise-then
439- p
440- (lambda (v )
441- (setcar (member p promises) v)
442- (cl-decf count)
443- (when (zerop count)
444- (diff-hl--promise-resolve res (apply function promises)))))))
445- res))
446-
447411(defun diff-hl-changes-buffer (file backend &optional new-rev bufname )
448412 (diff-hl-with-diff-switches
449413 (diff-hl-diff-against-reference file backend (or bufname " *diff-hl* " ) new-rev)))
@@ -503,31 +467,26 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
503467 ((and
504468 (not diff-hl-highlight-reference-function)
505469 (diff-hl-modified-p state))
506- `((:working . ,(diff-hl--promise-from-buffer
507- (diff-hl-changes-buffer file backend)))))
470+ `((:working . ,(diff-hl-changes-buffer file backend))))
508471 ((or
509472 diff-hl-reference-revision
510473 (diff-hl-modified-p state))
511474 (let* ((ref-changes
512475 (and (or diff-hl-reference-revision
513476 hide-staged)
514- (diff-hl--promise-from-buffer
515- (diff-hl-changes-buffer file backend
516- (if hide-staged
517- 'git-index
518- (diff-hl-head-revision backend))
519- " *diff-hl-reference* " ))))
477+ (diff-hl-changes-buffer file backend
478+ (if hide-staged
479+ 'git-index
480+ (diff-hl-head-revision backend))
481+ " *diff-hl-reference* " )))
520482 (diff-hl-reference-revision nil )
521- (work-changes (diff-hl--promise-from-buffer
522- (diff-hl-changes-buffer file backend))))
483+ (work-changes (diff-hl-changes-buffer file backend)))
523484 `((:reference . ,ref-changes )
524485 (:working . ,work-changes ))))
525486 ((eq state 'added )
526- `((:working . ,(diff-hl--make-promise
527- `((1 ,(line-number-at-pos (point-max )) 0 insert))))))
487+ `((:working . ,`((1 ,(line-number-at-pos (point-max )) 0 insert)))))
528488 ((eq state 'removed )
529- `((:working . ,(diff-hl--make-promise
530- `((1 0 ,(line-number-at-pos (point-max )) delete)))))))))))
489+ `((:working . ,`((1 0 ,(line-number-at-pos (point-max )) delete))))))))))
531490
532491(defvar diff-hl-head-revision-alist '((Git . " HEAD" ) (Bzr . " last:1" ) (Hg . " ." )))
533492
@@ -595,31 +554,6 @@ contents as they are (or would be) after applying the changes in NEW."
595554 (setq old (cdr old)))
596555 ref))
597556
598- (defun diff-hl--process-to-promise (buf fun )
599- (let* ((promise (diff-hl--make-promise))
600- (proc (get-buffer-process buf))
601- (resolve-fun
602- (lambda (_proc _status )
603- (diff-hl--promise-resolve
604- promise
605- (funcall fun buf)))))
606- (unless (eq diff-hl-update-async 'no-thread )
607- (diff-hl-process-wait buf))
608- (cond
609- ((or (null proc) (eq (process-status proc) 'exit ))
610- (when proc (accept-process-output proc))
611- (funcall resolve-fun proc nil ))
612- ((eq (process-status proc) 'run )
613- (add-function :after (process-sentinel proc)
614- resolve-fun))
615- (t (error " Unexpected process state " )))
616- promise))
617-
618- (defun diff-hl--promise-from-buffer (buf )
619- (diff-hl--process-to-promise
620- buf
621- #'diff-hl-changes-from-buffer ))
622-
623557(defun diff-hl-process-wait (buf )
624558 (let ((proc (get-buffer-process buf)))
625559 (while (process-live-p proc)
@@ -690,7 +624,7 @@ contents as they are (or would be) after applying the changes in NEW."
690624
691625(defun diff-hl--update-safe ()
692626 " Updates the diff-hl overlay. It handles and logs when an error is signaled."
693- (condition-case err
627+ (condition-case-unless-debug err
694628 (diff-hl--update)
695629 (error
696630 (message " An error occurred in diff-hl--update: %S " err)
@@ -743,24 +677,33 @@ Return a list of line overlays used."
743677 (nreverse ovls)))
744678
745679(defun diff-hl--update ()
746- (let* ((cc (diff-hl-changes))
747- (refs-promise (assoc-default :reference cc))
748- (changes-promise (assoc-default :working cc))
749- reuse)
750- (diff-hl--promise-map
751- refs-promise changes-promise
752- (lambda (ref-changes changes )
753- (diff-hl-remove-overlays)
754- (let ((diff-hl-highlight-function
755- diff-hl-highlight-reference-function)
756- (diff-hl-fringe-face-function
757- diff-hl-fringe-reference-face-function))
758- (setq reuse (diff-hl--update-overlays
759- (diff-hl-adjust-changes ref-changes changes)
760- nil )))
761- (diff-hl--update-overlays changes reuse)
762- (when (not (or changes ref-changes))
763- (diff-hl--autohide-margin))))))
680+ (let* ((orig (current-buffer ))
681+ (cc (diff-hl-changes)))
682+ (diff-hl--resolve
683+ (assoc-default :working cc)
684+ (lambda (changes )
685+ (diff-hl--resolve
686+ (assoc-default :reference cc)
687+ (lambda (ref-changes )
688+ (let ((ref-changes (diff-hl-adjust-changes ref-changes changes))
689+ reuse)
690+ (with-current-buffer orig
691+ (diff-hl-remove-overlays)
692+ (let ((diff-hl-highlight-function
693+ diff-hl-highlight-reference-function)
694+ (diff-hl-fringe-face-function
695+ diff-hl-fringe-reference-face-function))
696+ (setq reuse (diff-hl--update-overlays ref-changes nil )))
697+ (diff-hl--update-overlays changes reuse)
698+ (when (not (or changes ref-changes))
699+ (diff-hl--autohide-margin))))))))))
700+
701+ (defun diff-hl--resolve (value-or-buffer cb )
702+ (if (listp value-or-buffer)
703+ (funcall cb value-or-buffer)
704+ (with-current-buffer value-or-buffer
705+ (vc-run-delayed
706+ (funcall cb (diff-hl-changes-from-buffer (current-buffer )))))))
764707
765708(defun diff-hl--autohide-margin ()
766709 (let ((width-var (intern (format " %s -margin-width" diff-hl-side))))
0 commit comments