From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miles christopher Newsgroups: gmane.emacs.help Subject: Re: How to store list of variable values into another dynamically created variables Date: Wed, 6 Jan 2021 02:44:04 +0000 Message-ID: References: <86turvqm1b.fsf@x201.butler.org> Reply-To: miles christopher Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28633"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "help-gnu-emacs@gnu.org" To: Leo Butler Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 06 03:54:43 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kwyyA-0007MP-OZ for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 06 Jan 2021 03:54:42 +0100 Original-Received: from localhost ([::1]:33718 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwyy9-0005ra-Ph for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 05 Jan 2021 21:54:41 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38514) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwyxP-0005rN-UT for help-gnu-emacs@gnu.org; Tue, 05 Jan 2021 21:53:55 -0500 Original-Received: from mail-ej1-x630.google.com ([2a00:1450:4864:20::630]:41111) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kwyxO-0007Qy-2z for help-gnu-emacs@gnu.org; Tue, 05 Jan 2021 21:53:55 -0500 Original-Received: by mail-ej1-x630.google.com with SMTP id ce23so3183997ejb.8 for ; Tue, 05 Jan 2021 18:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:thread-topic:thread-index:date:message-id :references:in-reply-to:reply-to:accept-language:content-language :content-transfer-encoding:mime-version; bh=Gn89qY81lC+V2aXpLtYOA+5XyImrrzF+fOkr3mMZcoM=; b=T5LIm7D906rgnFvPPJ7ncSL/HJP4fgnpYVHyYxrcWFgR1YxK9gdXbWT67BjIEfuRwO d6Rnvfm0bGYE7tJUBZxE7/7ZWmku8w5YXxjr0twT7UnhgThF+zpmEUIgKwdAlVDzIvrl AbT1+r9y2J6WsjeyB6MFT6x8mNCe7lN+k3y75EGdY2UKJyZeGs3GhJCumb9C2EyoQ4B5 SZF3CpW1FTz0WYAsIAP0EPuK/lUjQLqbGKea48D0aFOUFBDnhbJKUyHo6d7dvEePFHv2 WkwwCj3w+gLBRZgE1Qi7s4JuBEl3N/LoWV0CVouuw/n7QJriBRtXorqxvBuInnrA2rHU JjSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:thread-topic:thread-index :date:message-id:references:in-reply-to:reply-to:accept-language :content-language:content-transfer-encoding:mime-version; bh=Gn89qY81lC+V2aXpLtYOA+5XyImrrzF+fOkr3mMZcoM=; b=NkkkCRxkxodbES4fhvELBqgMdG5DTi/RX9I5i5OSrOURviWKcKjQB+0Sbqq9J3/EY4 MiEbe7vJIm+21vKWhn6De2pN/nneLR2ziRujePgiGysLzf+NcD3GEVF8jx57eAiy2jAw f3yFoIENbxg26xgjhLOqKHOun/xV7g2Zlj6D9L9ES2IcWJ746m192I6JQqoh+Ye+eL0Q cPybVpAxMPNjHF7c0k6WF6QTvYvYnoJAvPZueMuwrferod6tYGq+2RR5uKMQEz66/vc6 DfH1UyoqNrFZRyrzqcnUOfkpgQ/FWagJUoFjxJHOA4v+iyZ0X7cKKEl0nxtKJjSqQaVQ kWtw== X-Gm-Message-State: AOAM531iYTSvKW1lplTtq4qjZLDqsZ3rQCTKJv9eIsWVeXLRUBh4Bhyq cNeNtLhLvG8Vb7wRf3vIyQ== X-Google-Smtp-Source: ABdhPJzgeHVBaSaQK8gs2HVEa7ZdxrHPWNhxg6KieupN1ovwCo1gFSVU5bjGzM5BNnxD8X9UikvLBA== X-Received: by 2002:a17:906:2e85:: with SMTP id o5mr1477770eji.521.1609901632197; Tue, 05 Jan 2021 18:53:52 -0800 (PST) Original-Received: from VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM ([2603:1026:300:5a::5]) by smtp.gmail.com with ESMTPSA id m5sm467547eja.11.2021.01.05.18.53.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jan 2021 18:53:51 -0800 (PST) Original-Received: from dark (183.246.146.135) by TYAPR01CA0022.jpnprd01.prod.outlook.com (2603:1096:404::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3742.6 via Frontend Transport; Wed, 6 Jan 2021 02:44:01 +0000 Thread-Topic: How to store list of variable values into another dynamically created variables Thread-Index: AQHW4qkXK10lERdItkWpz6OiHr7Jc6oZ5d4A X-MS-Exchange-MessageSentRepresentingType: 1 In-Reply-To: <86turvqm1b.fsf@x201.butler.org> Accept-Language: zh-TW, en-US Content-Language: en-US X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 06 X-MS-Exchange-Organization-AuthSource: VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM X-MS-Exchange-Organization-Network-Message-Id: 2f0cc042-87c2-44ed-8bcc-08d8b1ecedd6 X-MS-Exchange-Organization-SCL: -1 X-MS-Exchange-Organization-RecordReviewCfmType: 0 x-clientproxiedby: TYAPR01CA0022.jpnprd01.prod.outlook.com (2603:1096:404::34) To VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:69::18) Received-SPF: pass client-ip=2a00:1450:4864:20::630; envelope-from=numbchild@gmail.com; helo=mail-ej1-x630.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:127006 Archived-At: This seems a good solution for my purpose. I'm also interested in Stefan's implementation. I will try both. Thanks Leo. Leo Butler writes: > miles christopher 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 TOD= O. 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-p= refix) > (mu4e-headers-first-child-prefix . mu4e-saved-headers-first-child-pre= fix) > (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 --=20 [ stardiviner ] I try to make every word tell the meaning that I want to express. Blog: https://stardiviner.github.io/ IRC(freenode): stardiviner, Matrix: stardiviner GPG: F09F650D7D674819892591401B5DF1C95AE89AC3