Function: majutsu-row--parse-entry-record-at-point

majutsu-row--parse-entry-record-at-point is a natively compiled function defined in majutsu-row.el.

Signature

(majutsu-row--parse-entry-record-at-point COMPILED &optional STREAM-START)

Documentation

Parse one row record at point using COMPILED.

When STREAM-START is non-nil, treat it as the current stream origin for prefix calculation while keeping the physical line end as the record boundary. Return (ENTRY . RECORD-END), where RECORD-END is just after the end token.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-row.el
(defun majutsu-row--parse-entry-record-at-point (compiled &optional stream-start)
  "Parse one row record at point using COMPILED.
When STREAM-START is non-nil, treat it as the current stream origin for prefix
calculation while keeping the physical line end as the record boundary.
Return (ENTRY . RECORD-END), where RECORD-END is just after the end token."
  (let* ((entry-beg (or stream-start (line-beginning-position)))
         (bol entry-beg)
         (eol (line-end-position))
         (start-pos (if (majutsu-row--looking-at-token-p
                         majutsu-row-start-token)
                        (point)
                      (majutsu-row-line-token-position
                       majutsu-row-start-token bol eol))))
    (when start-pos
      (let* ((indent (- start-pos bol))
             (heading-prefixes nil)
             (heading-segments nil)
             (record-end nil)
             (done nil)
             (first-line t))
        (save-excursion
          (goto-char start-pos)
          (while (and (not done) (not (eobp)))
            (setq bol (line-beginning-position)
                  eol (line-end-position))
            (let* ((prefix-end (min (+ bol indent) eol))
                   (prefix (buffer-substring bol prefix-end))
                   (content-start (if first-line
                                      (+ start-pos
                                         (length majutsu-row-start-token))
                                    prefix-end)))
              (let ((segment-pos (majutsu-row-line-token-position
                                  majutsu-row-tail-token
                                  bol eol content-start)))
                (if segment-pos
                    (progn
                      ;; A visible template may end with a newline.  jj then
                      ;; puts the trailing protocol on a graph-only carrier
                      ;; line; that carrier is not an empty heading line.
                      (unless (and (not first-line)
                                   (= content-start segment-pos))
                        (push prefix heading-prefixes)
                        (push (buffer-substring content-start segment-pos)
                              heading-segments))
                      (if-let* ((payloads (majutsu-row-parse-trailing-payloads
                                           compiled segment-pos eol)))
                          (setq record-end (plist-get payloads :record-end)
                                done payloads)
                        (setq done :incomplete)))
                  (push prefix heading-prefixes)
                  (push (buffer-substring content-start eol) heading-segments)
                  (forward-line 1)
                  (when (eobp)
                    (setq done :incomplete)))))
            (setq first-line nil)))
        (when (plistp done)
          (let* ((profile (majutsu-row--profile compiled))
                 (entry (list :beg entry-beg
                              :record-end record-end
                              :end record-end
                              :row-profile (plist-get profile :name)
                              :indent indent
                              :columns nil
                              :column-values nil
                              :modules nil
                              :heading-prefixes (nreverse heading-prefixes)
                              :suffix-lines nil
                              :parent nil
                              :depth 0))
                 (heading-payload
                  (majutsu-row-join-lines
                   (nreverse heading-segments))))
            (setq entry (majutsu-row-record-module-fields
                         entry 'heading heading-payload compiled))
            (setq entry (majutsu-row-record-module-fields
                         entry 'tail (plist-get done :tail) compiled))
            (setq entry (majutsu-row-record-module-fields
                         entry 'body (plist-get done :body) compiled))
            (setq entry (majutsu-row-record-module-fields
                         entry 'metadata (plist-get done :metadata) compiled))
            (cons entry record-end)))))))