branch: elpa/magit commit cca2bfeed361fe2e4221dd82df9c24347a7b4c90 Author: Jonas Bernoulli <jo...@bernoul.li> Commit: Jonas Bernoulli <jo...@bernoul.li>
magit-diff--locate-file-position: Add shorthands for PARENTS --- lisp/magit-diff.el | 12 +++++++++--- lisp/magit-status.el | 6 ++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lisp/magit-diff.el b/lisp/magit-diff.el index ea395677825..3ba22b3ad91 100644 --- a/lisp/magit-diff.el +++ b/lisp/magit-diff.el @@ -1430,9 +1430,15 @@ for a revision." (defun magit-diff--locate-file-position (file line column &optional parent) (and-let* - ((diff (cl-find-if (##and (cl-typep % 'magit-file-section) - (equal (oref % value) file)) - (oref (or parent magit-root-section) children))) + ((parent (pcase parent + ('unstaged (magit-get-section '((unstaged) (status)))) + ('staged (magit-get-section '((staged) (status)))) + ('nil (and (cl-typep (car (oref magit-root-section children)) + 'magit-file-section) + magit-root-section)) + (_ parent))) + (diff (cl-find-if (##equal (oref % value) file) + (oref parent children))) (hunks (oref diff children))) (let (hunk pos found) (while (and (setq hunk (pop hunks)) diff --git a/lisp/magit-status.el b/lisp/magit-status.el index 19e5a698ec6..e301002245c 100644 --- a/lisp/magit-status.el +++ b/lisp/magit-status.el @@ -471,11 +471,9 @@ Type \\[magit-commit] to create a commit. (defun magit-status--goto-file-position (file line column) (pcase-let ((`(,upos ,_uhunk) - (magit-diff--locate-file-position - file line column (magit-get-section '((unstaged) (status))))) + (magit-diff--locate-file-position file line column 'unstaged)) (`(,spos ,shunk) - (magit-diff--locate-file-position - file line column (magit-get-section '((staged) (status)))))) + (magit-diff--locate-file-position file line column 'staged))) (cond (shunk (goto-char spos)) (upos (goto-char upos)) (spos (goto-char spos)))