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

From: Eli Zaretskii <[email-masked]>
Date: Sun, 30 Mar 2025 15:01:21 +0300

> From: Pengji Zhang <[email-masked]>
> Cc: [email-masked]
> Date: Sun, 30 Mar 2025 19:44:59 +0800
> 
> > 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.
> 
> Is casting the 'Lisp_Object' to a number acceptable here?

No, because Lisp_Object could be a struct (if Emacs was configured with
"--enable-check-lisp-object-type").

What I had in mind was to have a static global int variable named, say
elt_no, initialized to zero when display_mode_line is called, and then
give each segment of the mode line a value like this:

   AUTO_LIST2 (src, Qmode_line_element, make_fixnum (elt_no++));
   n += store_mode_line_string (NULL, elt, true, 0, prec, src);   

> I tried an incremental counter but gave up. Because
> 'display_mode_element' could be called recursively, we may have to
> change its signature or introduce a new global variable. That feels a
> bit less clean to me.

A global variable is what I had in mind.  I don't see why it would be
less clean.

> > 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.
> 
> I thought all objects would be GC'd. Since fixnums are not, I guess now
> we do not need to remove the text property before displaying the string?
> Please let me know what you think and I will update the patch if needed.

If you remove the text property because of GC, then indeed you don't
need to do that anymore with fixnums.