>> - (delete-and-extract-region (point) (point-max))))))) >> + (undo-boundary) > >> + (setq buffer-undo-list >> + (seq-drop-while 'identity buffer-undo-list))))))) > > This looks fragile and can be disasterous when buffer-undo-list is > large. I agree that it is very fragile, but could you explain why is it also problematic with a large `buffer-undo-list'? I guess you mean efficiency-wise, but it would only iterate through the few items added since the call to (undo-boundary). Is there something else I'm not seeing? > Maybe just use with-silent-modifications or some ideas from there (for > example, wrapping modifications inside let-bound (buffer-undo-list t))? > We should not inhibit modification hooks though. Otherwise, it will mess > up with caching code. Done. I attach the new patch: