Function: magit-diff--locate-file-position
magit-diff--locate-file-position is a byte-compiled function defined
in magit-diff.el.
Signature
(magit-diff--locate-file-position FILE LINE COLUMN &optional PARENT)
Source Code
;; Defined in ~/.emacs.d/elpa/magit-20260411.1452/magit-diff.el
(defun magit-diff--locate-file-position (file line column &optional parent)
(and-let*
((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))
(not pos))
(when-let* ((range (oref hunk to-range))
(beg (car range))
(len (cadr range))
(end (+ beg len)))
(cond
((> beg line)
(setq pos (oref diff start)))
((<= beg line end)
(save-excursion
(goto-char (oref hunk content))
(let ((l beg))
(while (or (< l line)
(= (char-after) ?-))
(unless (= (char-after) ?-)
(cl-incf l))
(forward-line)))
(setq found (if (= (char-after) ?+) 'line 'hunk))
(forward-char (1+ column))
(setq pos (point))))
((null hunks)
(setq pos (oref hunk start))))))
(and pos
(list pos (or found file))))))