Subject: bug#76107: Consider image specs when scanning for a column

From: Thuna <[email-masked]>
Date: Fri, 07 Feb 2025 00:29:38 +0100

This patch handles display specs within `scan_for_column', which mainly
works to handle it in `current-column' and `move-to-column', which then
effects the filling functions and commands, and visual-fill-column, and
so on.

The patch seems to be working, as far as I can tell, but it would be
nice if someone could take a look.  Specifically, I copied the code to
convert the Lisp_Object holding the width into an integer from the code
above handling the space display properties, so that needs
double-checking.

I decided to use `Fcar_safe' instead of `XCAR' when taking the `car' of
`Fimage_size' just to be safe but it doesn't look to be necessary?  If
that's fine, then feel free to make the change.

>From 39e412bd6eb9fa37bb47005309ed4d36c853cabe Mon Sep 17 00:00:00 2001
From: Thuna <[email-masked]>
Date: Thu, 6 Feb 2025 19:51:28 +0100
Subject: [PATCH] Consider image specs when scanning for a column

* src/indent.c (check_display_width): If looking at an image display
property, return the image's width.
---
 src/indent.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/indent.c b/src/indent.c
index 3094a9d3089..d503274ea0b 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -507,6 +507,16 @@ check_display_width (ptrdiff_t pos, ptrdiff_t col, ptrdiff_t *endpos)
 		   && (XFLOAT_DATA (prop) <= align_to_max))
 	    width = (int)(XFLOAT_DATA (prop) + 0.5) - col;
 	}
+      /* Handle `(image ...)' display specs */
+      else if (CONSP (val) && EQ (Qimage, XCAR (val)))
+	{
+	  Lisp_Object raw_width = Fcar_safe (Fimage_size (val, Qnil, Qnil));
+	  if (RANGED_FIXNUMP (0, raw_width, INT_MAX))
+	    width = XFIXNUM (raw_width);
+	  else if (FLOATP (raw_width) && 0 <= XFLOAT_DATA (raw_width)
+		   && XFLOAT_DATA (raw_width) <= INT_MAX)
+	    width = (int) (XFLOAT_DATA (raw_width) + 0.5);
+	}
       /* Handle 'display' strings.   */
       else if (STRINGP (val))
 	width = XFIXNUM (Fstring_width (val, Qnil, Qnil));
-- 
2.44.2