Emacs has quite a bit of protection against the loss of work. When you make enough changes to a document and save it, emacs automatically creates a backup file containing the original document. The name of the backup file is constructed by appending a tilde ~ to the name of the original file. With our default settings, only the most recent previous version of the file is kept.
When you start editing a file, emacs opens an ``autosave'' file that tracks your changes pretty much as you work. The name of this file is constructed by putting a hash symbol # before and after the name of the original file. If you do a directory listing while you are in the midst of editing a file, you will see the autosave file. When you save your edits, the autosave file becomes the new version, the old version is renamed, and the autosave file disappears from the directory listing.
The autosave file protects you against losing your work from a crash. If something kills your emacs process before you have a chance to save your work, the autosave file will have almost all of it.
So how do you recover your work? Start by opening the file according to its original name. In the command minibuffer, you will see a message telling you that the autosave file is more recent and suggesting you run the command M-x recover-file. So do it. You will get a dialog box containing the long directory listing of your original file and the autosave file and asking if you really want to recover from the autosave file. Type ``yes''. The buffer will then open with the contents of the autosave file, and you are back almost where you were before the crash. When you save your session, it will become the new version of your file.