Subject: Re: bug#23632: 25.1.50; Gratuitous undo boundary in latex-insert-block

From: [email-masked] (Phillip Lord)
Date: Mon, 06 Jun 2016 15:33:12 +0100

Stefan Monnier <[email-masked]> writes:

>> I guess "recursive-edit" is the only way to enter a recursive edit?
>
> AFAICT, `recursive_edit_1' is the C function that's used by both
> `recursive-edit' and `read-from-minibuffer', so it should catch all cases.

So, tried it, and AFAICT, you are correct. The attached patch seems to
fix. And it is significantly simpler than the last fix.

It currently does not deal with the case where there "left over" after a
command which changes a recursive edit level. The lists of buffers in
undo-auto-undoably-changed-buffer will be lost as we come out of the
specbind.

I do not know whether this is a problem or not. Potential solutions:

1) before we exit recursive_edit_1, append the value of
undo-auto-undoably-changed-buffer on a new variable
("undoably-changed-buffer-recursive"). Then, when undo-auto-boundary
runs append and nil this. Seems like a lot of effort for an occasional
issue.

2) Call undo-auto--add-boundary before exiting recursive_edit_1. This
should nil undoably-changed-buffer and add boundaries.

3) Just not worry about it.

Assuming we go for 3, is everyone happy to patch the Emacs-25 branch?

Phil

>From 92ec383f9c732af76f6ba18c87a6989a4b6f16e8 Mon Sep 17 00:00:00 2001
From: Phillip Lord <[email-masked]>
Date: Mon, 6 Jun 2016 09:35:17 +0100
Subject: [PATCH] Fix regression for recursive editing in undo

---
 src/keyboard.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/keyboard.c b/src/keyboard.c
index e3858a5..b5b603c 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -679,6 +679,8 @@ recursive_edit_1 (void)
      recursive edit, the original redisplay leading to the recursive
      edit will be unwound.  The outcome should therefore be safe.  */
   specbind (Qinhibit_redisplay, Qnil);
+
+  specbind (Qundo_auto__undoably_changed_buffers, Qnil);
   redisplaying_p = 0;
 
   val = command_loop ();
@@ -689,6 +691,7 @@ recursive_edit_1 (void)
   if (STRINGP (val))
     xsignal1 (Qerror, val);
 
+
   return unbind_to (count, Qnil);
 }
 
@@ -10956,6 +10959,8 @@ syms_of_keyboard (void)
   DEFSYM (Qpost_command_hook, "post-command-hook");
 
   DEFSYM (Qundo_auto__add_boundary, "undo-auto--add-boundary");
+  DEFSYM (Qundo_auto__undoably_changed_buffers,
+          "undo-auto--undoably-changed-buffers");
 
   DEFSYM (Qdeferred_action_function, "deferred-action-function");
   DEFSYM (Qdelayed_warnings_hook, "delayed-warnings-hook");
-- 
2.8.3