unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
@ 2020-04-25 21:24 Clément Pit-Claudel
  2020-04-26 15:33 ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Clément Pit-Claudel @ 2020-04-25 21:24 UTC (permalink / raw)
  To: 40856

Hi all,

The wrap-prefix property is very convenient, but it's hard to use for alignment when the width of the item to align to is not easy to compute.  For example, to get the following effect, it's easy to use 'wrap-prefix "  "

- Test
  wrapped
  wrapped

But take a more complex case, like this:

xyz
⟝ abc
   wrapped
   wrapped

Depending on the font in use, the ⟝ character may be more or less wide.  So, the wrap prefix can't just be "  " here; it needs to be calculated using `window-text-pixel-size`, which is costly if it needs to be repeated for many lines.  Additionally, this calculation becomes obsolete and needs to be redone as soon as the user changes the font size.

Or consider the first example again, but this time with non-monospace text:

- Test
  wrapped
  wrapped

Depending on the width of "-" and of the space in the current font, the with of the wrapping prefix should be different.

Specified spaces can already measure the width of an image and many other elements.  Could they be extended to measure an arbitrary string?  Concretely, one would use (:space :width "- ") in the first case and (:space :width "⟝ ") in the second case, and get perfect alignment.  This is similar to what LaTeX calls "phantoms": spaces whose width is exactly that of their argument text.

Clément.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
  2020-04-25 21:24 bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications Clément Pit-Claudel
@ 2020-04-26 15:33 ` Eli Zaretskii
  2020-04-26 16:09   ` Clément Pit-Claudel
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2020-04-26 15:33 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: 40856

> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
> Date: Sat, 25 Apr 2020 17:24:19 -0400
> 
> The wrap-prefix property is very convenient, but it's hard to use for alignment when the width of the item to align to is not easy to compute.  For example, to get the following effect, it's easy to use 'wrap-prefix "  "
> 
> - Test
>   wrapped
>   wrapped
> 
> But take a more complex case, like this:
> 
> xyz
> ⟝ abc
>    wrapped
>    wrapped
> 
> Depending on the font in use, the ⟝ character may be more or less wide.  So, the wrap prefix can't just be "  " here; it needs to be calculated using `window-text-pixel-size`, which is costly if it needs to be repeated for many lines.  Additionally, this calculation becomes obsolete and needs to be redone as soon as the user changes the font size.

wrap-prefix can have value that uses :align-to, so I don't see why
you'd need to call window-text-pixel-size many times.  You could call
it once, and then use the result in the subsequent values of prefix.

> Specified spaces can already measure the width of an image and many other elements.  Could they be extended to measure an arbitrary string?  Concretely, one would use (:space :width "- ") in the first case and (:space :width "⟝ ") in the second case, and get perfect alignment.

It should be possible to do that, but I'm not sure it will be cheaper
than calling window-text-pixel-size or something similar, because
(unlike with images) Emacs doesn't have the width already calculated
and stashed somewhere, it would need to lay out the string and
calculate the resulting pixel width each time it sees such a display
spec.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
  2020-04-26 15:33 ` Eli Zaretskii
@ 2020-04-26 16:09   ` Clément Pit-Claudel
  2020-04-26 17:07     ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Clément Pit-Claudel @ 2020-04-26 16:09 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40856

On 26/04/2020 11.33, Eli Zaretskii wrote:
>> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
>> Date: Sat, 25 Apr 2020 17:24:19 -0400
>>
>> The wrap-prefix property is very convenient, but it's hard to use for alignment when the width of the item to align to is not easy to compute.  For example, to get the following effect, it's easy to use 'wrap-prefix "  "
>>
>> - Test
>>   wrapped
>>   wrapped
>>
>> But take a more complex case, like this:
>>
>> xyz
>> ⟝ abc
>>    wrapped
>>    wrapped
>>
>> Depending on the font in use, the ⟝ character may be more or less wide.  So, the wrap prefix can't just be "  " here; it needs to be calculated using `window-text-pixel-size`, which is costly if it needs to be repeated for many lines.  Additionally, this calculation becomes obsolete and needs to be redone as soon as the user changes the font size.
> 
> wrap-prefix can have value that uses :align-to, so I don't see why
> you'd need to call window-text-pixel-size many times.  You could call> it once, and then use the result in the subsequent values of prefix.

True, if the prefix is the same on every line.
But that calculation isn't very robust to changes in font sizes, other face options, and windows.

>> Specified spaces can already measure the width of an image and many other elements.  Could they be extended to measure an arbitrary string?  Concretely, one would use (:space :width "- ") in the first case and (:space :width "⟝ ") in the second case, and get perfect alignment.
> 
> It should be possible to do that, but I'm not sure it will be cheaper
> than calling window-text-pixel-size or something similar, because
> (unlike with images) Emacs doesn't have the width already calculated
> and stashed somewhere, it would need to lay out the string and
> calculate the resulting pixel width each time it sees such a display
> spec.

I think that would be great; the cost should be reasonable, since 1. it only applies to the part of the buffer that is being displayed and 2. it won't be costlier than using the stirng being measured as the wrap prefix.
IOW, if we expect that it wouldn't be too costly to use a given string as the wrap-prefix, then it shouldn't be too costly to use a specified space of that width as the wrap prefix.

Thanks a lot,
Clément.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
  2020-04-26 16:09   ` Clément Pit-Claudel
@ 2020-04-26 17:07     ` Eli Zaretskii
  2020-04-26 17:23       ` Clément Pit-Claudel
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2020-04-26 17:07 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: 40856

> Cc: 40856@debbugs.gnu.org
> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
> Date: Sun, 26 Apr 2020 12:09:31 -0400
> 
> > wrap-prefix can have value that uses :align-to, so I don't see why
> > you'd need to call window-text-pixel-size many times.  You could call> it once, and then use the result in the subsequent values of prefix.
> 
> True, if the prefix is the same on every line.
> But that calculation isn't very robust to changes in font sizes, other face options, and windows.

I don't think I follow.  :align-to accepts pixel specification, so it
should be insensitive to font changes.

> > It should be possible to do that, but I'm not sure it will be cheaper
> > than calling window-text-pixel-size or something similar, because
> > (unlike with images) Emacs doesn't have the width already calculated
> > and stashed somewhere, it would need to lay out the string and
> > calculate the resulting pixel width each time it sees such a display
> > spec.
> 
> I think that would be great; the cost should be reasonable, since 1. it only applies to the part of the buffer that is being displayed and 2. it won't be costlier than using the stirng being measured as the wrap prefix.

I don't think your 2. is necessarily correct, because you want the
width computed each time the prefix spec is being used to produce
glyphs, by which time the string is old history.

> IOW, if we expect that it wouldn't be too costly to use a given string as the wrap-prefix, then it shouldn't be too costly to use a specified space of that width as the wrap prefix.

I don't think I follow the logic.  You intend to use :space in the
prefix spec, not the string.  So the display engine will have to
perform layout of the string and compute its pixel width each time it
produces a prefix for another line.  The string itself is either not
actually displayed, or is displayed on the first line of the
paragraph, before all the wrapped lines.  It may well be that
redisplay needs to produce the display of just some lines, which don't
even include the one with the string itself.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
  2020-04-26 17:07     ` Eli Zaretskii
@ 2020-04-26 17:23       ` Clément Pit-Claudel
  2020-04-26 17:43         ` Eli Zaretskii
  0 siblings, 1 reply; 7+ messages in thread
From: Clément Pit-Claudel @ 2020-04-26 17:23 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40856

On 26/04/2020 13.07, Eli Zaretskii wrote:
>> Cc: 40856@debbugs.gnu.org
>> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
>> Date: Sun, 26 Apr 2020 12:09:31 -0400
>>
>>> wrap-prefix can have value that uses :align-to, so I don't see why
>>> you'd need to call window-text-pixel-size many times.  You could call> it once, and then use the result in the subsequent values of prefix.
>>
>> True, if the prefix is the same on every line.
>> But that calculation isn't very robust to changes in font sizes, other face options, and windows.
> 
> I don't think I follow.  :align-to accepts pixel specification, so it
> should be insensitive to font changes.

I typically want to align text relative to a prefix whose length depends on face properties, so if I use window-text-pixel-size, I need to redo the computation every time faces change.

>> I think that would be great; the cost should be reasonable, since 1. it only applies to the part of the buffer that is being displayed and 2. it won't be costlier than using the stirng being measured as the wrap prefix.
> 
> I don't think your 2. is necessarily correct, because you want the
> width computed each time the prefix spec is being used to produce
> glyphs, by which time the string is old history.
> 
>> IOW, if we expect that it wouldn't be too costly to use a given string as the wrap-prefix, then it shouldn't be too costly to use a specified space of that width as the wrap prefix.
> 
> I don't think I follow the logic.  You intend to use :space in the
> prefix spec, not the string.  So the display engine will have to
> perform layout of the string and compute its pixel width each time it
> produces a prefix for another line.  The string itself is either not
> actually displayed, or is displayed on the first line of the
> paragraph, before all the wrapped lines.  It may well be that
> redisplay needs to produce the display of just some lines, which don't
> even include the one with the string itself.

What I meant to say is that if it's cheap enough to draw this:

⟝ bbbbbbbbbbb
⟝ bbbbbbbbbbb
⟝ bbbbbbbbbbb
⟝ bbbbbbbbbbb
⟝ bbbbbbbbbbb

(where "⟝" is a wrap-prefix on all lines but the first)

… then it should be cheap enough to draw this:

⟝ bbbbbbbbbbb
   bbbbbbbbbbb
   bbbbbbbbbbb
   bbbbbbbbbbb
   bbbbbbbbbbb

where the indentation is a specified space as wide as "⟝".

Clément.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
  2020-04-26 17:23       ` Clément Pit-Claudel
@ 2020-04-26 17:43         ` Eli Zaretskii
  2020-04-26 18:25           ` Clément Pit-Claudel
  0 siblings, 1 reply; 7+ messages in thread
From: Eli Zaretskii @ 2020-04-26 17:43 UTC (permalink / raw)
  To: Clément Pit-Claudel; +Cc: 40856

> Cc: 40856@debbugs.gnu.org
> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
> Date: Sun, 26 Apr 2020 13:23:15 -0400
> 
> What I meant to say is that if it's cheap enough to draw this:
> 
> ⟝ bbbbbbbbbbb
> ⟝ bbbbbbbbbbb
> ⟝ bbbbbbbbbbb
> ⟝ bbbbbbbbbbb
> ⟝ bbbbbbbbbbb
> 
> (where "⟝" is a wrap-prefix on all lines but the first)
> 
> … then it should be cheap enough to draw this:
> 
> ⟝ bbbbbbbbbbb
>    bbbbbbbbbbb
>    bbbbbbbbbbb
>    bbbbbbbbbbb
>    bbbbbbbbbbb
> 
> where the indentation is a specified space as wide as "⟝".

And what I meant is that the second one is more expensive, because for
each line but the first, Emacs will have to produce glyphs both for
"⟝" (to obtain its width) and for the stretch of space.





^ permalink raw reply	[flat|nested] 7+ messages in thread

* bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications
  2020-04-26 17:43         ` Eli Zaretskii
@ 2020-04-26 18:25           ` Clément Pit-Claudel
  0 siblings, 0 replies; 7+ messages in thread
From: Clément Pit-Claudel @ 2020-04-26 18:25 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 40856

On 26/04/2020 13.43, Eli Zaretskii wrote:
>> Cc: 40856@debbugs.gnu.org
>> From: Clément Pit-Claudel <cpitclaudel@gmail.com>
>> Date: Sun, 26 Apr 2020 13:23:15 -0400
>>
>> What I meant to say is that if it's cheap enough to draw this:
>>
>> ⟝ bbbbbbbbbbb
>> ⟝ bbbbbbbbbbb
>> ⟝ bbbbbbbbbbb
>> ⟝ bbbbbbbbbbb
>> ⟝ bbbbbbbbbbb
>>
>> (where "⟝" is a wrap-prefix on all lines but the first)
>>
>> … then it should be cheap enough to draw this:
>>
>> ⟝ bbbbbbbbbbb
>>    bbbbbbbbbbb
>>    bbbbbbbbbbb
>>    bbbbbbbbbbb
>>    bbbbbbbbbbb
>>
>> where the indentation is a specified space as wide as "⟝".
> 
> And what I meant is that the second one is more expensive, because for
> each line but the first, Emacs will have to produce glyphs both for
> "⟝" (to obtain its width) and for the stretch of space.

Got it. I assumed that producing a stretch of space was cheap.





^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-04-26 18:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-25 21:24 bug#40856: Feature request: support arbitrary propertized strings in wrap-prefix specifications Clément Pit-Claudel
2020-04-26 15:33 ` Eli Zaretskii
2020-04-26 16:09   ` Clément Pit-Claudel
2020-04-26 17:07     ` Eli Zaretskii
2020-04-26 17:23       ` Clément Pit-Claudel
2020-04-26 17:43         ` Eli Zaretskii
2020-04-26 18:25           ` Clément Pit-Claudel

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