Function: compose-gstring-for-terminal
compose-gstring-for-terminal is a byte-compiled function defined in
composite.el.gz.
Signature
(compose-gstring-for-terminal GSTRING DIRECTION)
Documentation
Compose glyph-string GSTRING for terminal display.
Non-spacing characters are composed with the preceding base character. If the preceding character is not a base character, each non-spacing character is composed as a spacing character by prepending a space before it.
Source Code
;; Defined in /usr/src/emacs/lisp/composite.el.gz
(defun compose-gstring-for-terminal (gstring _direction)
"Compose glyph-string GSTRING for terminal display.
Non-spacing characters are composed with the preceding base
character. If the preceding character is not a base character,
each non-spacing character is composed as a spacing character by
prepending a space before it."
(let ((nglyphs (lgstring-glyph-len gstring))
(i 0)
(coding (lgstring-font gstring))
glyph)
(while (and (< i nglyphs)
(setq glyph (lgstring-glyph gstring i)))
(if (not (char-charset (lglyph-char glyph) coding))
(progn
;; As the terminal doesn't support this glyph, return a
;; gstring in which each glyph is its own grapheme-cluster
;; of width 1..
(setq i 0)
(while (and (< i nglyphs)
(setq glyph (lgstring-glyph gstring i)))
(if (< (lglyph-width glyph) 1)
(lglyph-set-width glyph 1))
(lglyph-set-from-to glyph i i)
(setq i (1+ i))))
(if (= (lglyph-width glyph) 0)
(if (eq (get-char-code-property (lglyph-char glyph)
'general-category)
'Cf)
(progn
;; Compose Cf (format) control characters by
;; replacing with a space.
(lglyph-set-char glyph 32)
(lglyph-set-width glyph 1)
(setq i (1+ i)))
;; Compose by prepending a space.
(setq gstring (lgstring-insert-glyph gstring i
(lglyph-copy glyph))
nglyphs (lgstring-glyph-len gstring))
(setq glyph (lgstring-glyph gstring i))
(lglyph-set-char glyph 32)
(lglyph-set-width glyph 1)
(setq i (+ i 2)))
(let ((from (lglyph-from glyph))
(to (lglyph-to glyph))
(j (1+ i)))
(while (and (< j nglyphs)
(setq glyph (lgstring-glyph gstring j))
(char-charset (lglyph-char glyph) coding)
(= (lglyph-width glyph) 0))
(setq to (lglyph-to glyph)
j (1+ j)))
(while (< i j)
(setq glyph (lgstring-glyph gstring i))
(lglyph-set-from-to glyph from to)
(setq i (1+ i)))))))
gstring))