Function: ghostel--kitty-apply-row-slice
ghostel--kitty-apply-row-slice is a natively compiled function defined
in ghostel-kitty.el.
Signature
(ghostel--kitty-apply-row-slice ROW CW CH IMG VP-COL-CLAMPED VISIBLE-COLS SLICE-X SLICE-W)
Documentation
Apply one row of the sliced image at point.
ROW is the slice index (0-based) into the image's grid of cells. CW / CH are the cell pixel dimensions. IMG is the Emacs image object. VP-COL-CLAMPED is the placement's column origin clamped to >= 0; VISIBLE-COLS is how many columns of that row are on-screen; SLICE-X is the slice's x-origin in image pixels (non-zero only when the placement is partially scrolled off the left); SLICE-W is the fallback slice width when the buffer line is shorter than the placement.
Decides between the text-property and overlay paths based on whether the buffer line is long enough to hold the placement's column range.
Source Code
;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel-kitty.el
(defun ghostel--kitty-apply-row-slice (row cw ch img
vp-col-clamped visible-cols
slice-x slice-w)
"Apply one row of the sliced image at point.
ROW is the slice index (0-based) into the image's grid of cells.
CW / CH are the cell pixel dimensions. IMG is the Emacs image object.
VP-COL-CLAMPED is the placement's column origin clamped to >= 0;
VISIBLE-COLS is how many columns of that row are on-screen; SLICE-X is
the slice's x-origin in image pixels (non-zero only when the placement
is partially scrolled off the left); SLICE-W is the fallback slice
width when the buffer line is shorter than the placement.
Decides between the text-property and overlay paths based on whether
the buffer line is long enough to hold the placement's column range."
(let* ((line-pos (point))
(line-end-pos (line-end-position))
(start (min (+ line-pos vp-col-clamped) line-end-pos))
(end (min (+ line-pos vp-col-clamped visible-cols) line-end-pos))
;; The slice's pixel width must match the cell-range width Emacs
;; gives us; otherwise the display engine renders the slice at
;; its declared size and either overlaps subsequent cells or
;; truncates. This bites when `vp-col + g-cols' exceeds the
;; terminal width (line-end-pos clamps `end` shorter than the
;; slice the placement asked for) and shows up as a ghosted
;; copy of the image bleeding to the right.
(range-cols (- end start))
(clamped-slice-w (* range-cols cw))
(slice (list 'slice slice-x (* row ch)
(if (> range-cols 0) clamped-slice-w slice-w)
ch))
(spec (list slice img)))
(cond
;; Range is empty (line shorter than vp-col) — use an overlay so we
;; don't eat the newline.
((<= end start)
(let ((ov (make-overlay start start)))
(overlay-put ov 'before-string (propertize " " 'display spec))
(overlay-put ov 'ghostel-kitty t)))
;; Line has enough text — use text property.
(t
(add-text-properties start end
(list 'display spec 'ghostel-kitty t))))
(when (< line-end-pos (point-max))
(add-text-properties line-end-pos (1+ line-end-pos)
(list 'line-height ch 'ghostel-kitty t)))
(setq ghostel--kitty-active t)))