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

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

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


From: Marcin Borkowski
Subject: Re: Is there a way of setting a variable only when it exists?
Date: Tue, 15 Mar 2022 07:16:17 +0100
User-agent: mu4e 1.1.0; emacs 29.0.50

On 2022-03-14, at 23:09, Michael Heerdegen <michael_heerdegen@web.de> wrote:

> Marcin Borkowski <mbork@mbork.pl> writes:
>
>> 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.
>
> Byte compiling can help with things like name changes.

Not necessarily.  My use-case is an internal Emacs variable I'm setting
in my `init.el'; at the same time I submitted a bug report/feature
request to make it a user option, so I assume that it might change its
name in a future Emacs version.

>> I assume it would be fairly easy to code such a macro (using `boundp'),
>
> Maybe rather using `special-variable-p'?

Might be a good idea in this case, yes.

Thanks,

-- 
Marcin Borkowski
http://mbork.pl



reply via email to

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