I tend not to delete buffers in emacs, so over time, the number of buffers tends to grow to a hundred or more. (At the moment, *Buffer List*
has 144 lines.)
Many of these files are java files, and with my configuration, loading a Java file takes a second or two. This means that starting emacs can take a few minutes.
Is there a way to limit the number of buffers that are saved by the desktop? Ideally, I would like to drop buffers that I have not visited in a while.
I tried this:
(advice-add 'no-save-unseen-buffers :before-while 'desktop-save-buffer-p
(lambda (buffer &optional rest)
(let ((last-time (with-current-buffer buffer buffer-display-time)))
(when (and last-time
(< (time-to-seconds (time-subtract (current-time) last-time))
(* 2 7 24 60 60)))))))
but it does not seem to have an effect.
Advice on how to make the above code work, a completely different approach or package that does what I want are all fine answers.