Subject: Re: bug#64989: 29.1; Comment or uncomment lines in elisp-mode will show message in minibuffer

From: Stefan Monnier <[email-masked]>
Date: Sat, 26 Aug 2023 11:09:21 -0400

>> When update to the new released Emacs 29.1, I found that when comment or
>> uncomment lines in emacs-lisp-mode will show message in minibuffer as
>> below:
>> ```
>> combine-change-calls: buffer-undo-list broken
>> ```
>> Steps to reproduce:
>> 1. create a test.el file with any Elisp code. such as:
>> ```
>> (message "Test")
>> ```
>> 2. start emacs and open the test.el file with `emacs -Q ~/test.el`
>> 3. Use C-x C-; (comment-line) to comment the code in test.el
>> 4. Now you will see the message mentioned above.
>
> Thanks.
>
> Stefan, I think this is due to the commit below:

Yup.  The message is just wrong in this case: (cdr ptr) is nil simply
because `buffer-undo-list` was nil initially, not because the
`buffer-undo-list` has been shortened by the GC.

> If indeed this is the culprit, can we perhaps backport the "better
> fix" from master to the emacs-29 branch?

That would work as well.  The patch below should do the trick, tho, if
you prefer to keep changes to a minimum.

        Stefan

diff --git a/lisp/subr.el b/lisp/subr.el
index 28473f1d38c..ec30637b526 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -5002,7 +5002,7 @@ combine-change-calls-1
 			;; Don't include a timestamp entry.
 			(setcdr ptr (cddr ptr))
 		      (setq ptr (cdr ptr))))
-		  (unless (cdr ptr)
+		  (unless (or (cdr ptr) (null old-bul))
 		    (message "combine-change-calls: buffer-undo-list broken"))
 		  (setcdr ptr nil)
 		  (push ap-elt buffer-undo-list)