Function: string-glyph-split

string-glyph-split is an autoloaded and byte-compiled function defined in subr-x.el.gz.

Signature

(string-glyph-split STRING)

Documentation

Split STRING into a list of strings representing separate glyphs.

This takes into account combining characters and grapheme clusters: if compositions are enabled, each sequence of characters composed on display into a single grapheme cluster is treated as a single indivisible unit. Caveat: for this function to recognize characters compositions, the automatic compositions should be enabled (see auto-composition-mode(var)/auto-composition-mode(fun)) and the current buffer must be displayed in some window.

Other relevant functions are documented in the string group.

View in manual

Probably introduced at or before Emacs version 29.1.

Shortdoc

;; string
(string-glyph-split "Hello, πŸ‘ΌπŸ»πŸ§‘πŸΌβ€πŸ€β€πŸ§‘πŸ»")
    => ("H" "e" "l" "l" "o" "," " " "πŸ‘Ό" "🏻" "πŸ§‘" "🏼" "‍" "🀝" "‍" "πŸ§‘" "🏻")

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/subr-x.el.gz
;;;###autoload
(defun string-glyph-split (string)
  "Split STRING into a list of strings representing separate glyphs.
This takes into account combining characters and grapheme clusters:
if compositions are enabled, each sequence of characters composed
on display into a single grapheme cluster is treated as a single
indivisible unit.
Caveat: for this function to recognize characters compositions, the
automatic compositions should be enabled (see `auto-composition-mode')
and the current buffer must be displayed in some window."
  (declare (side-effect-free t))
  (let ((result nil)
        (start 0)
        comp)
    (while (< start (length string))
      (if (setq comp (find-composition-internal
                      start
                      ;; Don't search backward in the string for the
                      ;; start of the composition.
                      (min (length string) (1+ start))
                      string nil))
          (progn
            (push (substring string (car comp) (cadr comp)) result)
            (setq start (cadr comp)))
        (push (substring string start (1+ start)) result)
        (setq start (1+ start))))
    (nreverse result)))