Table of Contents
Part of Living with Emacs
1. what to do when Emacs hangs
When Emacs hangs or freezes, usually it means that Emacs is stuck in a loop, and you should press
C-g to get out. If
C-g doesn’t do anything and your Emacs is still frozen, it is likely that you ran a command that synchronously called an external program which for some reason is not finishing its job. In that case, you can get out of the freeze by simply killing that external process. On MS Windows, you can do that from Task Manager. What if you don’t know which external process to kill? In that case, it’s time for the last resort: kill Emacs. By killing the Emacs process, would your unsaved work be gone? Not necessarily. We’ll come to that later.
On MS Windows, Emacs may hang when you try to use commands that rely on external tools like grep, find, ftp, diff, or latex if you have not done the job of installing related tools and configuring relevant user options.
Here’s some code for practice. Evaluate that and Emacs will hang.
(while t (print "haha"))
You can then press
C-g to get out.
This one is for MS Windows only. Evaluate that and Emacs will hang again.
Pretend that you don’t see that notepad window. Open Task Manager and the process to kill is
If you want to debug and find out what is causing Emacs to hang, use the command
If you want to debug a command that causes Emacs to hang where
C-g doesn’t work, use
M-x debug-on-entry RET call-process RET
3. what to do when Emacs crashes
If Emacs crashes often, you must be using an old version of Emacs or a very old laptop.
You were writing a PhD thesis with Emacs for hours and you never saved the file and then suddenly Emacs crashed. How to restore your unsaved work then? You just start Emacs and type
M-x recover-session and you will see a special dired buffer. That buffer has the instruction “Move to the session you want to recover, then type C-c C-c to select it.”. So you press
p to move to the item with the most recent timestamp and then press
C-c C-c. What happens then is Emacs visits the thesis file, extracts your unsaved work from autosave data, and writes that into the buffer visiting the thesis file. You can now continue to work on your thesis but before continuing, this is probably a good time to save the file.
Who writes a PhD thesis with Emacs and not a word processor? Some users of org-mode and/or AUCTeX. This video http://www.youtube.com/watch?v=lsYdK0C2RvQ demonstrates producing a PDF file with code snippets in it using Emacs. That is going to come in handy when you write your papers.
Do some work with Emacs, don’t save anything, take a break, peel an apple with a peeler, cut it down with a knife, wash your knife, do the sharpening rod thing, eat your apple, now autosave has probably kicked in, manually crash your Emacs by killing the Emacs process from Task Manager, see if you can restore your unsaved work.