diff --git a/README.md b/README.md index aa47914..0f8f649 100644 --- a/README.md +++ b/README.md @@ -9,19 +9,24 @@ The `easysession.el` Emacs package is a lightweight session manager for Emacs th ## Table of contents - -- [Features](#features) -- [Installation](#installation) -- [Usage](#usage) -- [Frequently asked questions](#frequently-asked-questions) - - [How to only persist and restore visible buffers](#how-to-only-persist-and-restore-visible-buffers) - - [How to persist and restore global variables?](#how-to-persist-and-restore-global-variables) - - [How to create an empty session setup](#how-to-create-an-empty-session-setup) - - [How does the author use easysession?](#how-does-the-author-use-easysession) - - [Why not use the desktop.el?](#why-not-use-the-desktopel) - - [Why not use one of the other third-party session packages?](#why-not-use-one-of-the-other-third-party-session-packages) -- [License](#license) -- [Links](#links) +**Table of Contents** + +- [easysession.el - Easily persist and restore your Emacs editing sessions](#easysessionel---easily-persist-and-restore-your-emacs-editing-sessions) + - [Table of contents](#table-of-contents) + - [Features](#features) + - [Installation](#installation) + - [Usage](#usage) + - [Frequently asked questions](#frequently-asked-questions) + - [How to only persist and restore visible buffers](#how-to-only-persist-and-restore-visible-buffers) + - [How to persist and restore global variables?](#how-to-persist-and-restore-global-variables) + - [How to create an empty session setup](#how-to-create-an-empty-session-setup) + - [How can I configure easysession-save-mode to automatically save only the "main" session and let me manually save others?](#how-can-i-configure-easysession-save-mode-to-automatically-save-only-the-main-session-and-let-me-manually-save-others) + - [How to make EasySession kill all buffers before loading a session?](#how-to-make-easysession-kill-all-buffers-before-loading-a-session) + - [How does the author use easysession?](#how-does-the-author-use-easysession) + - [Why not use the desktop.el?](#why-not-use-the-desktopel) + - [Why not use one of the other third-party session packages?](#why-not-use-one-of-the-other-third-party-session-packages) + - [License](#license) + - [Links](#links) @@ -43,6 +48,7 @@ The `easysession` package can be installed from MELPA by adding the following to :ensure t :custom (easysession-save-interval (* 10 60)) + (easysession-enable-mode-line t) :init (add-hook 'after-init-hook #'easysession-load-including-geometry 98) (add-hook 'after-init-hook #'easysession-save-mode 99)) @@ -50,6 +56,7 @@ The `easysession` package can be installed from MELPA by adding the following to Note that: - `easysession-load-including-geometry` is not needed after Emacs is loaded if you do not want EasySession to move or resize the Emacs frame when switching sessions. Instead, use `easysession-switch-to` or `easysession-load` to switch to another session or reload the current session without resizing or moving the Emacs frames. +- `easysession-enable-mode-line` controls whether the current session name is displayed in the mode line. Alternatively, `easysession-lighter-show-session` can be used to display the session name in the lighter. - The `easysession-save-mode` ensures that the current session is automatically saved every `easysession-save-interval` seconds and when emacs quits. - The `easysession-save-interval` variable determines the interval between automatic session saves. Setting it to nil disables timer-based autosaving, causing `easysession-save-mode` to save only when Emacs exits. diff --git a/easysession.el b/easysession.el index ad8eba2..50f9529 100644 --- a/easysession.el +++ b/easysession.el @@ -112,6 +112,49 @@ activated when `easysession-save-mode' is enabled." (integer :tag "Seconds")) :group 'easysession) +;; Mode line +(defvar easysession-mode-line-prefix "EasySession" + "Prefix string used to customize the session name display in the mode-line.") + +(defface easysession-mode-line-session-name-face + '((t :inherit font-lock-constant-face :weight bold)) + "Face used in the mode-line to indicate the current session.") + +(defvar easysession-mode-line-format + `(" " ,easysession-mode-line-prefix + "[" (:propertize (:eval easysession--current-session-name) + face easysession-mode-line-session-name-face) "]") + "Mode-line format used to display the session name.") +(put 'easysession-mode-line-format 'risky-local-variable t) + +(defcustom easysession-enable-mode-line t + "If non-nil, add `easysession` to `mode-line-misc-info'. If nil, remove it." + :type 'boolean + :group 'easysession + :set (lambda (symbol value) + (set symbol value) + (if value + (add-to-list 'mode-line-misc-info + `(easysession-save-mode + ,easysession-mode-line-format)) + (setq mode-line-misc-info + (assq-delete-all 'easysession-save-mode mode-line-misc-info))))) + +;; Lighter +(defvar easysession-lighter "EasySess" + "Default lighter string for `easysession-save-mode'.") + +(defvar easysession-lighter-show-session-name nil + "If non-nil, display the session name in the lighter.") + +(defvar easysession-lighter-session-name + `((:eval (format " %s[" easysession-lighter)) + (:propertize (:eval easysession--current-session-name) + face easysession-mode-line-session-name-face) "]") + "Lighter spec for showing the current session.") +(put 'easysession-lighter-session-name 'risky-local-variable t) + +;; Other (defcustom easysession-buffer-list-function #'buffer-list "Function used to retrieve the buffers for persistence and restoration. This holds a function that returns a list of buffers to be saved and restored @@ -919,7 +962,9 @@ non-nil, the current session is saved." (define-minor-mode easysession-save-mode "Toggle `easysession-save-mode'." :global t - :lighter " EasySes" + :lighter (:eval (if easysession-lighter-show-session-name + easysession-lighter-session-name + easysession-mode-line-prefix)) :group 'easysession (if easysession-save-mode (progn