reddit / emacs

Help! How can I recover my essay?

lord4ris · 2022-05-20 17:35
I was writing an essay on Doom-emacs, and by accident I deleted a part of it (I was trying to copy a section of it, but it was on insert mode), so I pressed U to undo, but it doesn't worked. I tried a lot of key commands like U, C-r, C-\_, C-/, C-x u, C-?, M-x undo-only, and still can't recover the part I deleted. At this time, I think it'll be easier to start again.
[deleted] · 2022-05-20 17:44
[deleted]
lord4ris · 2022-05-20 17:50
It didn't work. There's a lot of blocks from other buffers but not the one I'm using.
[deleted] · 2022-05-20 17:50
[deleted]
lord4ris · 2022-05-20 17:52
>U, C-r, C-\_, C-/, C-x u, C-?, M-x undo-only That's what I tried so far
[deleted] · 2022-05-20 17:54
[deleted]
BunnyLushington · 2022-05-20 17:55
No autosave (`#filename#`) file?
samsjj · 2022-05-20 20:14
Try undo-fu. It’s more easier [https://github.com/emacsmirror/undo-fu](https://github.com/emacsmirror/undo-fu)
organic-bookworm · 2022-05-21 07:56
Also, Doom by default has `global-undo-fu-session-mode` enabled, which persists an undo history before saving a buffer. So, chances are your undo history is still there even after restaring Emacs. Open your file and try `evil-undo` ("u" in normal state) multiple times. Or, if you still had that buffer open (yep), you could have reverted it (`revert-buffer`) to load old version from disk, copy things, then `evil-undo` to previous state.
thetemp_ · 2022-05-21 14:48
So it is probably too late at this point to be helpful, and I think Doom uses undo-fu by default anyway (though it's possible you might have turned that off). But in case you are using Emacs's default undo setup, be advised that it works differently from undo in most other programs. In Emacs, undo is itself an undoable action. And every time you interrupt a series of undo commands, your position in the undo-ring moves back in front of all those undo commands you just executed. What this means is that every time you try to undo something but interrupt the series of undos before reaching the thing you want to undo... you get even further away from it. At this point, you've probably already given up. But if not, find out which key is bound to `undo`. Make sure it isn't `undo-only`, as that one will stop at the undo commands and never reach the earlier state that you want. Then just hold down the `undo` key until you get past where you want to be. Be absolutely sure you are at or further back than you want to be. Now, interrupt the undo sequence (using "C-g" for example), and start undoing again. You'll be moving forward from an earlier point, instead of backwards from thirty miles away (and giving up before you get there). I hope that makes sense. The whole thing is rather convoluted, but it works well when you understand what it's doing.
lord4ris · 2022-05-21 20:40
It is too late, LOL. But thank you so much for your help anyways (no sarcasm intended). I recreated what I did, that was writing over selected text in insert mode, and again, I couldn't undo to the point where there was that text, even using undo-fu.
Kaligule · 2022-05-23 03:48
I can't help you on your problem, sorry. I am just here to suggest using version control on your texts next time. It is commonly associated with code, but works amazingly well for text, too. Everything I write that is more then 30 lines I put into a repo these days.