Subject: bug#76008: 31.0.50; visual-wrap-prefix-mode miscalculates prefix width when scaling text

From: Jim Porter <[email-masked]>
Date: Mon, 3 Feb 2025 14:36:23 -0800

On 2/2/2025 4:03 AM, Kévin Le Gouguec wrote:
> I believe the cause lies in visual-wrap--content-prefix; empirically the
> attached patch shows good results on this reproducer, but I landed on it
> more by trial-and-error than by rational analysis, so it may be
> incorrect or suboptimal (e.g. there may be better text-scale or
> string-width APIs to use).

Thanks. I think the issue here is actually that the display spec for the 
"average space" was wrong. It used a plain number for the width of the 
specified space, which means "N times the normal character width for the 
buffer", but we want "N times the normal character width for the 
*current face*".

Could you try this patch?

----------------------------------------

diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 1691ba9c500..f2a186ce320 100644
--- a/lisp/visual-wrap.el
+++ b/lisp/visual-wrap.el
@@ -164,7 +164,7 @@ visual-wrap--content-prefix
      ;; units of the font's average-width) large enough to fit the
      ;; first-line prefix.
      (let ((avg-space (propertize (buffer-substring position (1+ position))
-                                 'display '(space :width 1))))
+                                 'display '(space :width (1 . width)))))
        ;; Remove any `min-width' display specs since we'll replace with
        ;; our own later in `visual-wrap--apply-to-line' (bug#73882).
        (add-display-text-property 0 (length prefix) 'min-width nil prefix)