[Top][All Lists]

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

RE: Persistence of variables

From: Drew Adams
Subject: RE: Persistence of variables
Date: Sun, 25 Mar 2018 11:57:38 -0700 (PDT)

> >>> If you only want to save one variable, just use an option.
> >> Of course!
> >> What Drew said. The whole thing was in front of us all, we
> >> just had to squint the right way.
> >
> > Well, that depends on the variable. Options (i.e., those defined with
> > defcustom) are really meant for user customisation: meant to be set
> > explicitly by the user, and meant to be forgotten once set.

Yes - although it is not necessarily meant to be forgotten
once set.  It is sometimes useful for a user to change an
option during the same session, sometimes even multiple times.

And it can be useful for a user to have a command that changes
some option.  The rule that code should not trample on user
options does not apply to a command that a user invokes
explicitly, voluntarily, to make such a change.

> > If you want to save a variable that changes regularly and
> > that the user doesn't set explicitly, then a user option is
> > a bad fit.

Yes (although "changes regularly" is not relevant here, IMO).

In that case, the persistence is not to provide a user with
a persistent cache as much as it is to provide the code with
a persistent cache.

But is it really the case that the persistence is intended
across Emacs sessions for all users?  If not, it is, in
effect, something personal for the user, regardless of how
"regular" the updating might be, and regardless of which
file the value is persisted in.

> > IMHO the best
> > way to deal with that is indeed to use a separate file and to provide
> > a user option to set the file path & name. That way, users can decide
> > for themselves if they want to keep the file under version control,
> > sync it across machines, or not.

If the user specifies the file then this is, in effect,
user-specific.  Whether you make the variable itself a user
option, or you put its value in a file whose name is a user
option, does not change the fact that the variable value is
essentially user-specific.  All you're talking about in that
case is which file to save the value in: (1) `custom-file'
or init file versus (2) some other file.

> And this is exactly my use-case: a variable whose value will be
> periodically changed.

When and how often a variable gets changed doesn't enter
into it.  What's important wrt user options is whether the
variable is user-specific.

> And I don't like the hassle of having an option
> to a separate file with just this one variable...  Of course, if the
> only user beside me won't like Emacs messing around with his init.el,
> I'll do it that way.

If you don't want to save the value in your init file or your
`custom-file', and you don't want to save it in some other
file whose name you have to specify as an option value, then
consider using your bookmark file (which you presumably have
already).  If you want to do that, just create a variable-list
bookmark (using Bookmark+) - it persists and restores any
number of variables, including just one.

"Jumping" to the bookmark restores the saved variable value.
Use command `bmkp-set-variable-list-bookmark' to create and
update the value.  When you save your bookmark list (or when
it is saved automatically), the variable is persisted.

reply via email to

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