Subject: bug#76014: 31.0.50; Wrong highlighting of "All" in mode-line

From: Gerd Möllmann <[email-masked]>
Date: Tue, 04 Feb 2025 06:12:57 +0100

Gerd Möllmann <[email-masked]> writes:

> Gerd Möllmann <[email-masked]> writes:
>
>> Confirmed, 71505b723c9fb9de20f6d38be7c73d595e9be3ce it is.
>
> Don't know if this is directly related, but playing with
>
>   (defun foo ()
>     (interactive)
>     (with-current-buffer (get-buffer-create "*foo*")
>       (erase-buffer)
>       (insert "12345")
>       (put-text-property (point-min) (point)
>                          'display '(min-width (5)))
>       (put-text-property (point-min) (point)
>                          'mouse-face 'highlight)
>       (insert "abc")
>       (display-buffer (current-buffer))))
>
> shows that if the text, in this case "12345", is longer than min-width, a
> space is added, and if it's equal to min-width, no space is added.

That attached patch fixes both the above problem and the the one in the
mode-line.

>From 711f21b659633fb05b81f43f3e81391e5988fe3a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gerd=20M=C3=B6llmann?= <[email-masked]>
Date: Tue, 4 Feb 2025 06:09:52 +0100
Subject: [PATCH] Fix min-width display spec handling (bug#76014)

* src/xdisp.c (display_min_width): Take into account that the output may
already be longer than the specified min-width.
---
 src/xdisp.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/xdisp.c b/src/xdisp.c
index ed4a5564427..72311362035 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -5650,7 +5650,7 @@ get_display_property (ptrdiff_t charpos, Lisp_Object prop, Lisp_Object object)
 
 /* Handle 'display' property '(min-width (WIDTH))' at CHARPOS in OBJECT.
    OBJECT can be a buffer (or nil, which means the current buffer) or a
-   string.  MIN_WIDTH is the value of min-width spec that we expect to
+   string.  WIDTH_SPEC is the value of min-width spec that we expect to
    process.  */
 static void
 display_min_width (struct it *it, ptrdiff_t charpos,
@@ -5696,8 +5696,9 @@ display_min_width (struct it *it, ptrdiff_t charpos,
                  a stretch that ends beyond the visible portion of the
                  window if we are truncating screen lines.  If we are
                  requested to do that, some Lisp program went awry.  */
-	      if (!(it->line_wrap == TRUNCATE
-		    && it->current_x + width > it->last_visible_x))
+	      if (width > 0
+		  && !(it->line_wrap == TRUNCATE
+		       && it->current_x + width > it->last_visible_x))
 		w = list1 (make_int (width));
 	    }
 	  else
@@ -5708,8 +5709,9 @@ display_min_width (struct it *it, ptrdiff_t charpos,
 					  NULL, true, NULL);
 	      width -= (it->current_x - it->min_width_start) /
 		FRAME_COLUMN_WIDTH (it->f);
-	      if (!(it->line_wrap == TRUNCATE
-		    && it->current_x + width > it->last_visible_x))
+	      if (width > 0
+		  && !(it->line_wrap == TRUNCATE
+		       && it->current_x + width > it->last_visible_x))
 		w = make_int (width);
 	    }
 
-- 
2.48.1