17

There are files like session.10110ac205e127d7e2143131143297155100000021880037 in my .emacs.d folder. I would like to do something about it but could not figure out what to do.

  • What are these files for ?
  • Why emacs generate multiple files ?
Rangi Lin
  • 987
  • 9
  • 15

2 Answers2

14

These are saved session files which emacs dumps when the window manager notifies it that it is shutting down. See the function emacs-session-save. There are multiple files because they are suffixed by the X session ID. Are you by chance in the habit of quitting your window manager before you exit emacs?

stsquad
  • 4,626
  • 28
  • 45
  • That sounds right. However, I cannot find `emacs-session-save` function. Is there anything I should load into emacs ? – Rangi Lin May 28 '15 at 15:25
  • @RangiLin: C-h f emacs-session-save should take you there. It's in lisp/term/x-win.el if you have the Emacs source code. According to git the function has been there since 2002 so it's quite old ;-) – stsquad May 28 '15 at 15:34
  • It took me awhile to realize that emacs need to load `term` (or M-x term to load) in order to find this function, `emacs-session-filename` is the function that decide where the file should be saved. I will take some time to see how I can change it. Thanks. – Rangi Lin Jun 01 '15 at 04:00
  • 1
    How do we stop them from being made (or move them to another directory)? – Startec May 03 '18 at 05:21
2

There is a movement to clean up this kind of litter of files in .emacs.d:

emacscollective/no-littering: Help keeping ~/.emacs.d clean

This issue has been addressed to some degree by emacs-session: theme emacs-session-filename (#38) by DamienCassou · Pull Request #39 · emacscollective/no-littering but I think it simply puts the files in a subdirectory of .emacs.d

This still doesn't address the underlying question of why empty files are being left around. (Yes - for me, all 84 session.* files are empty. And yes, I don't bother exiting emacs before shutting down - I just run (desktop-save-in-desktop-dir))

nealmcb
  • 194
  • 5
  • no-littering is a ambitious approach, however still making too many mistakes. Hence, we need a session* files specialized solution. –  Aug 17 '21 at 07:06