Function: eca-diff-parse-unified-diff

eca-diff-parse-unified-diff is a natively compiled function defined in eca-diff.el.

Signature

(eca-diff-parse-unified-diff DIFF-TEXT)

Documentation

Parse DIFF-TEXT and return a plist with :original and :new strings.

Only hunks (lines between @@ ... @@) are considered for the content. This mirrors the original parser used by the chat UI.

Source Code

;; Defined in /nix/store/jklqzw6pzz6j4jrbv8wy0iwgi7jlrbld-emacs-packages-deps/share/emacs/site-lisp/elpa/eca-20260928.1827/eca-diff.el
(defun eca-diff-parse-unified-diff (diff-text)
  "Parse DIFF-TEXT and return a plist with :original and :new strings.
Only hunks (lines between @@ ... @@) are considered for the content.
This mirrors the original parser used by the chat UI."
  (let ((orig '()) (new '()) in-hunk)
    (dolist (l (split-string diff-text "\n"))
      (cond
       ((string-match "^@@.*@@$" l) (setq in-hunk t))
       ((and in-hunk (string-prefix-p " " l))
        (push (substring l 1) orig) (push (substring l 1) new))
       ((and in-hunk (string-prefix-p "-" l))
        (push (substring l 1) orig))
       ((and in-hunk (string-prefix-p "+" l))
        (push (substring l 1) new))))
    (list :original (string-join (nreverse orig) "\n")
          :new      (string-join (nreverse new) "\n"))))