diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-10-30 15:22:36 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-10-30 15:22:36 +0200 |
commit | c23cb2861eab646498d2d7d28a8d46f4de91ebb3 (patch) | |
tree | 9d5187a11c6cf7ebb6095f3e9117886314d45f4d /lisp/emacs-lisp | |
parent | b54be604bf8ad67346a82a0755349ffa8a715a11 (diff) | |
download | emacs-c23cb2861eab646498d2d7d28a8d46f4de91ebb3.tar.gz emacs-c23cb2861eab646498d2d7d28a8d46f4de91ebb3.tar.bz2 emacs-c23cb2861eab646498d2d7d28a8d46f4de91ebb3.zip |
Add new function string-glyph-split
* doc/lispref/strings.texi (Creating Strings): Document it.
* lisp/emacs-lisp/shortdoc.el (string): Mention it.
* lisp/emacs-lisp/subr-x.el (string-glyph-split): New function.
Diffstat (limited to 'lisp/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/shortdoc.el | 2 | ||||
-rw-r--r-- | lisp/emacs-lisp/subr-x.el | 16 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lisp/emacs-lisp/shortdoc.el b/lisp/emacs-lisp/shortdoc.el index 817dfa6b71e..daf362dd88b 100644 --- a/lisp/emacs-lisp/shortdoc.el +++ b/lisp/emacs-lisp/shortdoc.el @@ -159,6 +159,8 @@ There can be any number of :example/:result elements." :eval (split-string-and-unquote "foo \"bar zot\"")) (split-string-shell-command :eval (split-string-shell-command "ls /tmp/'foo bar'")) + (string-glyph-split + :eval (string-glyph-split "Hello, πΌπ»π§πΌβπ€βπ§π»")) (string-lines :eval (string-lines "foo\n\nbar") :eval (string-lines "foo\n\nbar" t)) diff --git a/lisp/emacs-lisp/subr-x.el b/lisp/emacs-lisp/subr-x.el index 9a82fe2449d..e3caf88c2f5 100644 --- a/lisp/emacs-lisp/subr-x.el +++ b/lisp/emacs-lisp/subr-x.el @@ -449,6 +449,22 @@ is inserted before adjusting the number of empty lines." (car (window-text-pixel-size (current-buffer) (point-min) (point))))) +;;;###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." + (let ((result nil) + (start 0) + comp) + (while (< start (length string)) + (if (setq comp (find-composition-internal start nil 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))) + (provide 'subr-x) ;;; subr-x.el ends here |