2 hours ago · Tech · hide · 0 comments

Emacs has a built-in way to save and restore sessions: the desktop.el library. As the Emacs manual says, putting this in the init file enables automatic save and restore of sessions: (desktop-save-mode 1) But, I wanted a different behavior: Automatically save the session But don't restore it automatically I wanted to only use the session feature to restore sessions that I closed by mistake, or where I forgot to finish something before quitting Emacs. By default, I wanted a fresh session every time. But this also means that some session history has to be maintained; otherwise, a fresh session will start to write to the desktop file and then I will not be able to recover the old session. By default, the way to do this is to not set desktop-save-mode, but manually call desktop-save when needed, and then call desktop-read when needed. But, if I forget to save, I cannot restore. This elisp is what I came up with to make it work the way I want: (defvar my/desktop-snapshot-keep 5 "How many…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.