Having persistent emacs sessions - where your data remains when you load up emacs - is supposed to be handled by desktop.el, a library that comes with emacs. However, I’ve never actually gotten it to work - I’m not sure why, the installation seems fairly easy. It’s just never loaded my state properly. But since I like some of my settings persisting across sessions, I use several other, more specific modes that come with Emacs, and a mode I wrote to save and load currently-opened files.
Saveplace is a built-in emacs package for saving your location in files. If you have a file open in emacs and then close it, with saveplace enabled the file will be opened with point at it’s last location. This is often what I want - just to pick up where I left off - so of course I enabled it.
save-place-file "~/.emacs.d/.saveplace") (setq-default save-place t) (require 'saveplace)
Another similar mode is savehist, which will save your minibuffer history across sessions. I don’t actually use the minibuffer history very much, but it does occasionally help so I just save it across sessions.
(setq savehist-file "~/.emacs.d/.savehist") (savehist-mode 1)
The other mode I wrote, save-visited-files.el, is available here. It is a lightweight replacement to the part of desktop that persists files across sessions. At the moment, it is very simple, though if you want any features added or have any bug reports feel free to contact me. It have three functions: save-visited-files, open-visited-files, and save-visited-files-mode. save-visited-files will just save a list of all the files you have opened. open-visited-files will open every file in this list. save-visited-files-mode will set up a timer that runs every 60 seconds by default and saves what files you have opened(unless you are currently in the minibuffer).
There are currently only two configuration options: save-visited-files-location, which will change what file to use to save and load file lists, and save-visited-files-interval, which controls how often the list of visited files are saved. To enable this mode and load your previous opened files, add the following to your initialization file:
(require 'save-visited-files) (open-visited-files) (save-visited-files-mode 1)
This is actually the second revision of this mode; In the first, instead of using a timer, I advised kill-buffer-hook and find-file-hook to maintain completely up-to-date file lists, instead of just saving every 60 seconds. This had some problems, however. It had to ensure that the file it was opening/closing wasn’t from another instance of save-visited-files. There were performance issues when the entire list was written whenever a buffer was killed, since it turns out temporary background buffers are always popping up, and attempting to just delete the specific line started getting complicated, so I decided saving every 60 seconds was good enough.