From e079b4b1e3117e7494b047f28abc364513cea0fc Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Fri, 27 Sep 2019 15:15:30 -0400 Subject: [PATCH] ui/vc-gutter: fix {next,previous}-hunk commands They would sometimes jump to random hunks. --- modules/ui/vc-gutter/config.el | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/modules/ui/vc-gutter/config.el b/modules/ui/vc-gutter/config.el index d65a4b262..0f6ede1f6 100644 --- a/modules/ui/vc-gutter/config.el +++ b/modules/ui/vc-gutter/config.el @@ -77,7 +77,18 @@ is deferred until the file is saved. Respects `git-gutter:disabled-modes'." (ignore (git-gutter))))) ;; update git-gutter when using magit commands (advice-add #'magit-stage-file :after #'+vc-gutter-update-h) - (advice-add #'magit-unstage-file :after #'+vc-gutter-update-h)) + (advice-add #'magit-unstage-file :after #'+vc-gutter-update-h) + + (defadvice! +vc-gutter--fix-linearity-of-hunks-a (diffinfos is-reverse) + "Fixes `git-gutter:next-hunk' and `git-gutter:previous-hunk' sometimes + jumping to random hunks." + :override #'git-gutter:search-near-diff-index + (cl-position-if (let ((lineno (line-number-at-pos))) + (lambda (line) + (funcall (if is-reverse #'> #'<) lineno line))) + diffinfos + :key #'git-gutter-hunk-start-line + :from-end is-reverse))) ;; subtle diff indicators in the fringe