From 5e389c9c8bea4667bd2a09a8b847004b058b1d64 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Thu, 20 Jun 2024 12:52:06 +0300 Subject: [PATCH] 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'. (cherry picked from commit 775aeabcfbf84c950610738cd130bf652c77bfa5) --- doc/lispref/display.texi | 8 ++++++-- src/dispextern.h | 5 +++++ src/xdisp.c | 9 ++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 4ea1bce320c..9960e807437 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -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 @@ -5382,7 +5384,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 diff --git a/src/dispextern.h b/src/dispextern.h index 85012130689..51dc354d37c 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -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, diff --git a/src/xdisp.c b/src/xdisp.c index 0148cd76ada..5987813cd28 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -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) -- 2.39.2