Jisang Yoo has a very nice post on recovering from Emacs hangs or crashes. He considers three topics
- What do do when Emacs hangs
- How to enable debugging
- What to do when Emacs crashes
His advice on Emacs hanging seems mostly aimed at Windows users and doesn’t mention my preferred method of
pkill -SIGUSR2 Emacs
That will usually unstick Emacs enough that you can save your files and quit. Sometimes you can even keep going but I’ve found it’s generally better to save your files and restart Emacs. If you aren’t on a Mac, you will want to use
pkill -SIGUSR2 emacs
instead.
The problem with a crash is that you can lose unsaved work. What I’ve always done in that case is to use recover-file
to get the file from disk and fold in the information in the autosave file. Yoo suggests using recover-session
instead. This has the advantage of recovering all files from the session that crashed. That’s something I didn’t know but that I’ll use from now on.
Yoo’s post is fairly short and one well worth reading. Knowing the things he talks about doesn’t make crashes/hangs painless but it does take a lot of the sting out of them.