I have a number of variables that store useful state that would be nice to persist across restarts of Emacs. Are there any libraries that allow this to be done simply so I can avoid a bunch of boilerplate for each variable?

I've considered the customise framework but that implies putting everything in one file and it would be nice to specify a specific state file for a given set of variables so they can easily be blown away when required.

2 Answers 2


The savehist library provides one option for persisting variable values across sessions. e.g.:

(eval-after-load "savehist"
  '(add-to-list 'savehist-additional-variables 'foo))

(savehist-mode 1)

As with customize, that's writing everything to a single specific file. But there's no reason why you couldn't leverage this library's functionality by let-binding the relevant vars to save and load specific sets of values.


Load library Bookmark+ and use a variable-list bookmark.

A variable-list bookmark saves and restores the values of a set of variables.

Command bmkp-set-variable-list-bookmark prompts you for the variables to include in the list and then sets the bookmark. Non-interactively, you can use function bmkp-create-variable-list-bookmark to create or update a variable-list bookmark.

Command bmkp-jump-variable-list (C-x j v) restores the recorded variable values for the bookmark's buffer. You can call also this function non-interactively, of course, including from your init file.

(bmkp-jump-variable-list BOOKMARK) ; BOOKMARK is a bookmark name or a bookmark

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.