@@ -449,8 +449,11 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
449449 (run-hook-with-args-until-success 'diff-hl-async-inhibit-functions
450450 default-directory))))
451451
452+ (defvar diff-hl-timer nil )
453+
452454(defun diff-hl-update ()
453455 " Updates the diff-hl overlay."
456+ (setq diff-hl-timer nil )
454457 (if (diff-hl--use-async-p)
455458 ; ; TODO: debounce if a thread is already running.
456459 (let ((buf (current-buffer ))
@@ -527,14 +530,14 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
527530 (dolist (win (get-buffer-window-list ))
528531 (set-window-buffer win (current-buffer ))))))
529532
530- (defvar-local diff-hl--modified-tick nil )
531-
532533(put 'diff-hl--modified-tick 'permanent-local t )
533534
534535(defun diff-hl-update-once ()
535- (unless (equal diff-hl--modified-tick (buffer-chars-modified-tick ))
536- (diff-hl-update)
537- (setq diff-hl--modified-tick (buffer-chars-modified-tick ))))
536+ ; ; Ensure that the update happens once, after all major mode changes.
537+ ; ; That will keep the the local value of <side>-margin-width, if any.
538+ (unless diff-hl-timer
539+ (setq diff-hl-timer
540+ (run-with-idle-timer 0 nil #'diff-hl-update ))))
538541
539542(defun diff-hl-add-highlighting (type shape )
540543 (let ((o (make-overlay (point ) (point ))))
@@ -564,8 +567,6 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
564567 (diff-hl-remove-overlays (overlay-start ov) (overlay-end ov))
565568 (delete-overlay ov))))
566569
567- (defvar diff-hl-timer nil )
568-
569570(defun diff-hl-edit (_beg _end _len )
570571 " DTRT when we've `undo' -ne the buffer into unmodified state."
571572 (when undo-in-progress
@@ -580,10 +581,6 @@ It can be a relative expression as well, such as \"HEAD^\" with Git, or
580581 (unless (buffer-modified-p )
581582 (diff-hl-update)))))
582583
583- (defun diff-hl-after-revert ()
584- (when (bound-and-true-p revert-buffer-preserve-modes)
585- (diff-hl-update)))
586-
587584(defun diff-hl-diff-goto-hunk-1 (historic )
588585 (defvar vc-sentinel-movepoint )
589586 (vc-buffer-sync )
@@ -1025,7 +1022,7 @@ The value of this variable is a mode line template as in
10251022 'diff-hl-update-once t t )
10261023 ; ; Never removed because it acts globally.
10271024 (add-hook 'vc-checkin-hook 'diff-hl-after-checkin )
1028- (add-hook 'after-revert-hook 'diff-hl-after-revert nil t )
1025+ (add-hook 'after-revert-hook 'diff-hl-update-once nil t )
10291026 ; ; Magit does call `auto-revert-handler' , but it usually
10301027 ; ; doesn't do much, because `buffer-stale--default-function'
10311028 ; ; doesn't care about changed VC state.
@@ -1038,7 +1035,7 @@ The value of this variable is a mode line template as in
10381035 (remove-hook 'after-save-hook 'diff-hl-update t )
10391036 (remove-hook 'after-change-functions 'diff-hl-edit t )
10401037 (remove-hook 'find-file-hook 'diff-hl-update-once t )
1041- (remove-hook 'after-revert-hook 'diff-hl-after-revert t )
1038+ (remove-hook 'after-revert-hook 'diff-hl-update-once t )
10421039 (remove-hook 'magit-revert-buffer-hook 'diff-hl-update t )
10431040 (remove-hook 'magit-not-reverted-hook 'diff-hl-update t )
10441041 (remove-hook 'text-scale-mode-hook 'diff-hl-maybe-redefine-bitmaps t )
0 commit comments