Function: ghostel--wrap-joined-region
ghostel--wrap-joined-region is a natively compiled function defined in
ghostel-links.el.
Signature
(ghostel--wrap-joined-region BEGIN END LIMIT)
Documentation
Return (STRING . CHUNKS) for BEGIN..END with soft-wrap newlines removed.
STRING is the region's text as the terminal program wrote it, so a value split across rows matches as one token. CHUNKS maps it back: a vector of (STRING-OFFSET . BUFFER-POS) pairs, one per row, ascending.
LIMIT bounds how many rows may be joined into one line, which keeps a megabyte-long line of output from becoming one unbroken token for the regexps to chew through. The count is per logical line: a hard newline in the region ends one line and starts the next from zero.
Source Code
;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel-links.el
(defun ghostel--wrap-joined-region (begin end limit)
"Return (STRING . CHUNKS) for BEGIN..END with soft-wrap newlines removed.
STRING is the region's text as the terminal program wrote it, so a
value split across rows matches as one token. CHUNKS maps it back:
a vector of (STRING-OFFSET . BUFFER-POS) pairs, one per row, ascending.
LIMIT bounds how many rows may be joined into one line, which keeps a
megabyte-long line of output from becoming one unbroken token for the
regexps to chew through. The count is per logical line: a hard
newline in the region ends one line and starts the next from zero."
(let ((chunks nil)
(parts nil)
(offset 0)
(rows 0)
(pos begin))
(while (< pos end)
(let* ((wrap (text-property-not-all pos end 'ghostel-wrap nil))
(wrapped (and wrap (eq (char-after wrap) ?\n)))
(join (and wrapped (< rows limit)))
(piece (buffer-substring-no-properties
pos (cond (join wrap)
(wrapped (1+ wrap))
(t end)))))
(push (cons offset pos) chunks)
(push piece parts)
;; A hard newline inside PIECE ended the logical line the count was
;; for; the row being joined now is the first of a new one.
(setq rows (cond ((not join) 0)
((string-search "\n" piece) 1)
(t (1+ rows)))
offset (+ offset (length piece))
pos (if wrapped (1+ wrap) end))))
(cons (string-join (nreverse parts))
(vconcat (nreverse chunks)))))