Function: majutsu-conflict-parse-buffer

majutsu-conflict-parse-buffer is a natively compiled function defined in majutsu-conflict.el.

Signature

(majutsu-conflict-parse-buffer)

Documentation

Parse all conflicts in current buffer.

Returns list of majutsu-conflict structs.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-conflict.el
;;; Main Parser

(defun majutsu-conflict-parse-buffer ()
  "Parse all conflicts in current buffer.
Returns list of `majutsu-conflict' structs."
  (save-excursion
    (goto-char (point-min))
    (let (conflicts)
      (while (re-search-forward majutsu-conflict-begin-re nil t)
        (let* ((begin (match-beginning 0))
               (marker-len (length (match-string 1)))
               (end-re (format "^>\\{%d,\\}\\(?: .*\\)?$" marker-len)))
          ;; Find matching end marker
          (when (re-search-forward end-re nil t)
            (let* ((match-end (match-end 0))
                   (marker-has-eol (and (< match-end (point-max))
                                        (eq (char-after match-end) ?\n)))
                   (end (if marker-has-eol
                            (1+ match-end)
                          match-end))
                   (style (majutsu-conflict--detect-style begin marker-len))
                   (parsed (if (eq style 'git)
                               (majutsu-conflict--parse-git-hunk begin end marker-len)
                             (majutsu-conflict--parse-jj-hunk begin end marker-len))))
              (when (and parsed (not marker-has-eol))
                ;; jj compensates missing trailing newlines by omitting EOL on the
                ;; end marker; strip one synthetic trailing EOL from each term.
                (setq parsed (majutsu-conflict--drop-synthetic-ending-eol parsed)))
              (when parsed
                (push (majutsu-conflict--create
                       :begin-pos begin
                       :end-pos end
                       :marker-len marker-len
                       :style (car parsed)
                       :removes (cadr parsed)
                       :adds (caddr parsed)
                       :base (cadddr parsed))
                      conflicts))))))
      (nreverse conflicts))))