unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#32460: 27.0.50; diff-mode sometimes doesn't refine hunks
@ 2018-08-16 20:48 Juri Linkov
  2019-03-07 19:26 ` Charles A. Roelli
  0 siblings, 1 reply; 3+ messages in thread
From: Juri Linkov @ 2018-08-16 20:48 UTC (permalink / raw)
  To: 32460

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

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):


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: diff-refine.1.patch --]
[-- Type: text/x-diff, Size: 1253 bytes --]

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))
                     max)))
       (while (< beg max)
         (let ((end
@@ -2092,7 +2105,10 @@ diff--font-lock-refined
               (overlay-put ol 'modification-hooks
                            '(diff--font-lock-refine--refresh))))
           (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))

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-03-08  3:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-16 20:48 bug#32460: 27.0.50; diff-mode sometimes doesn't refine hunks Juri Linkov
2019-03-07 19:26 ` Charles A. Roelli
2019-03-08  3:07   ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).