Subject: bug#77336: [PATCH] Fix mouse highlighting for compact mode lines

From: Eli Zaretskii <[email-masked]>
Date: Sat, 29 Mar 2025 12:21:01 +0300

> From: Pengji Zhang <[email-masked]>
> Date: Fri, 28 Mar 2025 18:55:30 +0800
> 
> @@ -28014,7 +28059,10 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
>  		n += store_mode_line_noprop (SSDATA (elt), -1, prec);
>  		break;
>  	      case MODE_LINE_STRING:
> -		n += store_mode_line_string (NULL, elt, true, 0, prec, Qnil);
> +		{
> +		  AUTO_LIST2 (src, Qmode_line_element, elt);
> +		  n += store_mode_line_string (NULL, elt, true, 0, prec, src);
> +		}
>  		break;
>  	      case MODE_LINE_DISPLAY:
>  		n += display_string (NULL, elt, Qnil, 0, 0, it,
> @@ -28067,8 +28115,9 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
>  		      Lisp_Object mode_string
>  			= Fsubstring (elt, make_fixnum (charpos),
>  				      make_fixnum (endpos));
> +		      AUTO_LIST2 (src, Qmode_line_element, elt);
>  		      n += store_mode_line_string (NULL, mode_string, false,
> -						   0, 0, Qnil);
> +						   0, 0, src);
>  		    }
>  		    break;
>  		  case MODE_LINE_DISPLAY:
> @@ -28148,6 +28197,7 @@ display_mode_element (struct it *it, int depth, int field_width, int precision,
>  			{
>  			  Lisp_Object tem = build_string (spec);
>  			  props = Ftext_properties_at (make_fixnum (charpos), elt);
> +			  props = plist_put (props, Qmode_line_element, elt);
>  			  /* Should only keep face property in props */
>  			  n += store_mode_line_string (NULL, tem, false,
>  						       field, prec, props);

Thanks, but why do we need to make the value of this mode-line-element
property be the element itself?  Why not give it some simple value,
like the ordinal number of the element (which should be incremented
whenever we process another element)?  So we could call this property
mode-line-elt-number and assign the elements values 1, 2, 3, etc.

I'm concerned that having the elements themselves be values will
prevent them from being GC'd, which might increase the memory
pressure.  By contrast, fixnums are immediate values that don't need
to be GC'ed, and the element itself will not have any references after
the mode line is processed.