all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: How to store list of variable values into another dynamically created variables
Date: Tue, 05 Jan 2021 14:38:34 -0500	[thread overview]
Message-ID: <jwvpn2jw58g.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: 86turvqm1b.fsf@x201.butler.org

> 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




  reply	other threads:[~2021-01-05 19:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 14:51 How to store list of variable values into another dynamically created variables miles christopher
2021-01-05 18:24 ` Leo Butler
2021-01-05 19:38   ` Stefan Monnier [this message]
2021-01-06  2:47     ` miles christopher
2021-01-06  3:01       ` Stefan Monnier
2021-01-06  2:44   ` miles christopher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=jwvpn2jw58g.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.