all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Leo Butler <leo.butler@umanitoba.ca>
To: Emacs Help <help-gnu-emacs@gnu.org>
Subject: Re: How to store list of variable values into another dynamically created variables
Date: Tue, 05 Jan 2021 12:24:48 -0600	[thread overview]
Message-ID: <86turvqm1b.fsf@x201.butler.org> (raw)
In-Reply-To: <VI1PR1001MB10703807AC5509C42C86C62CA3D20@VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM> (miles christopher's message of "Mon, 4 Jan 2021 14:51:32 +0000")

miles christopher <numbchild@gmail.com> writes:

> I want to store some variables' value into another minor mode temporary variable
> for later restore.
>
> Here is my Elisp code, I don't know how to implement it in FIXME and TODO. Hope
> some Elisp master help me.
>
> #+begin_src emacs-lisp
> (defvar mu4e-marker-icons-marker-list
>   '(mu4e-headers-seen-mark
>     mu4e-headers-new-mark
>     mu4e-headers-unread-mark
>     mu4e-headers-signed-mark
>     mu4e-headers-encrypted-mark
>     mu4e-headers-draft-mark
>     mu4e-headers-attach-mark
>     mu4e-headers-passed-mark
>     mu4e-headers-flagged-mark
>     mu4e-headers-replied-mark
>     mu4e-headers-trashed-mark
>     ;; thread prefix marks
>     mu4e-headers-default-prefix
>     mu4e-headers-has-child-prefix
>     mu4e-headers-empty-parent-prefix
>     mu4e-headers-first-child-prefix
>     mu4e-headers-duplicate-prefix)
>   "A list of markers used in mu4e.")
>
> (defun mu4e-marker-icons--store ()
>   "Store user old config."
>   (mapcar
>    (lambda (marker-variable)
>      ;; FIXME:
>      `(setq
>        ,(intern (replace-regexp-in-string
>                  "mu4e-headers-" "mu4e-marker-icons--"
>                  (symbol-name marker-variable)))
>        ,(symbol-value marker-variable))
>      )
>    mu4e-marker-icons-marker-list))
>
> (defun mu4e-marker-icons--restore ()
>   "Restore user old config."
>   ;; TODO:
>   (mapcar
>    (lambda (marker-variable)
>      ;; FIXME:
>      `(setq
>        marker-variable
>        ,(symbol-value (intern (replace-regexp-in-string
>                                "mu4e-headers-" "mu4e-marker-icons--"
>                                (symbol-name marker-variable))))))
>    mu4e-marker-icons-marker-list))
> #+end_src

Since you are trying to rename the variables, why not start with a list
of conses (old . new) rather than a list of variable names?

#+begin_src emacs-lisp
(defvar mu4e-marker-icons-marker-list
  '((mu4e-headers-seen-mark . mu4e-saved-headers-seen-mark)
    (mu4e-headers-new-mark . mu4e-saved-headers-new-mark)
    (mu4e-headers-unread-mark . mu4e-saved-headers-unread-mark)
    (mu4e-headers-signed-mark . mu4e-saved-headers-signed-mark)
    (mu4e-headers-encrypted-mark . mu4e-saved-headers-encrypted-mark)
    (mu4e-headers-draft-mark . mu4e-saved-headers-draft-mark)
    (mu4e-headers-attach-mark . mu4e-saved-headers-attach-mark)
    (mu4e-headers-passed-mark . mu4e-saved-headers-passed-mark)
    (mu4e-headers-flagged-mark . mu4e-saved-headers-flagged-mark)
    (mu4e-headers-replied-mark . mu4e-saved-headers-replied-mark)
    (mu4e-headers-trashed-mark . mu4e-saved-headers-trashed-mark)
    ;; thread prefix marks
    (mu4e-headers-default-prefix . mu4e-saved-headers-default-prefix)
    (mu4e-headers-has-child-prefix . mu4e-saved-headers-has-child-prefix)
    (mu4e-headers-empty-parent-prefix . mu4e-saved-headers-empty-parent-prefix)
    (mu4e-headers-first-child-prefix . mu4e-saved-headers-first-child-prefix)
    (mu4e-headers-duplicate-prefix . mu4e-saved-headers-duplicate-prefix))
  "A list of markers used in mu4e.")

#+end_src

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)))

#+end_src

Leo



  reply	other threads:[~2021-01-05 18:24 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 [this message]
2021-01-05 19:38   ` Stefan Monnier
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=86turvqm1b.fsf@x201.butler.org \
    --to=leo.butler@umanitoba.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.