Emacs: reopen buffers from last session on startup?

Viewed 22750

Every day I start up emacs and open the exact same files I had open the day before. Is there something I can add to init.el file so it will reopen all the buffers I was using when I last quit emacs?

5 Answers

You can use the Emacs Desktop library:

You can save the desktop manually with the command M-x desktop-save. You can also enable automatic saving of the desktop when you exit Emacs, and automatic restoration of the last saved desktop when Emacs starts: use the Customization buffer (see Easy Customization) to set desktop-save-mode to t for future sessions, or add this line in your ~/.emacs file:

 (desktop-save-mode 1)

Although I suspect the question was looking for the emacs "desktop" functionality (see above answer), Lewap's approach can be useful if the set of files one uses really is the exact same file set. In fact, one can go a step further and define 'profiles' if one has different sets of regularly used files... Quickie example:

(let ((profile 
       (read-from-minibuffer "Choose a profile (acad,dist,lisp,comp,rpg): ")
       ))
  (cond
   ((string-match "acad" profile) 
    (dired "/home/thomp/acad")
    (dired "/home/thomp/acad/papers")
    )
   ((string-match "lisp" profile)
    (setup-slime)
    (lisp-miscellany)
    (open-lisp-dirs)
    )
   ((string-match "rpg" profile)
    (find-file "/home/thomp/comp/lisp/rp-geneval/README")
    (dired "/home/thomp/comp/lisp/rp-geneval/rp-geneval")
... etc.

If you find that you regularly switch back and forth between different sets of regularly-used files as you work, consider using perspectives and populating each perspective with the desired set of regularly-used files.

Related