Subject: Re: bug#10047: Looking for help debugging an undo issue

From: Stefan Monnier <[email-masked]>
Date: Tue, 29 Nov 2011 15:22:10 -0500

> As it turned out, most of my code & context was irrelevant.
> You should be able to reproduce the bug like this:

> emacs -Q
> M-: (add-hook 'post-command-hook 'align-current) RET
> <backspace> (until the scratch buffer message is gone)
> C-/ (or otherwise undo, until it fails with the message
> "No further undo information")

OK, here's my analysis:
1- align-current uses several (call it M) temporary markers.
2- they all get added to the undo-list whenever you DEL (because their
   position is modified).
3- so after N uses of DEL, you have M * N^2 entries.  In my tests, M is
   10, so after deleting 50 chars, you have 10 * 2500 = 25000
   "marker-update" entries in your undo-log.
4- at the beginning of GC, the log is considered too long (because of
   those spurious entries) and gets truncated.
5- at the end of GC, those spurious entries are removed from the log
   because those markers were temporary and only the undo-log still had
   references to them.

The problem can be fixed in 2 ways, both of which are desired:
- change align.el so it doesn't leave so many temporary markers around
  (it could use fewer markers, and it could also unset them explicitly
  at the end).
- swap 4 and 5 (actually it was swapped in Emacs-22, so that would
  revert to the behavior of Emacs-21).

I've installed a patch which reduces align.el's use of markers a little
bit.  It seems sufficient to get your test case to work, but I can't
guarantee it will solve the problem in your more general case.
It'd take a bit more analysis of align.el's code to figure out how to
fix it further.

        Stefan