[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, 21 Mar 2018 10:13:11 +0100 |
User-agent: |
mu4e 1.1.0; emacs 27.0.50 |
On 2018-03-21, at 08:25, Marcin Borkowski <mbork@mbork.pl> wrote:
> On 2018-03-21, at 07:55, Eli Zaretskii <eliz@gnu.org> wrote:
>
>>> From: Marcin Borkowski <mbork@mbork.pl>
>>> Date: Wed, 21 Mar 2018 07:08:44 +0100
>>>
>>> I want to make a variable persistent across Emacs sessions. How do I do
>>> it?
>>
>> Did you consider desktop.el?
>
> No, I did not remember about its existence.
>
> But no, way too heavy. I want _one variable_ to persist, and nothing
> more.
OK, how about this?
--8<---------------cut here---------------start------------->8---
(defun make-variable-persistent (variable-name)
"Save VARIABLE-NAME to `custom-file' or `init-file'."
(when (y-or-n-p (format "I am going to save variable `%s' in %s. Should I
proceed? " variable-name user-init-file))
(with-temp-file user-init-file
(let ((sentinel-text (format "\n;; Persistent variable `%s'. Do not edit
manually!\n" variable-name)))
(insert-file-contents user-init-file)
(if (search-forward sentinel-text nil t)
(if (not (looking-at-p (format "^(setq %s" variable-name)))
(error "Broken init file.")
(kill-sexp))
(goto-char (point-max))
(insert sentinel-text)))
(insert (format "(setq %s %S)" variable-name (symbol-value
variable-name))))))
--8<---------------cut here---------------end--------------->8---
Any thoughts/suggestions?
--
Marcin Borkowski
http://mbork.pl
- Persistence of variables, Marcin Borkowski, 2018/03/21
- Re: Persistence of variables, Emanuel Berg, 2018/03/21
- Message not available
- Re: Persistence of variables, Emanuel Berg, 2018/03/21
- Re: Persistence of variables, Eric Abrahamsen, 2018/03/21
- Re: Persistence of variables, Marcin Borkowski, 2018/03/21
- RE: Persistence of variables, Drew Adams, 2018/03/21
- Re: Persistence of variables, tomas, 2018/03/21