branch: elpa/magit
commit fb768870f0506fac4ba4c59fb0f97a8e4632e6f6
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    magit-diff-visit--position: New function
---
 lisp/magit-diff.el | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el
index a2b0a189e52..d82b9d167b3 100644
--- a/lisp/magit-diff.el
+++ b/lisp/magit-diff.el
@@ -1747,12 +1747,9 @@ the Magit-Status buffer for DIRECTORY."
 (defun magit-diff-visit-file--noselect (&optional goto-file)
   (pcase-let*
       ((file (magit-diff--file-at-point t t))
-       (hunk (magit-diff-visit--hunk))
        (goto-from
         (and (not goto-file)
              (magit-diff-on-removed-line-p)))
-       (line (and hunk (magit-diff-hunk-line   hunk goto-from)))
-       (col  (and hunk (magit-diff-hunk-column hunk goto-from)))
        (spec (magit-diff--dwim))
        (rev  (if goto-from
                  (magit-diff-visit--range-from spec)
@@ -1767,20 +1764,25 @@ the Magit-Status buffer for DIRECTORY."
                       ((stringp rev) rev)
                       ("HEAD"))
                 file)))
-    (if line
-        (with-current-buffer buffer
-          (cond ((eq rev 'staged)
-                 (setq line (magit-diff-visit--offset file nil line)))
-                ((and goto-file
-                      (stringp rev))
-                 (setq line (magit-diff-visit--offset file rev line))))
-          (list buffer (save-restriction
-                         (widen)
-                         (goto-char (point-min))
-                         (forward-line (1- line))
-                         (move-to-column col)
-                         (point))))
-      (list buffer nil))))
+    (list buffer
+          (magit-diff-visit--position buffer rev file goto-from goto-file))))
+
+(defun magit-diff-visit--position (buffer rev file goto-from goto-file)
+  (and-let* ((hunk (magit-diff-visit--hunk)))
+    (let* ((line   (magit-diff-hunk-line   hunk goto-from))
+           (column (magit-diff-hunk-column hunk goto-from)))
+      (with-current-buffer buffer
+        (cond ((eq rev 'staged)
+               (setq line (magit-diff-visit--offset file nil line)))
+              ((and goto-file
+                    (stringp rev))
+               (setq line (magit-diff-visit--offset file rev line))))
+        (save-restriction
+          (widen)
+          (goto-char (point-min))
+          (forward-line (1- line))
+          (move-to-column column)
+          (point))))))
 
 (defun magit-diff--file-at-point (&optional expand assert)
   ;; This is a variation of `magit-file-at-point'.

Reply via email to