phillip.lord@russet.org.uk (Phillip Lord) writes: > Chong Yidong writes: > >>> The attached patch, which gets rid of the undo boundary, seems to fix >>> this: >> >> Actually, the previous patch does not DTRT: if you switch back to the >> original buffer from the minibuffer, and make further editing changes, >> those changes would get lost because buffer-undo-list is temporarily >> rebound. >> >> Here is a different patch, which works by removing the undo boundary in >> buffer-undo-list if there's one. It also tweaks HTML mode and Texinfo >> mode, which have similar issues. It defines a new function >> `undo-amalgamate', split off from `undo-auto-amalgamate', for >> convenience. > > > In and off itself, the patch seems fine, but my concern is that that the > previous heuristic did the right thing, the new heuristic does not. If > you've found three instances where it's causing a problem, then there > will be others also. > > I'm not 100% sure why the old system didn't insert an undo-boundary. > But, if we could solve this entirely in the undo system without changes > to client code that would be nicer. > > Not sure how yet -- need a few days to think about it. Perhaps, > suppressing the auto-boundary functionality when only the mini-buffer > has changed. I've debugged this now. The problem, I think, is that latex-insert-block uses recursive editing (via `completing-read', then `read-from-minibuffer') -- so the minibuffer is edited, then the exit-minibuffer command runs, causing an undo boundary to be added to minibuffer (correctly) but also to the latex buffer because it has also changed. The patch below seems to fix -- I need to test it out tomorrow in case it has any other unexpected effects. What worries me is that it just deals with the minibuffer. I wonder whether there are other circumstances where a recursive edit is going to break things. Stefan, would welcome your opinion here. Incidentally, this is a nightmare to debug. Emacs needs to be able to write to standard out, so I could log without changing any buffers!