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:47:07 +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="28937"; mail-complaints-to="usenet@ciao.gmane.io" Cc: "help-gnu-emacs@gnu.org" To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jan 06 03:54:46 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 1kwyyE-0007Q2-DC for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 06 Jan 2021 03:54:46 +0100 Original-Received: from localhost ([::1]:33890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kwyyD-0005wX-FN for geh-help-gnu-emacs@m.gmane-mx.org; Tue, 05 Jan 2021 21:54:45 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38528) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kwyxQ-0005rU-Uo for help-gnu-emacs@gnu.org; Tue, 05 Jan 2021 21:53:56 -0500 Original-Received: from mail-ed1-x52d.google.com ([2a00:1450:4864:20::52d]:42676) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kwyxP-0007RV-3j for help-gnu-emacs@gnu.org; Tue, 05 Jan 2021 21:53:56 -0500 Original-Received: by mail-ed1-x52d.google.com with SMTP id g24so3000988edw.9 for ; Tue, 05 Jan 2021 18:53:54 -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=HmdtNFocPqVWn633rJOpmdrXoVg75yMr7WgxEUDi2f0=; b=OJaXgGOxQuqlEsqQHtu5xsvqY9GC0FYZPY4GLDCzDv9jjsFIDbs5Q0sSrErVEmFTbq bExiL03Px1hcoRsRlmi1+9rCv3TOpxOTX9Z9Q5CHD9sX9RR3H9IPMqhev+zvlUmRsija j6ErjCdPr1xTrHXORGom4yZxlewDcfc+mZkj+tzAsdy2U58bkvtp9XUbu/ZhFxfM39wN btV4YcAS6dIBM2xtabl9WZV0xbFDy3AKyy1DH/wg/n3kQcMCiCFsha6RehucQL4hfYAX X7xgs/PxIluy3Voiu3ePeoMWWanRTbD3iaFaFdV3sKbaeiJFWCvug2DNDoVjYFtFhsNm paMQ== 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=HmdtNFocPqVWn633rJOpmdrXoVg75yMr7WgxEUDi2f0=; b=ALubueTVqxqwKtRLWFNA3Pc3X/biHSdOYL+qq9lAYuaUBYKgm1/wpRyRCQBmYx4TEL pPCsOI49mgBchRz2mteDxYJVR9mW65o9JU225+UD/Ij4AG165mE8/Om+8RNOD1MKan8G 6JkSFlLRAxNKL3b1lM+9+ICtx4NMpcEIbmEOHe1ZNLSbx+hPuEdZFhL2m0LKafD0+EAA 2BCh9RtOC1KHkaJggWPV1hlNg0+ByEqqiBMSSTfpEIwecsgf7+VhjIh7KnNgZdVGWqi0 DFGSIbJqALPD0ej+b/+AL7zrI4utRjemG0TX5ALWX4HiS2kClm9jrg4IBuKctpoV2KHw brRg== X-Gm-Message-State: AOAM533UgQfW7DjyBd38nVDVXaXiQKbI3p3rFP6eEQm3hJS/9JR6wks/ lic8OeA/uW2X/x13DF2/MQ== X-Google-Smtp-Source: ABdhPJz4htgzfJtR0hXqALpsaHmbhOx6DEfOpJmYdaWbTA8dlj1dLSSJsyPwbGYleeT51TUFESrfRA== X-Received: by 2002:a05:6402:1597:: with SMTP id c23mr2564045edv.212.1609901633497; Tue, 05 Jan 2021 18:53:53 -0800 (PST) Original-Received: from VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM ([2603:1026:300:5a::5]) by smtp.gmail.com with ESMTPSA id ot18sm454043ejb.54.2021.01.05.18.53.52 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Jan 2021 18:53:53 -0800 (PST) Original-Received: from dark (183.246.146.135) by TY2PR01CA0014.jpnprd01.prod.outlook.com (2603:1096:404:a::26) 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:47:05 +0000 Thread-Topic: How to store list of variable values into another dynamically created variables Thread-Index: AQHW4qkXK10lERdItkWpz6OiHr7Jc6oZ5lYA X-MS-Exchange-MessageSentRepresentingType: 1 In-Reply-To: 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: 2b0ff379-db3e-4283-f9bf-08d8b1ed5b2a X-MS-Exchange-Organization-SCL: -1 X-MS-Exchange-Organization-RecordReviewCfmType: 0 x-clientproxiedby: TY2PR01CA0014.jpnprd01.prod.outlook.com (2603:1096:404:a::26) To VI1PR1001MB1070.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:800:69::18) Received-SPF: pass client-ip=2a00:1450:4864:20::52d; envelope-from=numbchild@gmail.com; helo=mail-ed1-x52d.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:127008 Archived-At: Stefan Monnier writes: >> 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 Maybe can provide a simple package for this purpose? And include it in Emac= s / GNU ELPA will be available for some package developers. WDYT? Indeed, because some minor modes are based on another mode. As a minor mode= , should provide a mechanism to store and restore original settings. Of cours= e, not provided is also acceptable. --=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