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.
Tags: emacs
I’m getting Debugger entered–Lisp error: (void-variable save-visited-files)
when I try run (save-visited-files-mode 1)
Also, compiling gives me warnings about certain things being meant for interactive use.
Wow, looks like I checked in an old version of the file - to fix those errors, just change the references from save-visited-files to save-visited-files-timer and I’ll update asap.
I’m experiencing what I call ‘refrigerator-blindness’; which is where one can’t see what’s right in front of them.
It’s generally experienced when looking at someone else’s fridge,
Could you tell me the line(s) I need to change?
The correct function should be:
that gives me (void-variable save-visited-files-timer)
feel free to mail me if that’s more convenient.
I use mail from that gugol company as gzeusmants.
The correct file should be located here now, just download it.
awesome
ISTR you need to call (desktop-save) or something manually once to get it started, or something like that.
Instead of using a 60-second timer, why don’t you just add a hook to auto-save-hook?
I’m actually implementing my suggestion, and a bunch of other improvements. I’ll send you the final product when I finish.
[...] opened, the next time I open emacs on that computer the buffers should re-open, much like how save-visisted-files opens all the files that were opened previously. I also allow w3m to use cookies so I can log into [...]
I’ve pretty much finished my revamp of save-visited-files mode. Would you like me to send it to you, and if so, where?
Yeah, that would be great! Send it to me at nflath@nflath.com
[...] almost every file is in directory customizations/1/: the only one that is in customizations/2 is state.el, which will open all previously visited files. I want this to happen after my hooks have been added [...]
[...] A few people including me have been using it since then; I’ve written about it before here and here. A few weeks ago, Jonathan Kotta emailed me a patch that fixed a few minor issues, as well [...]