From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tomas Nordin Newsgroups: gmane.emacs.help Subject: Re: Is there a way of setting a variable only when it exists? Date: Wed, 16 Mar 2022 06:02:59 +0000 Message-ID: <87fsnijuy4.fsf@posteo.net> References: <87lexdul8e.fsf@mbork.pl> <878rtcir1h.fsf@zoho.eu> <87a6drviwp.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24145"; mail-complaints-to="usenet@ciao.gmane.io" Cc: help-gnu-emacs@gnu.org To: Marcin Borkowski , Emanuel Berg Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Mar 16 07:13:34 2022 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 1nUMub-00063H-Iv for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Mar 2022 07:13:33 +0100 Original-Received: from localhost ([::1]:54580 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nUMua-0000eK-BM for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 16 Mar 2022 02:13:32 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:59570) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUMkV-0002md-Al for help-gnu-emacs@gnu.org; Wed, 16 Mar 2022 02:03:07 -0400 Original-Received: from mout02.posteo.de ([185.67.36.66]:49103) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nUMkS-00077W-TP for help-gnu-emacs@gnu.org; Wed, 16 Mar 2022 02:03:06 -0400 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 508C4240101 for ; Wed, 16 Mar 2022 07:03:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1647410580; bh=CNgn5sbxu0yw6W8QbTQ7F5dPGkIIB/kNyeJFgwmJ7G4=; h=From:To:Cc:Subject:Date:From; b=NG0FvxWVBJdMYzrLT3M4scqf164JY5H+FS9q+d2ZT3+YggpAIGHNbUqwO+10PXmb9 LQ9z+r06UfDmp66biO+ppLvR3FpJ5RHq38EReDaF/YjTcm/XQOxfHmBgGYnx9WO8uB kJcBEbVRO+/T0bTTvvNjd6O6msCloaLQXDTjTTK9VA/evNkjgddpndDvj6skIlW+hs f91tv6sRowQpAEJ3gk6PFNajMxtyIFKxqBmXdJpAaQzplgCqDLJ90JyQze/xwz2Za1 3m9PIGKCztrKh1wPyRb/nUq5N/FaJKQabOB1vgSUM/RXTrlD3v4Jaw8La4MTqR+Zoq JlBk0thSkdhcQ== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4KJKSg2xgtz9rxL; Wed, 16 Mar 2022 07:02:59 +0100 (CET) In-Reply-To: <87a6drviwp.fsf@mbork.pl> Received-SPF: pass client-ip=185.67.36.66; envelope-from=tomasn@posteo.net; helo=mout02.posteo.de X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 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, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 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:136607 Archived-At: Marcin Borkowski writes: > On 2022-03-14, at 14:48, Emanuel Berg via Users list for the GNU Emacs text editor wrote: > >> Stefan Monnier via Users list for the GNU Emacs text editor wrote: >> >>>> I assume it would be fairly easy to code such a macro >>>> (using `boundp'), but maybe it exists already? >>> >>> AFAIK it doesn't exist yet. The reason for it is that it is >>> not often useful. Typically there are two cases: >>> >>> - If the var exist, you want to set it and if not you have >>> no fallback. In that case, it is typically harmless to set >>> the var even when it doesn't exist, so the code just uses >>> `setq` without bothering to test `boundp`. >>> >>> - If the var exist you want to set it, and if it doesn't you >>> want to do something else. In that case, the something >>> else tends to depend on the specifics so (if (boundp 'foo) >>> (setq foo ..) ...) is about s good as it gets. >> >> If it exists set it with `setq'. If it doesn't exist, create >> and set it ... with `setq'? > > What if it's an internal Emacs variable which might become a user option > one day (I submitted a bug report about it) and then my customization > silently disappears? It's the "silently" part I want to guard > against... What about doing an assert of sorts (message "some--internal-var is %S" some--internal-var) (setq some--internal-var 42) It will crash your init process if some--internal-var is void. -- Tomas