From dbf2285da694cb11b50281f99ef48dce26af8cdc Mon Sep 17 00:00:00 2001 From: "Nicholas B. Hubbard" Date: Thu, 20 Nov 2025 11:25:59 -0500 Subject: [PATCH 1/2] Add option to auto recenter after diff-hl-{next,previous}-hunk --- diff-hl.el | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/diff-hl.el b/diff-hl.el index 72a325f3..6b2fa145 100644 --- a/diff-hl.el +++ b/diff-hl.el @@ -142,6 +142,11 @@ enclosed in a `progn' form. ELSE-FORMS may be empty." :group 'diff-hl :type 'boolean) +(defcustom diff-hl-next-previous-hunk-auto-recenter nil + "Non-nil to `recenter' after `diff-hl-next-hunk' and `diff-hl-previous-hunk'." + :group 'diff-hl + :type 'boolean) + (defcustom diff-hl-fallback-to-margin t "Non-nil to use margin instead of fringe on non-graphic displays. @@ -1081,9 +1086,11 @@ its end position." "Go to the beginning of the next hunk in the current buffer." (interactive) (let ((overlay (diff-hl-search-next-hunk backward))) - (if overlay - (goto-char (overlay-start overlay)) - (user-error "No further hunks found")))) + (unless overlay + (user-error "No further hunks found")) + (goto-char (overlay-start overlay)) + (when diff-hl-next-previous-hunk-auto-recenter + (recenter)))) (defun diff-hl-previous-hunk () "Go to the beginning of the previous hunk in the current buffer." From 3ffc55cf550320d9a48dec477d901f79c095af1a Mon Sep 17 00:00:00 2001 From: "Nicholas B. Hubbard" Date: Fri, 21 Nov 2025 09:12:22 -0500 Subject: [PATCH 2/2] disable auto recentering from diff-hl-find-current-hunk --- diff-hl.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/diff-hl.el b/diff-hl.el index 6b2fa145..6ab472c6 100644 --- a/diff-hl.el +++ b/diff-hl.el @@ -1098,7 +1098,8 @@ its end position." (diff-hl-next-hunk t)) (defun diff-hl-find-current-hunk () - (let (o) + (let ((o) + (diff-hl-next-previous-hunk-auto-recenter nil)) (cond ((diff-hl-hunk-overlay-at (point))) ((setq o (diff-hl-search-next-hunk t))