* Converting compositions to strings
@ 2017-01-30 5:13 Clément Pit-Claudel
2017-01-30 13:34 ` Stefan Monnier
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Clément Pit-Claudel @ 2017-01-30 5:13 UTC (permalink / raw)
To: Emacs developers
Hi emacs-devel,
Many compositions can be represented as strings: for example, prettify-symbols-mode composes "lambda" into "λ", and nameless prettifies the name of the current package as ":" or "::".
How can I reconstruct these strings from the value of the 'composition' text property? Small experiments suggest that for single-character compositions the property has the shape (_ _ [?λ]) and for multi-character compositions (_ _ [?x _ ?y _ …]), but I also found instances of the shape ((_ ?x _ _)), and ((_ . ?x)) (I think).
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).
Thanks!
Clément.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Converting compositions to strings
2017-01-30 5:13 Converting compositions to strings Clément Pit-Claudel
@ 2017-01-30 13:34 ` Stefan Monnier
2017-01-30 16:23 ` Clément Pit-Claudel
2017-01-30 14:24 ` Ted Zlatanov
2017-01-30 15:18 ` Eli Zaretskii
2 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2017-01-30 13:34 UTC (permalink / raw)
To: emacs-devel
> How can I reconstruct these strings from the value of the 'composition' text
> property?
This value is documented explicitly as being "internal! don't look at it!".
Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Converting compositions to strings
2017-01-30 5:13 Converting compositions to strings Clément Pit-Claudel
2017-01-30 13:34 ` Stefan Monnier
@ 2017-01-30 14:24 ` Ted Zlatanov
2017-01-30 16:27 ` Clément Pit-Claudel
2017-01-30 15:18 ` Eli Zaretskii
2 siblings, 1 reply; 10+ messages in thread
From: Ted Zlatanov @ 2017-01-30 14:24 UTC (permalink / raw)
To: emacs-devel
On Mon, 30 Jan 2017 00:13:34 -0500 Clément Pit-Claudel <cpitclaudel@gmail.com> wrote:
CP> Many compositions can be represented as strings: for example, prettify-symbols-mode composes "lambda" into "λ", and nameless prettifies the name of the current package as ":" or "::".
CP> How can I reconstruct these strings from the value of the 'composition' text
CP> property?
Can you explain why you need this?
Ted
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Converting compositions to strings
2017-01-30 5:13 Converting compositions to strings Clément Pit-Claudel
2017-01-30 13:34 ` Stefan Monnier
2017-01-30 14:24 ` Ted Zlatanov
@ 2017-01-30 15:18 ` Eli Zaretskii
2017-01-30 16:39 ` Clément Pit-Claudel
2 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-01-30 15:18 UTC (permalink / raw)
To: Clément Pit-Claudel; +Cc: emacs-devel
> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
> Date: Mon, 30 Jan 2017 00:13:34 -0500
>
> Many compositions can be represented as strings: for example, prettify-symbols-mode composes "lambda" into "λ", and nameless prettifies the name of the current package as ":" or "::".
>
> How can I reconstruct these strings from the value of the 'composition' text property? Small experiments suggest that for single-character compositions the property has the shape (_ _ [?λ]) and for multi-character compositions (_ _ [?x _ ?y _ …]), but I also found instances of the shape ((_ ?x _ _)), and ((_ . ?x)) (I think).
The information about this can be found in the doc strong of
compose-region, under COMPONENTS.
> 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).
I don't really understand what you mean by "string representation of a
composition". In general, a composition doesn't represent a string,
and even those that are represented by characters or strings in the
property are many times something other than a string. 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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Converting compositions to strings
2017-01-30 15:18 ` Eli Zaretskii
@ 2017-01-30 16:39 ` Clément Pit-Claudel
2017-01-30 16:52 ` Eli Zaretskii
0 siblings, 1 reply; 10+ messages in thread
From: Clément Pit-Claudel @ 2017-01-30 16:39 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: emacs-devel
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.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Converting compositions to strings
2017-01-30 16:39 ` Clément Pit-Claudel
@ 2017-01-30 16:52 ` Eli Zaretskii
2017-01-31 14:31 ` Stefan Monnier
0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2017-01-30 16:52 UTC (permalink / raw)
To: Clément Pit-Claudel; +Cc: emacs-devel
> Cc: emacs-devel@gnu.org
> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
> Date: Mon, 30 Jan 2017 11:39:09 -0500
>
> 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?
No, AFAIK this documents both relative and rule-based compositions.
> > 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)))
I think if we want to be able to produce text with all the text
properties and overlays expressed explicitly as text, we need to write
a back-end for xdisp.c that "displays" to a buffer. It shouldn't be
hard, the number of interface routines a back-end needs to support is
not large; see 'struct redisplay_interface' in dispextern.h.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Converting compositions to strings
2017-01-30 16:52 ` Eli Zaretskii
@ 2017-01-31 14:31 ` Stefan Monnier
0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2017-01-31 14:31 UTC (permalink / raw)
To: emacs-devel
> I think if we want to be able to produce text with all the text
> properties and overlays expressed explicitly as text, we need to write
> a back-end for xdisp.c that "displays" to a buffer. It shouldn't be
> hard, the number of interface routines a back-end needs to support is
> not large; see 'struct redisplay_interface' in dispextern.h.
And IIRC it was mentioned that it would be helpful for some ERT tests
(and even more so, if it can render the whole screen, so we can test
the appearance of the modeline and headerline as well).
Stefan
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-01-31 14:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-30 5:13 Converting compositions to strings Clément Pit-Claudel
2017-01-30 13:34 ` Stefan Monnier
2017-01-30 16:23 ` Clément Pit-Claudel
2017-01-30 14:24 ` Ted Zlatanov
2017-01-30 16:27 ` Clément Pit-Claudel
2017-01-30 17:48 ` Ted Zlatanov
2017-01-30 15:18 ` Eli Zaretskii
2017-01-30 16:39 ` Clément Pit-Claudel
2017-01-30 16:52 ` Eli Zaretskii
2017-01-31 14:31 ` Stefan Monnier
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.