How to write .emacs from Emacs when I removed .emacs

I have Emacs open, but I accidentally deleted the .emacs file that it read when it started. It is about 15 years old. (I know, I know, backups.)

Is there a way to get Emacs to write the .emacs file that I deleted?

I would usually not ask such a lame question about SO, but I know that I only have a day or so before the Emacs session ends.

+6
source share
4 answers

As ayckoster suggests, you can try a file recovery or forensic tool like The Sleuth Kit . Or, and it might seem crazy if you are using a Unix-like system, you can search through an unprocessed disk device (on the Mac I am currently working on, it will be / dev / rdisk 1). Seriously, several times I was too lazy to pry out a full-blown recovery tool, but instead used something like sudo less -f /dev/rdisk1 , looked for a line that I knew was in a file ( global-set-key , who anything?) And succeeded in restoring the original contents of the file.

+5
source

If you have Emacs backup enabled, you should have a copy of your next .emacs file in ~ / .emacs ~. If so, just rename it to ".emacs" and you will have a .emacs file with all but your latest changes. Even if you do not have backups, you can still have a substantial portion of your .emacs file in the last backup of the file. You should also look at the value of the variable "backup-directory-alist" - it determines the location (s) for the backup files that will be saved if the default value (the same directory as the modified file) is not used.

Otherwise, how good is your memory ...; -)

EDIT: since you do not have a backup of your .emacs file, but you have a running instance of Emacs that was running with this .emacs file, another thing you can do is save all user settings that would be specific in the .emacs file. To do this, do something like:

 (setq custom-file "/my/home/directory/.emacs-custom.el") (custom-save-all) 

Then you can create a new .emacs file and add the following lines to it:

 (setq custom-file "/my/home/directory/.emacs-custom.el") (load custom-file) 

This will at least restore some of the custom variable parameters that were in your .emacs file.

+5
source

Emacs evaluates your .emacs file and then closes. So basically you cannot return your .emacs.

The solution might be to use a file recovery application. The chances of your .emacs on your hard drive are good.

Since most of these programs cannot display the file name or directory name of the remote file, you need to know the contents of your .emacs.

Then you can recover all files that are currently deleted in a certain folder and recursively search the contents of your .emacs.

This process can take a very long time. You must decide if you should do this.

+1
source

I don’t know how to get Emacs to provide the source .emacs file, but you can of course poll the loaded functions and variable characters and get their values.

It would be quite a lot of work, but I think that in theory you should be able to get a good chunk of this data in one form or another, if you can filter everything out before you know how yours is.

For evaluated functions (symbol-function 'SYMBOL) will return a (less readable) definition of the supplied function. Then you can use (fset 'SYMBOL VALUE) , where VALUE is the result of calling symbol-function to define this function in a new .emacs file. This will give you an approach to recovering certain functions.

You can also see: How to print all defined variables in emacs?

This is a very incomplete starter, but given the time limitations, I publish and flag it to the community wiki if someone wants to run with it.

A practical guide to resetting an application with a reliable recovery method would be a great start if the current session is definitely killed (or even if it does not protect against failures or other failures at all).

You could re-tag it with some more general tags such as data recovery to expand your audience.

+1
source

Source: https://habr.com/ru/post/896259/


All Articles