help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Is there a way of setting a variable only when it exists?


From: Marcin Borkowski
Subject: Is there a way of setting a variable only when it exists?
Date: Mon, 14 Mar 2022 07:00:33 +0100
User-agent: mu4e 1.1.0; emacs 29.0.50

Hi all,

I'd like to be able to say something like

(setq-safe hello "world")

so that `hello' is set to `"world"' if it is an existing variable (e.g.,
defined by `defvar') and an error is raised if `hello' does not exist.

Rationale: I'm setting an internal Emacs variable.  At the same time,
I submitted a feature request to turn it into a user option, so that
it's possible that in a future version of Emacs it's going to change its
name (it has two dashes in it).  I want to be warned then that I need to
change my `init.el' accordingly.

I assume it would be fairly easy to code such a macro (using `boundp'),
but maybe it exists already?

TIA,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

[Prev in Thread] Current Thread [Next in Thread]