unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Maragakis via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 52067@debbugs.gnu.org
Subject: bug#52067: possible fix for string-glyph-split halts on certain emoji strings.
Date: Tue, 23 Nov 2021 23:58:17 -0500	[thread overview]
Message-ID: <33CD01AE-0B26-42EA-83F0-A1FFEBE6E11B@icloud.com> (raw)
In-Reply-To: <EACE3D30-82CE-4AD2-AC10-FA274DC6C4BD@icloud.com>

The following code fixes this bug, though there might be better ways to fix it for someone who understands the domain.
I don't know much about glyph/grapheme representations, so although this code passes my limited tests, it may break other things.

(defun pm-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)
	(laststart -1) ;; the last start of a character with the composition property
        comp)
    (while (< start (length string))
      (setq comp (find-composition-internal start nil string nil))
      (if (and comp (/= laststart (car comp)))  ;; check that we don't return to same start
          (progn
            (push (substring string (car comp) (cadr comp)) result)
	    (setq laststart start)  ;; keep the start of the last successful search.
            (setq start (cadr comp)))
        (push (substring string start (1+ start)) result)
        (setq start (1+ start))))
    (nreverse result)))


Compare to the original:

(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)))







      parent reply	other threads:[~2021-11-24  4:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-23 23:01 bug#52067: 29.0.50; string-glyph-split halts on certain emoji strings PAVLOS MARAGAKIS via Bug reports for GNU Emacs, the Swiss army knife of text editors
     [not found] ` <handler.52067.B.16377084873203.ack@debbugs.gnu.org>
2021-11-24  3:51   ` bug#52067: Acknowledgement (29.0.50; string-glyph-split halts on certain emoji strings) Paul Maragakis via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-24  7:30     ` bug#52067: 29.0.50; string-glyph-split halts on certain emoji strings Lars Ingebrigtsen
2021-11-24 15:15       ` Paul Maragakis via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-24 16:14         ` Lars Ingebrigtsen
2021-11-24  4:58 ` Paul Maragakis via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33CD01AE-0B26-42EA-83F0-A1FFEBE6E11B@icloud.com \
    --to=bug-gnu-emacs@gnu.org \
    --cc=52067@debbugs.gnu.org \
    --cc=paul.maragakis@icloud.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).