Function: majutsu-diff--offset-in-buffer
majutsu-diff--offset-in-buffer is a natively compiled function defined
in majutsu-diff.el.
Signature
(majutsu-diff--offset-in-buffer LINE)
Documentation
Return LINE offset after applying diff hunks in current buffer.
Assumes current buffer contains a unified diff.
Source Code
;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-diff.el
;;; Line Offset Calculation
(defun majutsu-diff--offset-in-buffer (line)
"Return LINE offset after applying diff hunks in current buffer.
Assumes current buffer contains a unified diff."
(let ((offset 0))
(goto-char (point-min))
(catch 'found
(while (re-search-forward
"^@@ -\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? \\+\\([0-9]+\\)\\(?:,\\([0-9]+\\)\\)? @@.*\\n"
nil t)
(let* ((from-beg (string-to-number (match-string 1)))
(from-len (if (match-string 2)
(string-to-number (match-string 2))
1))
(to-len (if (match-string 4)
(string-to-number (match-string 4))
1)))
(if (<= from-beg line)
(if (<= (+ from-beg from-len) line)
(setq offset (+ offset (- to-len from-len)))
(let ((rest (- line from-beg)))
(while (> rest 0)
(pcase (char-after)
(?\s (setq rest (1- rest)))
(?- (setq offset (1- offset))
(setq rest (1- rest)))
(?+ (setq offset (1+ offset))))
(forward-line 1))))
(throw 'found nil)))))
(+ line offset)))