[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to store list of variable values into another dynamically create
From: |
Stefan Monnier |
Subject: |
Re: How to store list of variable values into another dynamically created variables |
Date: |
Tue, 05 Jan 2021 14:38:34 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) |
> Your save and restore functions are then dead easy:
>
> #+begin_src emacs-lisp
> (defun mu4e-save (l)
> (mapcar (lambda(x) (set (cdr x) (symbol-value (car x)))) l))
>
> (defun mu4e-restore (l)
> (let ((lrev (mapcar (lambda(x) (cons (cdr x) (car x))) l)))
> (mu4e-save lrev)))
FWIW, in most of the minor modes where I've needed such a thing, I found
it more convenient to use a single "save" variable, e.g. something like:
(defvar FOO--saved-vals nil)
(define-minor-mode FOO-mode
"blabla FOO blabla"
;; Revert to original values.
(dolist (x (prog1 FOO--saved-vals (setq FOO--saved-vals nil)))
(if (consp x)
(set (car x) (cdr x))
(mkunbound x)))
;; Set minor mode's values.
(when FOO-mode
(setq FOO--saved-vals
(mapcar (lambda (v)
(if (boundp v) (cons v (symbol-value v)) v))
'(mu4e-headers-seen-mark
...
mu4e-headers-duplicate-prefix)))
..etc..))
-- Stefan