Subject: Re: bug#73600: 31.0.50; Visual wrap prefix mode and image display

From: Jim Porter <[email-masked]>
Date: Thu, 3 Oct 2024 17:28:14 -0700

On 10/3/2024 3:59 AM, Eli Zaretskii wrote:
> I think image-mode is just the tip of a very large iceberg, see above:
> visual-wrap-prefix-mode currently doesn't correctly handle text
> covered by display properties.  I think this bug was uncovered when we
> removed on master a few artificial restrictions on min-width, such as
> non-support for display and overlay strings.

How about something like this? With this patch, if the start of a line 
is in the middle of a multi-line display spec, 'visual-wrap-prefix-mode' 
won't add any new properties. That should prevent any unwanted interference.

From 432ac5b4fd4a5f15b0ae59d739ed2dd2b2e38a05 Mon Sep 17 00:00:00 2001
From: Jim Porter <[email-masked]>
Date: Thu, 3 Oct 2024 17:24:18 -0700
Subject: [PATCH] Don't add visual-wrap-prefix properties to multiline display
 specs

This makes sure we don't interfere with other display specs, e.g. for
images displayed in 'image-mode' (bug#73600).

* lisp/visual-wrap.el (visual-wrap--apply-to-line): Bail out if we're in
the middle of a multi-line display spec
---
 lisp/visual-wrap.el | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lisp/visual-wrap.el b/lisp/visual-wrap.el
index 76276c0f474..af0b4fc8b0f 100644
--- a/lisp/visual-wrap.el
+++ b/lisp/visual-wrap.el
@@ -117,7 +117,16 @@ visual-wrap--apply-to-line
   "Apply visual-wrapping properties to the logical line starting at POSITION."
   (save-excursion
     (goto-char position)
-    (when-let ((first-line-prefix (fill-match-adaptive-prefix))
+    (when-let (;; Don't add wrapping properties if we're in the middle
+               ;; of a multi-line display spec; it could be doing
+               ;; absolutely anything, and we don't want to interfere.
+               ;; (For example, this could be an image containing a
+               ;; newline-byte being displayed in `image-mode'; see
+               ;; bug#73600.)
+               ((or (= position (point-min))
+                    (not (eq (get-char-property position 'display)
+                             (get-char-property (1- position) 'display)))))
+               (first-line-prefix (fill-match-adaptive-prefix))
                (next-line-prefix (visual-wrap--content-prefix
                                   first-line-prefix position)))
       (when (numberp next-line-prefix)
-- 
2.25.1