If you remember a post I wrote a while back, I had made a mode save-visited-files that was a lightweight replacement for desktop.el. It saves the files you have opened, reloading these whenever you start emacs. Ryan Thompson spent some time improving save-visited-files, so I thought I’d release his improvements. save-visited-files.el can be downloaded from here.
Save-visited-files now uses auto-save-hook instead of a periodic timer. This is probably the better decision, but it means you don’t want it to trigger too often. In order to reduce the number of auto-saves, you can use the following, which will auto-save every 3000 input events:
(setq auto-save-interval 3000)
The functions and variables in save-visited-files are also named more consistently, with each one being prefixed with save-visited-files. The mode can now also be customized with M-x customize-group save-visited files. As a final improvement, the handling of the temporary buffer is handled much more nicely, so that the user is never presented with it.
To use the new save-visited-files, just put the following in your .emacs file:
(require 'save-visited-files) (turn-on-save-visited-files-mode)
Tags: emacs, save-visited-files
I’ve found one annoying problem that I can’t think of how to solve. If I use tramp to open a file that requires a password, then I quit and restart emacs, there’s no way for emacs to prompt me for a password on startup, becase I used emas –daemon. So if I have any password-requiring files in the save-visited-files cache, I have to manually remove them before starting emancs by editing the file. Maybe I should add the save-visited-files restore function to make-frame-hook or something, or at least filter out the tramp entries and hold them until make-frame-hook.
Hi,
I just wanted to say how awesome your blog is. I’ve been trailing it through planet emacs for a while now and I like your writing style, the depth to which you’re covering subjects and the simple utility of your tips.
Please keep up the good work!
Robert
What does it offer over recentf-mode ?
I keep getting asked if I want to kill emacs-opened-files, at seemingly random intervals.
…
save-visited-files doesn’t do the same thing as recentf. Recentf lets you re-open files that you had open recently. Save-visited-files mode makes emacs automatically, at start-up, re-open every file that was open last time emacs exited (or died, or you rebooted, or whatever). It’s the simplest possible implementation of a “workspace”-type feature for emacs. There’s a single workspace, and every file is in it.
So, to summarize, it’s a continuity feature, to make it so that when you close and re-open emacs, you can more quickly get back to where you left off.
By the way, I found a useful improvement: file-precious-flag, which makes emacs take extra steps not to leave you with a half-modified file when saving. To enable it for save-visited-files, insert it into the save function like this:
(defun save-visited-files-save (&optional location)
“Save the list of currently visited files”
;(interactive)
(save-window-excursion
(setq location (or location save-visited-files-location))
(switch-to-buffer “*Save Visited*”)
(ignore-errors
(erase-buffer)
(mapcar ‘(lambda (x) (insert x “\n”))
(remove-if ‘(lambda (x)
(or (string-equal location x)
(eq nil x))) (mapcar ‘buffer-file-name (buffer-list))))
(let ((file-precious-flag t))
(write-file location nil))
(kill-buffer (get-buffer “*Save Visited*”))))
hmm.
This doesn’t seem to work for me any more.
it doesn’t restore my visited files, and keeps randomly asking me if I want to kill emacs-opened-files, sometimes emacs-opened-files buffers keep propagating.
emacs-opened-files etc.
I’m on a weekly snapshot of CVS emacs, and I use a number of other packages, too. Might be an interaction of those things, but the old version, while wonky at times, worked.
there should be a number in greater-than/less-than signs after that last emacs-opened-files.
ah, mkdir .emacs/persistence
Ok, I can confirm that even with that directory in existence that this no longer works for me.
TheGZeus:Hmm, that’s odd…It’s been mostly working for me so far. I do sometimes have the replication problem, which is caused when you attempt to C-g out of a save-visited-files-save - It will open a new buffer emacs-opened-files buffer and then keep going. I’m not sure why it doesn’t work at all for you - are you using the new loading sequence?
I installed this and set it up, and then I got these dialog boxes asking me if I wanted to kill the “*Saved Visited*” buffer. It turned out that it was erroring when the directory ~/.emacs/persistent/ didn’t exist. You should make sure you can write to the file before you do (file-writable-p). You can try to create the directory with something like this:
(let ((dir (directory-file-name
(file-name-directory
(expand-file-name
(directory-file-name save-visited-files-location))))))
(if (not (file-exists-p dir))
(make-directory dir)))
No, I don’t know why directory-file-name should be there twice. I stole that from uniquify.el.
BTW, the line that was giving me trouble is
(kill-buffer (get-buffer “*Save Visited*”))
Anyway, it seems to be working as advertised; nice package.