reddit / emacs
Redo / undo ... again (drives me crazy)
ThalaMuax · 2022-11-18 10:49
I have a question about the undo and redo workflow (mostly org-roam). Undo often deletes a lot of changes for me. There doesn't seem to be any caching of steps between escaping.
Example:
1. Write code and an explanation below.
2. I mark the code to copy it, but when I hit "y" there is only this little y where the code once was. Forgot to escape.
3. When I now use undo, the whole text resets to an almost ancient state, sometimes from 10-30 minutes ago.
4. So I have to redo-undo.
5. Now I'm still stuck with the y instead of the code and I have two options:
1. Type all again from the ancient state.
2. Type the code again, I accidentally deleted by pressing y without escaping first.
Is there any way I can prevent this time-consuming mess? It can't be that everyone who works with Emacs constantly loses text / code and hours of work. So the fault must be on my side.
I read through the undo chapter of Emacs and a few threads here in Emacs on reddit. ([https://www.gnu.org/software/emacs/manual/html\_node/emacs/Undo.html](https://www.gnu.org/software/emacs/manual/html_node/emacs/Undo.html)). But I can't really make sense of it.
How do you prevent this from happening? What is your workflow for undo and redo?
I am very grateful for any help.
404cn · 2022-11-18 11:14
Try vundo
ThalaMuax · 2022-11-18 11:34
I tried. Vundo shows me what I already know. If I do a step to the "left" the ancient version is there. Nothing in between.
bhrgunatha · 2022-11-18 11:35
The other alternative is undo-tree, which seems to be the most common recommendation, but I prefer vundo because it doesn't clutter my file system with hidden `.<filename>~undo-tree~` files.
ThalaMuax · 2022-11-18 11:50
I'll try that right away. Thank you both.
11fdriver · 2022-11-18 12:08
Perhaps I'm mistaken, but is this overaggressive undo-amalgamation?
There are ways you can advise how undo steps get grouped together that might split this up, but for testing (or if you don't like the amalgamation behaviour outright), try:
(fset 'undo-auto-amalgamate 'ignore)
Ed: Perhaps another way is to tackle this at the source and try disabling `delete-selection-mode`. A feature lost, but maybe it will save your sanity.
Ghosty141 · 2022-11-18 12:31
You can just set some variables and it puts them under one directory.
bhrgunatha · 2022-11-18 12:49
OK thanks. I might re-asses then. I seem to remember it had more features.
sledgespread · 2022-11-18 13:08
I don't know what's going on, but I can confirm that undo-ing to the state from 10 minutes ago is definitely not the normal behavior. For me undo is about as granular in Emacs as in any other application.
If it only happens in org-roam then maybe it's a bug in that package?
olikn · 2022-11-18 14:00
I assume you are using evil, because you wrote you hit "y".
I have the following variable set and it works like you want:
evil-want-fine-undo t
evil-undo-system 'undo-redo
ThalaMuax · 2022-11-18 14:38
>I assume you are using evil, because you wrote you hit "y".
Problem solved. Thank you so much!
MangyCanine · 2022-11-18 14:38
Give undo-tree a try. I think it’s a billion times better than the default emacs undo.
I’ve forgotten the default but, if your file system gets littered with .*-undo-tree- files, you can either turn off persistent undo or enable the option the puts those files into a single directory.
ThalaMuax · 2022-11-18 14:40
>There are ways you can advise how undo steps get grouped together that might split this up, but for testing (or if you don't like the amalgamation behaviour outright), try:
I found some additional clues about this and tried the following. It did not work.
`(defun undo-auto-amalgamate ()`
`(let ((last-amalgamating-count`
`(undo-auto--last-boundary-amalgamating-number)))`
`(setq undo-auto--this-command-amalgamating t)`
`(when`
`last-amalgamating-count`
`(if`
`(and`
`(< last-amalgamating-count 20)`
`(eq this-command last-command))`
`;; Amalgamate all buffers that have changed.`
`(dolist (b (cdr undo-auto--last-boundary-cause))`
`(when (buffer-live-p b)`
`(with-current-buffer`
`b`
`(when`
`(and (listp buffer-undo-list)`
`(not (car buffer-undo-list)))`
`(setq buffer-undo-list`
`(cdr buffer-undo-list))))))`
`(setq undo-auto--last-boundary-cause 0))))`
`nil)`
11fdriver · 2022-11-18 14:56
How strange!
If you start `emacs -Q` and re-enact some of your steps, do you get similar behaviour?
Never mind, just saw that it was Evil handling things it's own way, glad you got it solved ;)
reddit_clone · 2022-11-18 16:52
Amazingly I had the same 'y' replacing a whole lot of text and I went through the same confusion as you just two days ago.
tdavey · 2022-11-18 19:00
Those files are indeed annoying. Fix it with (setq undo-tree-auto-save-history nil)