branch: externals/diff-hl commit a682de60187763128d2d0a85f1d168d89877691f Author: Dmitry Gutov <dgu...@yandex.ru> Commit: Dmitry Gutov <dgu...@yandex.ru>
If there is no hunk at or above point, search below Resolves #169 --- diff-hl-show-hunk.el | 7 +++---- diff-hl.el | 12 ++++++++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/diff-hl-show-hunk.el b/diff-hl-show-hunk.el index f8998b7..10473da 100644 --- a/diff-hl-show-hunk.el +++ b/diff-hl-show-hunk.el @@ -345,11 +345,10 @@ The backend is determined by `diff-hl-show-hunk-function'." (save-excursion (diff-hl-show-hunk-hide)) - (cond - ((not (vc-backend buffer-file-name)) + (unless (vc-backend buffer-file-name) (user-error "The buffer is not under version control")) - ((not (diff-hl-hunk-overlay-at (point))) - (diff-hl-previous-hunk))) + + (diff-hl-find-current-hunk) (setq diff-hl-show-hunk--original-overlay nil) diff --git a/diff-hl.el b/diff-hl.el index 1c1bf51..5481caa 100644 --- a/diff-hl.el +++ b/diff-hl.el @@ -540,8 +540,7 @@ in the source file, or the last line of the hunk above it." (let ((diff-buffer (generate-new-buffer-name "*diff-hl*")) (buffer (current-buffer)) (line (save-excursion - (unless (diff-hl-hunk-overlay-at (point)) - (diff-hl-previous-hunk)) + (diff-hl-find-current-hunk) (line-number-at-pos))) (fileset (vc-deduce-fileset))) (unwind-protect @@ -625,6 +624,15 @@ in the source file, or the last line of the hunk above it." (interactive) (diff-hl-next-hunk t)) +(defun diff-hl-find-current-hunk () + (let (o) + (cond + ((diff-hl-hunk-overlay-at (point))) + ((setq o (diff-hl-search-next-hunk t)) + (goto-char (overlay-start o))) + (t + (diff-hl-next-hunk))))) + (defun diff-hl-mark-hunk () (interactive) (let ((hunk (diff-hl-hunk-overlay-at (point))))