Skip to content

Commit

Permalink
Merge pull request #14 from EGmux/main
Browse files Browse the repository at this point in the history
Update modeline to show colorized session name

Co-authored-by: Enzo Gurgel <[email protected]>
Co-authored-by: James Cherti <[email protected]>
  • Loading branch information
jamescherti and EGmux committed Sep 14, 2024
1 parent 8fcd01e commit fb6102c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
33 changes: 20 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@ The `easysession.el` Emacs package is a lightweight session manager for Emacs th
## Table of contents

<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc-refresh-toc -->

- [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)

<!-- markdown-toc end -->

Expand All @@ -43,13 +48,15 @@ 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))
```

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.

Expand Down
47 changes: 46 additions & 1 deletion easysession.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fb6102c

Please sign in to comment.