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

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

Re: Generality of defvar


From: carlmarcos
Subject: Re: Generality of defvar
Date: Wed, 27 Jul 2022 14:18:27 +0200 (CEST)

Jul 27, 2022, 07:29 by thibaut.verron@gmail.com:

> Le mer. 27 juil. 2022 à 01:11, carlmarcos--- via Users list for the GNU
> Emacs text editor <help-gnu-emacs@gnu.org> a écrit :
>
>> Jul 26, 2022, 23:01 by philipk@posteo.net:
>>
>> > carlmarcos--- via Users list for the GNU Emacs text editor
>> > <help-gnu-emacs@gnu.org> writes:
>> >
>> >> Have been looking into defvar and noticed the generality of its use
>> >>
>> >> (defvar aname t)
>> >> (defvar bname nil)
>> >> (defvar cname 1)
>> >> (defvar dname "text")
>> >>
>> >> Then I can do
>> >>
>> >> (when aname (setq debug-on-error t))
>> >> (when bname (setq debug-on-error nil))
>> >>
>> >> Is this correct?
>> >>
>> >
>> > You can /do/ it, but what do you /want/ to archive?
>> >
>> Want to use a defvar to enable or disable some functionality using `when',
>> such as enabling error diagnostics with the command
>>
>> (when myopt (setq debug-on-error t))
>>
>
> In principle yes, but for this example there already is a variable for that
> purpose, debug-on-error.
> So you might as well just use it as your control variable, and use
> conditionals like (when debug-on-error ...) or (unless debug-on-error ...)
> if you want to do more things.
>
> Also, those lines:
>
> (when aname (setq debug-on-error t))
> (when bname (setq debug-on-error nil))
>
> are equivalent to
>
> (setq debug-on-error (and aname (not bname)))
>
> I don't really see the point of having two variables hold opposite values.
> Wouldn't
>
> (if aname
>  (setq debug-on-error t)
>  (setq debug-on-error nil))
>
> or equivalently
>
> (setq debug-on-error aname)
>
> be more what you want?
>
Thank you very much for your elaboration.  

This is what I got right now

(defvar error-diagnostics t
  "Enable error diagnostics if non-nil.")

(defun enable-error-diagnostics ()
  "Enable error diagnostics with backtrace buffer.
One can exit the debugger with the q command."

  (setq debug-on-error t)
  (setq debug-ignored-errors t))

(when error-diagnostics (enable-error-diagnostics))







reply via email to

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