]> code.delx.au - gnu-emacs-elpa/blobdiff - diff-hl.el
diff-hl-revert-hunk: Recenter the window on the hunk, if possible
[gnu-emacs-elpa] / diff-hl.el
index fcda8fe8c81bb321de31abc309d959ba278a0666..84725a0c358c53cabbf9a44d38f35fe63d3b11a7 100644 (file)
@@ -3,7 +3,7 @@
 ;; Author:   Dmitry Gutov <dgutov@yandex.ru>\r
 ;; URL:      https://github.com/dgutov/diff-hl\r
 ;; Keywords: vc, diff\r
-;; Version:  1.2\r
+;; Version:  1.3\r
 ;; Package-Requires: ((smartrep "0.0.3"))\r
 \r
 ;; This file is not part of GNU Emacs.\r
@@ -248,19 +248,25 @@ in the source file, or the last line of the hunk above it."
         (progn\r
           (vc-diff-internal nil fileset nil nil nil diff-buffer)\r
           (vc-exec-after\r
-           `(progn\r
+           `(let (beg-line end-line)\r
               (when (eobp)\r
                 (with-current-buffer ,buffer (diff-hl-remove-overlays))\r
                 (error "Buffer is up-to-date"))\r
               (diff-hl-diff-skip-to ,line)\r
               (save-excursion\r
                 (while (looking-at "[-+]") (forward-line 1))\r
+                (setq end-line (line-number-at-pos (point)))\r
                 (unless (eobp) (diff-split-hunk)))\r
               (unless (looking-at "[-+]") (forward-line -1))\r
               (while (looking-at "[-+]") (forward-line -1))\r
+              (setq beg-line (line-number-at-pos (point)))\r
               (unless (looking-at "@")\r
                 (forward-line 1)\r
                 (diff-split-hunk))\r
+              (let ((wbh (window-body-height)))\r
+                (if (>= wbh (- end-line beg-line))\r
+                    (recenter (/ (+ wbh (- beg-line end-line) 2) 2))\r
+                  (recenter 1)))\r
               (unless (yes-or-no-p (format "Revert current hunk in %s?"\r
                                            ,(caadr fileset)))\r
                 (error "Revert canceled"))\r