Function: markdown-ts--fontify-hard-line-break
markdown-ts--fontify-hard-line-break is a byte-compiled function
defined in markdown-ts-mode.el.gz.
Signature
(markdown-ts--fontify-hard-line-break NODE OVERRIDE START END &rest _)
Documentation
Fontify hard line break NODE; show a Unicode symbol when markup is hidden.
A backslash break gets markdown-ts-hard-line-break-backslash (or its
-hidden variant when markup is hidden); a trailing-spaces break gets
markdown-ts-hard-line-break-space (or -hidden). When hidden, a
backslash break is replaced by a single markdown-ts-hard-line-break
glyph; a trailing-spaces break replaces each space with the glyph, so the run
of pilcrows fills the line up to the newline.
If markdown-ts-hard-line-break-backslash or
markdown-ts-hard-line-break-space are the symbol hide, hide the
markup entirely.
OVERRIDE, START, and END are passed through to
treesit-fontify-with-override.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--fontify-hard-line-break (node override start end &rest _)
"Fontify hard line break NODE; show a Unicode symbol when markup is hidden.
A backslash break gets `markdown-ts-hard-line-break-backslash' (or its
`-hidden' variant when markup is hidden); a trailing-spaces break gets
`markdown-ts-hard-line-break-space' (or `-hidden'). When hidden, a
backslash break is replaced by a single `markdown-ts-hard-line-break'
glyph; a trailing-spaces break replaces each space with the glyph, so the run
of pilcrows fills the line up to the newline.
If `markdown-ts-hard-line-break-backslash' or
`markdown-ts-hard-line-break-space' are the symbol `hide', hide the
markup entirely.
OVERRIDE, START, and END are passed through to
`treesit-fontify-with-override'."
(let* ((node-start (treesit-node-start node))
(node-end (treesit-node-end node))
(text (treesit-node-text node t))
(backslash (and (> (length text) 0) (eq (aref text 0) ?\\)))
;; Determine the actual range to fontify and replace. The
;; hard_line_break node may not cover the full run of trailing
;; spaces, so walk back from end-of-line ourselves for the
;; spaces variant.
(region (if backslash
(cons node-start
(if (and (> node-end node-start)
(eq (char-before node-end) ?\n))
(1- node-end)
node-end))
(save-excursion
(goto-char node-start)
(let ((eol (line-end-position)))
(cons (save-excursion
(goto-char eol)
(skip-chars-backward
" " (line-beginning-position))
(point))
eol)))))
(region-start (car region))
(region-end (cdr region))
(face (cond
((and backslash markdown-ts-hide-markup)
'markdown-ts-hard-line-break-backslash-hidden)
(backslash 'markdown-ts-hard-line-break-backslash)
(markdown-ts-hide-markup
'markdown-ts-hard-line-break-space-hidden)
(t 'markdown-ts-hard-line-break-space))))
(treesit-fontify-with-override region-start region-end face
override start end)
;; Always start by clearing any stale `display' property. We never
;; span the trailing newline with `display' (it confuses
;; redisplay's cursor placement), and we only paint a single
;; combined string onto the first character of the run, leaving
;; the rest of the markup alone.
(remove-text-properties region-start region-end '(display nil))
(when markdown-ts-hide-markup
(let* ((spec (if backslash
(markdown-ts--resolve-display-value
markdown-ts-hard-line-break-backslash)
markdown-ts-hard-line-break-space))
(str (cond
((null spec) nil)
((characterp spec) (char-to-string spec))
((stringp spec) spec)
((functionp spec)
(funcall spec (- region-end region-start))))))
(if (eq spec 'hide)
(put-text-property region-start region-end
'invisible 'markdown-ts--markup)
(when (and (stringp str)
(> (length str) 0)
(char-displayable-p (aref str 0)))
(put-text-property region-start (1+ region-start)
'display str)
;; For the trailing-spaces variant, hide the remaining
;; spaces in the run so the line doesn't end with leftover
;; whitespace after the substituted glyph. Each position
;; gets its own empty-string `display' so cursor placement
;; stays unambiguous.
(unless backslash
(let ((i (1+ region-start)))
(while (< i region-end)
(put-text-property i (1+ i) 'display "")
(setq i (1+ i)))))))))))