Subject: bug#1501: Emacs 22 loses undo buffer

From: Stefan Kangas <[email-masked]>
Date: Tue, 20 Aug 2019 20:36:13 +0200

Chong Yidong <[email-masked]> writes:

> "Emerick Rogul" <[email-masked]> writes:
>
>> That's clearly not the issue at all, since the header file is only 8k
>> in total size.  What's more, I get the message after hitting the undo
>> key sequence a couple of times.  Also, this works perfectly fine in
>> Emacs 21.2, as I mentioned in my initial report.
>
> In the key sequence you reported:
>
> ... C-k C-k C-k C-k C-k C-k C-k C-k C-k
> C-k C-k C-k C-k C-k C-k C-k C-k C-k C-k C-k C-k C-k
> [snip]
> C-k C-k C-k C-k C-k C-k C-/ C-/ C-/ C-/ C-/ C-/ C-/
> C-/ C-/ C-/ C-/ C-/ C-/ C-/ C-/ C-/ C-/ C-/ C-/ C-/
> C-/ ESC x r e p o r t - e m a <tab> <return>
>
> it appears that you hit C-/ 22 times.  If Emacs kept 22 undo records,
> and each undo record takes about 1 kilobyte, that is enough to hit the
> default undo limit.  It might be that each undo record takes more space
> in Emacs 23 than in Emacs 21, which is why you don't see the problem in
> Emacs 21 (there are several reasons why this could happen, which could
> be investigated).
>
> I do observe the same behavior that you reported, using the key sequence
> you supplied; furthermore, if I increase undo-limit to a larger number,
> I find that Emacs can undo all the way back to the buffer's original
> state.

Chong Yidong <[email-masked]> writes:

> I've expanded the undo limits by a factor of four.  A more sophisticated
> fix, if one exists, will have to wait till after the release.

The undo limits were recently again doubled on master in commit
9466372 in relation to Bug#31104.  The latter change will be included
in the next major version of Emacs (version 27.1).

If you're still seeing this problem on a recent version of Emacs, a
workaround is to increase the values of the variables undo-limit,
undo-outer-limit and undo-strong-limit.  You could add something like
the following to your init file:

(setq undo-limit        (* 2 undo-limit))
(setq undo-outer-limit  (* 2 undo-outer-limit))
(setq undo-strong-limit (* 2 undo-strong-limit))

Of course, you could use a bigger number than 2 should that be necessary.

Given the discussion in Bug#31104, I'm not sure there's more to do
here.  But the discussion here also suggests that there have been an
increase in the memory usage of each undo record, especially when
using font-lock-mode.  I'm not sure that is a serious problem, since
memory is only getting cheaper, but it might be worth investigating.
On the other hand, we could just decide that this is not worth the
effort and close this as wontfix.

Thanks,
Stefan Kangas