samkdt · 2022-05-28 10:45
I accidentally deleted my init.el but i have a running instance of emacs that has loaded my configs.
I was wondering if there is a way to get my init.el back from the emacs that is still runnuing.
BettaGeorge · 2022-05-28 11:01
Is there no autosave of the file? Look for something ending with ~. It may be hidden in some graphical file managers.
7890yuiop · 2022-05-28 11:13
Only if you'd opened your init file in a buffer, in which case you could simply re-save it.
You *should* have a backup file, though. E.g. `~/.emacs.d/init.el~` if your init file was `~/.emacs.d/init.el` (and if you haven't customized the backup options to save backup files elsewhere). Read `C-h i g (emacs)Backup` for all the details. If you create a new (empty) init file (being sure to *actually* write a file) and run `M-x diff-backup` from that buffer you would hopefully get a diff against the most recent backup; and `M-: (make-backup-file-name (buffer-file-name))` ought to tell you which directory the backup file is being written to, if you're not sure.
The closest you can get to what you've asked is to get Emacs to write all of your *customized* user options and faces, based on the running session. If you had set `custom-file` to a non-nil value then this won't help you (unless you'd deleted that as well), but if your custom values were written directly to your init file, then you could at least restore those.
`M-x customize-save-customized` would do this.
Finally, make this a learning experience and reason to put your Emacs config under version control.
PaulRudin · 2022-05-28 12:20
Yeah - VC is the way forward, see [https://www.atlassian.com/git/tutorials/dotfiles](https://www.atlassian.com/git/tutorials/dotfiles), for a good approach to keeping all kinds of config (including your emacs config) in git.
mtk000 · 2022-05-28 12:41
there is a program called 'gcore' (at least on fedora) that will capture the virtual memory image of a running process and store it in a file. if you run it on your emacs process, you can search this file for your init (or fragments of your init). not guaranteed to yield anything useful but it has worked in the past.
organic-bookworm · 2022-05-28 13:47
Not related to Emacs per se, but you've got a high chance of recovering a recently deleted file using e.g. [PhotoRec](https://www.cgsecurity.org/wiki/PhotoRec).
eras · 2022-05-28 14:36
Well, there are good suggestions elsewhee in the thread, so this will be..
_Preaching time!_ You should back up all your files (all minus excluded ones is my preference). `init.el~` is probably one of the least important files you have so this should serve as a good warning. Note that synchronization is not backup (and wouldn't have helped in this case: it would have just synchronized the deletion). In addition to restoring accidentally removed files I've also restored stuff like corrupted browser state. It's nice.
Good backup apps: my favorite is [`kopia`](https://kopia.io/) and if you don't have a requirement of dedupping among different hosts, [`borgbackup`](https://www.borgbackup.org/) is a good one too. Both do end-to-end encryption meaning that you can store the data in the cloud and others won't be able to read the contents. Of course, you need to keep your encryption password safe.
**Set it up today!** Bonus points for putting those backups outside the disaster zone, e.g. your home.
grewil · 2022-05-28 20:24
I secretly wish I deleted mine - it’s some two decades old in parts, hundreds of lines and makes Emacs semi broken.
paretoOptimalDev · 2022-05-28 20:41
Try starting a new config from scratch and implementing things as needed. You might change your mind when you realize how much value you've accreted like I did.
Adventurous-Can4429 · 2022-05-29 02:59
But save it somewhere, maybe [archive.org](https://archive.org) ;)
ckoneru · 2022-05-29 04:41
Try recuva, it can resurrect deleted files in windows. There should be similar solutions out there for Linux and macOS.