Fix use of ':align-to' in 'wrap-prefix'

* src/dispextern.h (struct it): New flag 'align_visually_p'.
* src/xdisp.c (handle_line_prefix): Set the 'align_visually_p'
flag for 'wrap-prefix'.
(produce_stretch_glyph): If 'align_visually_p' flag is set, count
the :align-to offset from the beginning of the screen line, not
from BOL.  (Bug#71605)

* doc/lispref/display.texi (Truncation, Specified Space): Document
the special handling of ':align-to' in 'wrap-prefix'.
This commit is contained in:
Eli Zaretskii 2024-06-20 12:52:06 +03:00
parent b8affdb7b5
commit 775aeabcfb
3 changed files with 19 additions and 3 deletions

View file

@ -192,7 +192,9 @@ never used.) Its value may be a string or an image (@pxref{Other
Display Specs}), or a stretch of whitespace such as specified by the
@code{:width} or @code{:align-to} display properties (@pxref{Specified
Space}). The value is interpreted in the same way as a @code{display}
text property. @xref{Display Property}.
text property, with one important difference: the horizontal position
specified by @code{:align-to} is measured from the visual beginning of
the screen line. @xref{Display Property}.
A wrap prefix may also be specified for regions of text, using the
@code{wrap-prefix} text or overlay property. This takes precedence
@ -5354,7 +5356,9 @@ Scrolling}), @var{hpos} is measured from the beginning of the logical
line, not from the visual beginning of the screen line. This way,
alignment produced by @code{:align-to} is consistent with functions
that count columns, such as @code{current-column} and
@code{move-to-column} (@pxref{Columns}).
@code{move-to-column} (@pxref{Columns}). (There's a single exception
from this rule: when @code{:align-to} is used to specify whitespace of
the @code{wrap-prefix} variable or text property, @pxref{Truncation}.)
@end table
You should use one and only one of the above properties. You can

View file

@ -2629,6 +2629,11 @@ struct it
the current row. */
bool_bf line_number_produced_p : 1;
/* If true, the :align-to argument should be counted relative to the
beginning of the screen line, not the logical line. Used by
'wrap-prefix'. */
bool_bf align_visually_p : 1;
enum line_wrap_method line_wrap;
/* The ID of the default face to use. One of DEFAULT_FACE_ID,

View file

@ -24494,6 +24494,11 @@ handle_line_prefix (struct it *it)
prefix = get_line_prefix_it_property (it, Qwrap_prefix);
if (NILP (prefix))
prefix = Vwrap_prefix;
/* Interpreting :align-to relative to the beginning of the logical
line effectively renders this feature unusable, so we make an
exception for this use of :align-to. */
if (!NILP (prefix))
it->align_visually_p = true;
}
else
{
@ -31972,7 +31977,9 @@ produce_stretch_glyph (struct it *it)
&& calc_pixel_width_or_height (&tem, it, prop, font, true,
&align_to))
{
int x = it->current_x + it->continuation_lines_width;
int x = it->current_x + (it->align_visually_p
? 0
: it->continuation_lines_width);
int x0 = x;
/* Adjust for line numbers, if needed. */
if (!NILP (Vdisplay_line_numbers) && it->line_number_produced_p)