Subject: Re: bug#79200: 31.0.50; Duplicated elements for '#<marker at' in buffer-undo-list

From: Gerd Möllmann <[email-masked]>
Date: Sat, 09 Aug 2025 12:12:51 +0200

Pip Cet via "Bug reports for GNU Emacs, the Swiss army knife of text
editors" <[email-masked]> writes:

> Well, compact_undo_list is a nop with HAVE_MPS:
>
> static Lisp_Object
> compact_undo_list (Lisp_Object list)
> {
> #ifndef HAVE_MPS
>   Lisp_Object tail, *prev = &list;
>
>   for (tail = list; CONSP (tail); tail = XCDR (tail))
>     {
>       if (CONSP (XCAR (tail))
> 	  && MARKERP (XCAR (XCAR (tail)))
> 	  && !vectorlike_marked_p (&XMARKER (XCAR (XCAR (tail)))->header))
> 	*prev = XCDR (tail);
>       else
> 	prev = xcdr_addr (tail);
>     }
> #endif
>   return list;
> }
>
> We still truncate undo lists, but we don't "compact" them, i.e. treat
> them as weak structures and remove markers that are referred to only in
> undo lists. Correct?

I think you are correct. buffer_step -> compact_buffer ->
truncate_undo_list, but no compact.

> The "obvious" fix would be to use a weak hash table to associate undo
> information with markers rather than keeping them in the undo
> list. However, that sounds quite hard to do, and it might make undo a
> lot more expensive.

Hm, yes that sounds hard. Hm.

Do you think we could, in compact, locally keep track of markers already
seen, and coalesce their entries somehow? My memory of the undo stuff is
pretty hazy, alas, and probably outdated, too.