apheleia icon indicating copy to clipboard operation
apheleia copied to clipboard

Seems to wreck undo history

Open raxod502 opened this issue 5 years ago • 4 comments

When a lot of formatting is going on I seem to lose the ability to undo back very far. This is extremely bad for UX. Probably a consequence of undo-limit and the reformatting generating large volumes of undo data (not sure why).

raxod502 avatar May 08 '20 03:05 raxod502

Taking a page out of evil's evil-with-single-undo macro, how about wrapping apheleia--apply-rcs-patch in something like this?

(unwind-protect
    (progn
      (when (car-safe buffer-undo-list)
        (undo-boundary))
      (let (buffer-undo-list)
        ...))
  (when (car-safe buffer-undo-list)
    (undo-boundary)))

hlissner avatar May 21 '20 18:05 hlissner

Thanks for the great tip! I pushed a commit that incorporates this and some related code, we'll see if it seems to have fixed the problem I guess :)

raxod502 avatar May 25 '20 16:05 raxod502

I must have done something wrong with the implementation, since this change made it impossible to undo reformatting operations.

raxod502 avatar May 26 '20 20:05 raxod502

I recently created a little major mode where I wanted to ensure some modifications were registered as a single undo, perhaps it could help here?

(let ((marker (prepare-change-group)))
  (unwind-protect
      (save-excursion
        ...) ;; Do all sorts of stuff)
    (undo-amalgamate-change-group marker)))

Edit: I see that #17 seems to have looked at this approach, but perhaps it's worth revisiting now that Emacs 26 is the minimum? Even though it doesn't alleviate the "large undo entry" problem, it seems like making sure the formatting is recorded as a single undo step this way could be worthwhile.

tecosaur avatar Feb 22 '23 09:02 tecosaur