unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Question about align-to behaviour with wrap-mode
@ 2022-11-20 22:20 Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor
  2022-11-21 17:42 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor @ 2022-11-20 22:20 UTC (permalink / raw)
  To: help-gnu-emacs


I noticed what I think is strange behaviour with `:align-to` that I am wondering if it's intended and if there's a way of achieving a desired behaviour.

To reproduce in an `emacs -Q`, just run this:

(progn
   (toggle-word-wrap +1)
   (goto-char (point-max))
   (insert
    (concat "\n\n"
            (make-string (- (window-width) 3) 69)
            " "
            (propertize " " 'display
                        `(space :align-to (- right
                                             10)))
            "After\n\n")))

The word 'After' is not aligned to `(- right 10)` because the text before is too long. Instead "After" is displayed at the beginning of the next line (or broken across two lines if toggle-word-wrap is disabled) and the alignment is ignored.

If I execute instead

(progn
   (toggle-word-wrap +1)
   (goto-char (point-max))
   (insert
    (concat "\n\n"
            (make-string (window-width) 69)
            " "
            (propertize " " 'cursor 1 'display
                        `(space :align-to (- right
                                             10)))
            "After\n\n")))
            
the alignment is "correct" on the second line.

In both situation, I was intending (and expecting) the word "After" to be on the second line and to be correctly aligned at (- right 10). Is the current behaviour intended? Is there a way to achieve my desired behaviour?

I could of course add spaces before the right-aligned text, but then if more text is added I would need to adjust the spaces dynamically which is less-than-ideal.

-- Al

________________________________
Heriot-Watt University was founded in 1821 and is a registered Scottish charity (SC000278).



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

* Re: Question about align-to behaviour with wrap-mode
  2022-11-20 22:20 Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor
@ 2022-11-21 17:42 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-11-21 17:42 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Sun, 20 Nov 2022 22:20:50 +0000
> From:  Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> 
> 
> I noticed what I think is strange behaviour with `:align-to` that I am wondering if it's intended and if there's a way of achieving a desired behaviour.

It's intended, yes.

> To reproduce in an `emacs -Q`, just run this:
> 
> (progn
>    (toggle-word-wrap +1)
>    (goto-char (point-max))
>    (insert
>     (concat "\n\n"
>             (make-string (- (window-width) 3) 69)
>             " "
>             (propertize " " 'display
>                         `(space :align-to (- right
>                                              10)))
>             "After\n\n")))
> 
> The word 'After' is not aligned to `(- right 10)` because the text before is too long. Instead "After" is displayed at the beginning of the next line (or broken across two lines if toggle-word-wrap is disabled) and the alignment is ignored.
> 
> If I execute instead
> 
> (progn
>    (toggle-word-wrap +1)
>    (goto-char (point-max))
>    (insert
>     (concat "\n\n"
>             (make-string (window-width) 69)
>             " "
>             (propertize " " 'cursor 1 'display
>                         `(space :align-to (- right
>                                              10)))
>             "After\n\n")))
>             
> the alignment is "correct" on the second line.

I don't see the correct alignment here.  I see a behavior similar to the
first recipe, as I'd expect.

The problem here is that the implementation of align-to takes the width of
continuation lines into consideration, i.e. the column doesn't wrap to zero
when the line is continued.  So if the window is 80-column wide, and you say

     (space :align-to (- right 10))

that yields 70, but text wrapped to the next line has its horizontal
coordinate start from 80, so it is already past 70, and the alignment
doesn't happen.

The bottom line is that you cannot use relative alignment if your lines can
wrap, and hope for that to work.  For wrapped lines the alignment must be to
absolute column numbers, and it must take the continuation lines into
consideration when you calculate the alignment column.



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

* Re: Question about align-to behaviour with wrap-mode
@ 2022-11-22  9:45 Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor
  2022-11-22 13:46 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor @ 2022-11-22  9:45 UTC (permalink / raw)
  To: eliz, help-gnu-emacs


Thanks Eli for explaining.

> I don't see the correct alignment here.  I see a behavior similar to the
> first recipe, as I'd expect.

This is what I see with this example on my Emacs 28.2 (assume window width is 50):

,----
| EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
|                                         After
`----

So the text is "correctly" aligned to (- right 10) on the second line. Are you seeing something different?

The only problem I see is that when the word is broken and word-wrap is off then I get

,----
| EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE Af
| ter                                      
`----

while if word wrap is on I get

,----
| EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
| After                                      
`----


> The bottom line is that you cannot use relative alignment if your lines can
> wrap, and hope for that to work.  For wrapped lines the alignment must be to
> absolute column numbers, and it must take the continuation lines into
> consideration when you calculate the alignment column.

I see. Do you mean that I should write a hook to update the alignment of "After" as more text is inserted before it (to calculate the alignment column taking the continuation lines into considerations)?
Or is there a way to have `align-to` be calculated from a function?

Thanks,
-- Al

________________________________
Heriot-Watt University was founded in 1821 and is a registered Scottish charity (SC000278).



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

* Re: Question about align-to behaviour with wrap-mode
  2022-11-22  9:45 Question about align-to behaviour with wrap-mode Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor
@ 2022-11-22 13:46 ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2022-11-22 13:46 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Abdul-Lateef Haji-Ali <a.hajiali@hw.ac.uk>
> Date: Tue, 22 Nov 2022 09:45:20 +0000
> 
> > The bottom line is that you cannot use relative alignment if your lines can
> > wrap, and hope for that to work.  For wrapped lines the alignment must be to
> > absolute column numbers, and it must take the continuation lines into
> > consideration when you calculate the alignment column.
> 
> I see. Do you mean that I should write a hook to update the alignment of "After" as more text is inserted before it (to calculate the alignment column taking the continuation lines into considerations)?

Yes, something like that.

Basically, align-to is not well suited to deal with continued lines.



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

end of thread, other threads:[~2022-11-22 13:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22  9:45 Question about align-to behaviour with wrap-mode Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor
2022-11-22 13:46 ` Eli Zaretskii
  -- strict thread matches above, loose matches on Subject: below --
2022-11-20 22:20 Abdul-Lateef Haji-Ali via Users list for the GNU Emacs text editor
2022-11-21 17:42 ` Eli Zaretskii

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