[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Converting compositions to strings
From: |
Clément Pit-Claudel |
Subject: |
Re: Converting compositions to strings |
Date: |
Mon, 30 Jan 2017 11:39:09 -0500 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 |
On 2017-01-30 10:18, Eli Zaretskii wrote:
> The information about this can be found in the doc strong of
> compose-region, under COMPONENTS.
Thanks. This covers only "relative" compositions, right? Is there more
information on non-relative compositions somewhere?
>> Is there a recipe that I can use to construct a string
>> representation of a composition? (I realize that many compositions
>> can't adequately be represented as plain strings; I'm only
>> interested in those that can).
>
> The ones that seem to be relevant to what you are looking for (I'm
> guessing) are a small class, and I don't think you can discern them
> from the others unless you look at the "rules" parts of a
> composition.
Looking at the rules sounds fine; thanks! I think these compositions form a
small class in terms of what Emacs supports, but that class seems to most if
not all uses of composition that I see in my daily use of Emacs (where are
other compositions used, beyond character spacing in what-cursor-position?).
Based on your pointers, the following seems to work OK for me (I guess it could
be extended to cover the (Bl . Br) case, but I haven't seen that pop up yet in
practice).
(defun esh--parse-composition (components)
"Translate composition COMPONENTS into a string."
(let ((chars (list (aref components 0)))
(nrules (/ (length components) 2)))
(dotimes (nrule nrules)
(let* ((rule (aref components (+ 1 (* 2 nrule))))
(char (aref components (+ 2 (* 2 nrule)))))
(pcase rule
(`(Br . Bl) (push char chars))
(_ (error "Unsupported composition COMPONENTS")))))
(concat chars)))
Thanks,
Clément.