# How to open all the opened files from a previous session?

Whenever I open my spacemacs I see the recentf buffer which lists 5 files I had open in my previous session. There is only an option to open them one by one, and only five of them, because others are listed later in the same buffer, separately (sort of history). Is there a way to make emacs open all the files I opened in the previous session, in one click?

I can only see the recentf-open-most-recent-file-X (X: [0; 9]) function, however, it is unclear, are the files listed there from the previous session or the session before previous.

Or are there any functions I could use to write my own function to do all of this?

Customize option recentf-menu-open-all-flag to t.

The recentf menu then shows item All..., which lists all recent files, letting you open any of them individually.

2. Your question about opening all recent files at once. (Use C-x C-b to navigate to their buffers.)

   (defun open-all-recent-files ()
"Open all recent files."
(interactive)
(dolist (file  recentf-list) (find-file file)))

• This is much more elegant than my elisp hack, thanks. I should learn more about elisp. – AltruisticDelay Aug 14 '19 at 5:08

I am not sure if this is what you are looking for and if it works in spacemacs. I am using standard emacs and desktop-save-mode. It is configurable with several options. I am using currntly this:

 (setq desktop-dirname             "~/.emacs.d/desktop/"
desktop-base-file-name      "emacs.desktop"
desktop-base-lock-name      "lock"
desktop-path                (list desktop-dirname)
desktop-save                t
desktop-auto-save-timeout   30)
(desktop-save-mode 1)


You can also exclude buffers not to save, for example

    (add-to-list 'desktop-modes-not-to-save 'Info-mode)


You can check the emacs manual for this here

Hope this helps.

EDIT:

I think I understand now what you want. At least it inspired me to experiment a little bit. I am a newbie in ELISP and maybe someone here can help improve this, but I just tried a small function looking like this, opening all buffers in recentf-list:

 (defun open-all-recent()
(let* ((rlist (copy-sequence recentf-list)))
(while rlist
(find-file (car rlist))
(setq rlist (cdr rlist))))


desktop-save-mode is not always feasible and I am thinking, if it would not be better to think about your idea.

• Though this answers the question indirectly, I've upvoted your answer but I'll also let others answer the question directly without using the desktop-save-mode, even though I am going to use it. – Victor Polevoy Aug 13 '19 at 12:49