all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jim Porter <jporterbugs@gmail.com>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 72721@debbugs.gnu.org, gautier@gautierponsinet.xyz
Subject: bug#72721: 31.0.50; Visual-wrap-prefix-mode breaks Magit log buffers
Date: Tue, 20 Aug 2024 22:18:11 -0700	[thread overview]
Message-ID: <f61ddda8-4fc4-b05f-b14c-8a0147ac4739@gmail.com> (raw)
In-Reply-To: <c3a6a9e9-0cae-f7bb-a52e-29c30a3a2e46@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 508 bytes --]

On 8/20/2024 8:15 PM, Jim Porter wrote:
> Hopefully the attached reproducers help make sense of this. I've also 
> updated my patch to handle 'min-width' in what I think is a simpler way. 
> This implementation relies on the fact that you can't nest 'min-width' 
> specs (the iterator struct can only hold one spec at a time). I'm 
> guessing on some of these parts, so I may be totally off-base, but the 
> test cases do what I expect anyway...

Whoops, I'd uploaded the wrong patch. Here's the correct one.

[-- Attachment #2: 0001-Fix-bad-interactions-with-min-width-display-spec-and.patch --]
[-- Type: text/plain, Size: 4647 bytes --]

From f149cf2d6fbd9f864696620f94187e373812c919 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Mon, 19 Aug 2024 17:38:47 -0700
Subject: [PATCH] Fix bad interactions with 'min-width' display spec and
 replacement strings

Previously, when iterating over overlays or replacement strings from a
display spec, we would pass the string and the buffer position to
'display_min_width', which would use  those values to try to get the
display property.  However, the buffer position is very likely out of
bounds for the replacement string! (bug#72721)

* src/xdisp.c (get_display_property): Rename BUFPOS to CHARPOS; OBJECT
might not be a buffer.
(display_min_width): Add CHARPOS argument and update callers.  This
helps us distinguish when we're still examining a replacement string.
Simplify implementation to use a non-nil 'min_width_property' to
determine what to do; since we can't nest 'min-width', this should be
safe.  It also lets us insert space into the buffer at the right time.
---
 src/xdisp.c | 41 +++++++++++++++--------------------------
 1 file changed, 15 insertions(+), 26 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index 30771a1c83d..1fb9a436b8c 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -5633,15 +5633,15 @@ find_display_property (Lisp_Object disp, Lisp_Object prop)
 }
 
 static Lisp_Object
-get_display_property (ptrdiff_t bufpos, Lisp_Object prop, Lisp_Object object)
+get_display_property (ptrdiff_t charpos, Lisp_Object prop, Lisp_Object object)
 {
-  return find_display_property (Fget_text_property (make_fixnum (bufpos),
+  return find_display_property (Fget_text_property (make_fixnum (charpos),
 						    Qdisplay, object),
 				prop);
 }
 
 static void
-display_min_width (struct it *it, ptrdiff_t bufpos,
+display_min_width (struct it *it, ptrdiff_t bufpos, ptrdiff_t charpos,
 		   Lisp_Object object, Lisp_Object width_spec)
 {
   /* We're being called at the end of the `min-width' sequence,
@@ -5656,11 +5656,8 @@ display_min_width (struct it *it, ptrdiff_t bufpos,
       if ((bufpos == 0
 	   && !EQ (it->min_width_property,
 		   get_display_property (0, Qmin_width, object)))
-	  /* In a buffer -- check that we're really right after the
-	     sequence of characters covered by this `min-width'.  */
-	  || (bufpos > BEGV
-	      && EQ (it->min_width_property,
-		     get_display_property (bufpos - 1, Qmin_width, object))))
+	  /* In a buffer, and not working with a replacement string.  */
+	  || (bufpos > BEGV && charpos > 0))
 	{
 	  Lisp_Object w = Qnil;
 	  double width;
@@ -5705,21 +5702,13 @@ display_min_width (struct it *it, ptrdiff_t bufpos,
   /* We're at the start of a `min-width' sequence -- record the
      position and the property, so that we can later see if we're at
      the end.  */
-  if (CONSP (width_spec))
+  if (CONSP (width_spec)
+      /* Make sure we're not actively processing a `min-width' sequence.
+	 We can't currently nest them.  */
+      && NILP (it->min_width_property))
     {
-      if (bufpos == BEGV
-	  /* Mode line (see above).  */
-	  || (bufpos == 0
-	      && !EQ (it->min_width_property,
-		      get_display_property (0, Qmin_width, object)))
-	  /* Buffer.  */
-	  || (bufpos > BEGV
-	      && !EQ (width_spec,
-		      get_display_property (bufpos - 1, Qmin_width, object))))
-	{
-	  it->min_width_property = width_spec;
-	  it->min_width_start = it->current_x;
-	}
+      it->min_width_property = width_spec;
+      it->min_width_start = it->current_x;
     }
 }
 
@@ -5795,10 +5784,10 @@ handle_display_prop (struct it *it)
   if (!STRINGP (it->string))
     object = it->w->contents;
 
-  /* Handle min-width ends. */
+  /* Handle min-width ends.  */
   if (!NILP (it->min_width_property)
       && NILP (find_display_property (propval, Qmin_width)))
-    display_min_width (it, bufpos, object, Qnil);
+    display_min_width (it, bufpos, CHARPOS (*position), object, Qnil);
 
   if (NILP (propval))
     return HANDLED_NORMALLY;
@@ -6099,7 +6088,7 @@ handle_single_display_spec (struct it *it, Lisp_Object spec, Lisp_Object object,
       && CONSP (XCAR (XCDR (spec))))
     {
       if (it)
-	display_min_width (it, bufpos, object, XCAR (XCDR (spec)));
+	display_min_width (it, bufpos, CHARPOS (*position), object, XCAR (XCDR (spec)));
       return 0;
     }
 
@@ -29235,7 +29224,7 @@ display_string (const char *string, Lisp_Object lisp_string, Lisp_Object face_st
 	    {
 	      Lisp_Object min_width = plist_get (display, Qmin_width);
 	      if (!NILP (min_width))
-		display_min_width (it, 0, face_string, min_width);
+		display_min_width (it, 0, 0, face_string, min_width);
 	    }
 	}
     }
-- 
2.25.1


  reply	other threads:[~2024-08-21  5:18 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-19 21:39 bug#72721: 31.0.50; Visual-wrap-prefix-mode breaks Magit log buffers Gautier Ponsinet
2024-08-20  0:46 ` Jim Porter
2024-08-20 11:53   ` Eli Zaretskii
2024-08-20 17:33     ` Jim Porter
2024-08-20 19:01       ` Eli Zaretskii
2024-08-21  3:15         ` Jim Porter
2024-08-21  5:18           ` Jim Porter [this message]
2024-08-21 19:12             ` Jim Porter
2024-08-22 12:54               ` Eli Zaretskii
2024-08-22  9:59             ` Eli Zaretskii
2024-08-22  9:53           ` Eli Zaretskii
2024-08-22 16:19             ` Jim Porter
2024-08-25  7:29               ` Eli Zaretskii
2024-08-25 16:26                 ` Jim Porter
2024-08-25 17:39                   ` Eli Zaretskii
2024-08-25 18:41                     ` Jim Porter
2024-08-29 11:47                       ` Eli Zaretskii
2024-08-30  5:01                         ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f61ddda8-4fc4-b05f-b14c-8a0147ac4739@gmail.com \
    --to=jporterbugs@gmail.com \
    --cc=72721@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=gautier@gautierponsinet.xyz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.