help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Persistence of variables


From: Marcin Borkowski
Subject: Re: Persistence of variables
Date: Wed, 28 Mar 2018 21:12:53 +0200
User-agent: mu4e 1.1.0; emacs 27.0.50

On 2018-03-26, at 03:48, Eric Abrahamsen <eric@ericabrahamsen.net> wrote:

> Drew Adams <drew.adams@oracle.com> writes:
>
>>> > But no, way too heavy.  I want _one variable_ to persist, and nothing
>>> > more.
>>> 
>>> If you already use savehist-mode, you can add your variable to
>>> savehist-additional-variables.
>>
>> There are several possibilities, including these:
>>
>> 1. `savehist.el' (what Eric said)
>> 2. Customize (option value)
>> 3. Bookmark (e.g., Bookmark+ variable-list bookmark)
>> 4. Desktop
>>
>> If you only want to save one variable, just use an option.
>
> To muddy the waters further, there's also eieio-persistent:
>
> (require 'eieio-base)
> (defclass my-var-persister (eieio-persistent)
>   ((directory
>     :initarg :directory
>     :initform ""
>     :type string)))
>
> (setq persister (make-instance 'my-var-persister
>                              :directory "~/dir"
>                              :file "~/.emacs.d/persist"))
>
> (eieio-persistent-save persister)
>
> ;; Restart Emacs
>
> (setq persister (eieio-persistent-read "~/.emacs.d/persist"))
>
> (slot-value persister 'directory) ; "~/.dir"
>
>
> Probably too heavy-weight for what you're describing, but it's another
> option. If you ever want to save more complex data than just a single
> value, it's not a bad choice.

Interesting.  Not for one string-valued variable, but worth keeping in
mind.  Thanks!

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]