I just want to erase history here - the very last entry. This shouldn't be dangerous, right?

I figured I need to somehow transform (undo-tree-current buffer-undo-tree) and pass that to undo-tree-snip-node but I don't see exactly how to do that.

  • Do you want to undo your last entry and return to your previous state and then erase that last entry; or, do you want to keep your current state and tell undo-tree to just forget about how you got there? Inasmuch as undo-tree just creates a new branch when you undo and then go somewhere else, why (if you don't mind explaining) would you want to erase the last entry (e.g., a use case example)?
    – lawlist
    Commented Jun 8, 2020 at 17:49
  • @lawlist I just want to forget how I got to that state. I am making an evil motion for paredit-kill. The way I do it is do the kill, then paste the killed text where it was, pop the kill ring, save the (point) for use as a motion. For simplicity, I set a handle to (prepare-change-group) before these and do (undo-amalgamate-change-group handle) afterwards so that I have just one unnecessary undo event. I tried to use undo-tree-undo, but that doesn't play well with evil - it cancels the operator which was pressed before the motion (like d). Commented Jun 8, 2020 at 18:24
  • 1
    Other than Dr. Cubitt (the author of undo-tree.el), a regular forum participant named Tobias is probably the most familiar with the data structure of the buffer-undo-tree of the undo-tree.el library. One idea would be to save a copy of the list using copy-tree* (in the following link) before doing your stuff and then restore the list when you finish: emacs.stackexchange.com/a/32230/2287 Off hand, I do not know how to just snip off the last entry -- but, perhaps Tobias or another forum participant does ... or they can suggest an alternative approach that best suits your needs.
    – lawlist
    Commented Jun 9, 2020 at 4:23
  • @lawlist Oh, man. I think I will just rewrite the paredit-kill instead, looks like less trouble after all. But thanks for the directions and the link! Commented Jun 9, 2020 at 9:51


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.