Easysession.el
easysession.el: Easily persist and restore Emacs file buffers, Magit buffers, scratch, Dired, narrowing, indirect buffers (clones), windows, and tab-bar configurations; a robust desktop.el replacement that allows switching sessions and fully supports GUI and daemon modes
Install / Use
/learn @jamescherti/Easysession.elREADME
easysession.el: Easily persist and restore Emacs file buffers, Magit buffers, scratch, Dired, narrowing, indirect buffers (clones), windows, and tab-bar configurations; a robust desktop.el replacement
The easysession Emacs package provides a comprehensive session management for Emacs. It is capable of persisting and restoring file-visiting buffers, indirect buffers (clones), buffer narrowing, Dired buffers, window configurations, the built-in tab-bar (including tabs, their buffers, and associated windows), as well as entire Emacs frames (frame name, size, position, etc.).
With easysession, your Emacs setup is restored automatically when you restart. All files, Dired buffers, and window layouts come back as they were, so you can continue working right where you left off. While editing, you can also switch to another session, switch back, rename sessions, or delete them, giving you full control over multiple work environments.
Easysession also supports extensions, enabling the restoration of Magit buffers and the scratch buffer. Custom extensions can also be created to extend its functionality.
<p align="center"> <img src="https://jamescherti.com/misc/easysession-m.png" width="40%" /> </p>If this package enhances your workflow, please show your support by ⭐ starring EasySession on GitHub to help more users discover its benefits.
Key features include:
- Quickly switch between sessions while editing with or without disrupting the frame geometry.
- Capture the full Emacs workspace state: file buffers, indirect buffers and clones, buffer narrowing, Dired buffers, window layouts and splits, the built-in tab-bar with its tabs and buffers, and Emacs frames with optional position and size restoration.
- Built from the ground up with an emphasis on speed, minimalism, and predictable behavior, even in large or long-running Emacs setups.
- Supports both standard Emacs sessions and Emacs running in daemon mode.
- Never lose context with automatic session persistence. (Enable
easysession-save-modeto save the active session at regular intervals defined byeasysession-save-intervaland again on Emacs exit.) - Comprehensive command set for session management: switch sessions instantly with
easysession-switch-to, save witheasysession-save, delete witheasysession-delete, and rename witheasysession-rename. - Highly extensible architecture that allows custom handlers for non-file buffers, making it possible to restore complex or project-specific buffers exactly as needed.
- Fine-grained control over file restoration by selectively excluding individual functions from
find-file-hookduring session loading viaeasysession-exclude-from-find-file-hook. - Clear visibility of the active session through modeline integration or a lighter.
- Built-in predicate to determine whether the current session qualifies for automatic saving.
- Save and unload the currently loaded session using
easysession-unload. - Exact restoration of narrowed regions in both base and indirect buffers, ensuring each buffer reopens with the same visible scope as when it was saved.
- Optional scratch buffer persistence via the extensions/easysession-scratch.el extension, preserving notes and experiments across restarts.
- Optional Magit state restoration via the extensions/easysession-magit.el extension, keeping version control workflows intact.
Table of Contents
- easysession.el: Easily persist and restore Emacs file buffers, Magit buffers, scratch, Dired, narrowing, indirect buffers (clones), windows, and tab-bar configurations; a robust desktop.el replacement
- Installation
- Extensions
- Usage
- Customization
- How to only persist and restore visible buffers
- How to persist and restore global variables?
- How to make the current session name appear in the mode-line?
- How to create an empty session setup
- How to prevent EasySession from saving when switching sessions
- How to configure easysession-save-mode to automatically save only the "main" session and let me manually save others?
- Passing the session name to Emacs via an environment variable
- How to make EasySession kill all buffers, frames, and windows before loading a session?
- How to create custom load and save handlers for non-file-visiting buffers
- How to start afresh after loading too many buffers
- How to kill all buffers when changing a session?
- How to save the session and close frames without quitting
emacs --daemon - How to persist and restore text scale?
- How does the author use easysession?
- How to reduce the number of buffers in my session, regularly
- What does 'EasySession supports restoring indirect buffers' mean?
- What does EasySession offer that desktop.el doesn't?
- Why not just improve and submit patches to desktop.el?
- Why not use one of the other third-party session packages?
- License
- Links
Installation
To install easysession from MELPA:
-
If you haven't already done so, add MELPA repository to your Emacs configuration.
-
Add the following code to your Emacs init file to install easysession from MELPA:
(use-package easysession
:demand t
:custom
(easysession-save-interval (* 10 60)) ; Save every 10 minutes
;; Save the current session when using `easysession-switch-to'
(easysession-switch-to-save-session t)
;; Do not exclude the current session when switching sessions
(easysession-switch-to-exclude-current nil)
;; Display the active session name in the mode-line lighter.
(easysession-save-mode-lighter-show-session-name t)
;; Optionally, the session name can be shown in the modeline info area:
;; (easysession-mode-line-misc-info t)
:config
;; Key mappings
(global-set-key (kbd "C-c sl") #'easysession-switch-to) ; Load session
(global-set-key (kbd "C-c ss") #'easysession-save) ; Save session
(global-set-key (kbd "C-c sL") #'easysession-switch-to-and-restore-geometry)
(global-set-key (kbd "C-c sr") #'easysession-rename)
(global-set-key (kbd "C-c sR") #'easysession-reset)
(global-set-key (kbd "C-c su") #'easysession-unload)
(global-set-key (kbd "C-c sd") #'easysession-delete)
;; non-nil: Make `easysession-setup' load the session automatically.
;; (nil: session is not loaded automatically; the user can load it manually.)
(setq easysession-setup-load-session t)
;; The `easysession-setup' function adds hooks:
;; - To enable automatic session loading during `emacs-startup-hook', or
;; `server-after-make-frame-hook' when running in daemon mode.
;; - To save the session at regular intervals, and when Emacs exits.
(easysession-setup))
Extensions
Extension: easysession-scratch (Persist and restore the scratch buffer)
This extension makes EasySession persist and restore the scratch buffer.
To enable easysession-scratch-mode, add the following to your configuration:
(with-eval-after-load 'easysession
(require 'easysession-scratch)
(easysession-scratch-mode 1))
Extension: easysession-magit (Persist and restore Magit buffers)
This extension enables EasySession to persist and restore Magit buffers.
To activate easysession-magit-mode, add the following to your Emacs configuration:
(with-eval-after-load 'easysession
(require 'easysession-magit)
(easysession-magit-mode 1))
Usage
It is recommended to use the following functions:
easysession-switch-toto switch to another session,easysession-saveto save
