[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#32460: 27.0.50; diff-mode sometimes doesn't refine hunks

From: Juri Linkov
Subject: bug#32460: 27.0.50; diff-mode sometimes doesn't refine hunks
Date: Thu, 16 Aug 2018 23:48:05 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu)

It's difficult to debug a sporadic problem when automatic diff
refinement doesn't display refined overlays on some diff hunks
occasionally.  Looking at the code, it seems there is a possible
race condition when diff--font-lock-refined calls diff-hunk-next
that sets a timer that later might remove and try to re-add again
overlays already added by the direct call of diff--refine-hunk
from diff--font-lock-refined.  Also diff-hunk-next prevents
multiple consequent calls from refining a set of hunks
by checking diff--auto-refine-data.

To avoid such double refinement, this patch let-binds
diff-auto-refine-mode to nil before calling diff-hunk-next
for non-interactive navigation (it calls diff--refine-hunk
explicitly below):

diff --git a/lisp/vc/diff-mode.el b/lisp/vc/diff-mode.el
index b91a2ba45a..175687f184 100644
--- a/lisp/vc/diff-mode.el
+++ b/lisp/vc/diff-mode.el
@@ -2077,7 +2088,9 @@ diff--font-lock-refined
                   (point) 'diff--font-lock-refined nil max)))
     (let* ((min (point))
            (beg (or (ignore-errors (diff-beginning-of-hunk))
-                    (ignore-errors (diff-hunk-next) (point))
+                    (ignore-errors (let ((diff-auto-refine-mode nil))
+                                     (diff-hunk-next))
+                                   (point))
       (while (< beg max)
         (let ((end
@@ -2092,7 +2105,10 @@ diff--font-lock-refined
               (overlay-put ol 'modification-hooks
           (goto-char (max beg end))
-          (setq beg (or (ignore-errors (diff-hunk-next) (point)) max)))))))
+          (setq beg (or (ignore-errors (let ((diff-auto-refine-mode nil))
+                                         (diff-hunk-next))
+                                       (point))
+                        max)))))))
 (defun diff--font-lock-refine--refresh (ol _after _beg _end &optional _len)
   (delete-overlay ol))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]