1
0
Fork 0
Emacs package that automatically saves the state in the background.
Go to file
2023-07-02 08:03:29 +02:00
.gitignore Add .gitignore 2023-05-14 22:49:45 +02:00
LICENSE.txt Apply license properly 2023-06-03 18:03:34 +02:00
persist-state.el Version bump 2023-07-02 08:03:29 +02:00
README.org Add badge for MELPA stable 2023-07-02 08:02:09 +02:00

Emacs Persist State

MELPA MELPA Stable

Introduction

I don't leave Emacs often, but sometimes Emacs leaves me.

At moments like these it's convenient to start Emacs again with a reasonably up to date state from the previous session: history variables, bookmarks, open buffers, etc. Usually these items are saved at Emacs exit (as part of kill-emacs-hook), but when Emacs exits unexpectedly due to a crash, these functions are not executed and you're left with an outdated state (if any).

This package saves your Emacs state regularly when idle for a brief moment, to minimize the disturbance of executing all save functions in sequence (as Emacs blocks for a brief moment). In case Emacs is idle for a longer time, no state is saved.

Supported packages

persist-state supports a number of packages out of the box. For some packages the save only takes place when the corresponding mode or variable is set accordingly. For example, saving history only takes place if savehist-mode is active. Consult the package's documentation or source code for more info about auto-saving.

  • bookmark
  • desktop
  • Eshell history
  • Prescient.el
  • recentf
  • savehist
  • saveplace

Installation and usage

The easiest method is to install via MELPA.

Alternatively, clone the repository and put the package in your load-path, for example with use-package:

git clone https://codeberg.org/bram85/emacs-persist-state.git
  (use-package persist-state
    :ensure nil
    :load-path "/path/to/emacs-persist-state"
    :config
    (persist-state-mode))

Configuration

This table shows which variables can be customized.

Custom variable Description
persist-state-save-interval Interval (in seconds) to persist state.
persist-state-saving-functions A list of functions that should be executed as part of saving state.
persist-state-wait-idle When it's time to save, wait for this amount of idle time (in seconds).

To add your own save functions, simply add those to the persist-state-functions variable. For example, if you use the org-visibility package, you could save the heading visibility data on a regular basis as well:

  (add-to-list 'persist-state-functions #'org-visibility-save-all-buffers)

Related packages

persist
This package targets package developers to declare variables to be persisted across Emacs sessions.
savehist
This built-in package saves history variables. Actually, this package is called by persist-state to save the history variables at regular intervals.

Contact