all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Checking in Lisp if a given symbol has its original value
@ 2020-03-31  8:14 Bruno Félix Rezende Ribeiro
  2020-03-31 15:36 ` Drew Adams
  0 siblings, 1 reply; 2+ messages in thread
From: Bruno Félix Rezende Ribeiro @ 2020-03-31  8:14 UTC (permalink / raw)
  To: help-gnu-emacs

What’s the canonical way of checking if a given symbol has its
original value, as reported by ‘describe-variable’?

I’ve come up with:

#+BEGIN_SRC elisp
  (defun standard-value-p (symbol)
    "Return non-nil if SYMBOL has its original value."
      (equal (eval (car (get symbol 'standard-value)))
             symbol))
#+END_SRC

-- 
Bruno Félix Rezende Ribeiro (oitofelix) [0x28D618AF]
<http://oitofelix.freeshell.org/>



^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Checking in Lisp if a given symbol has its original value
  2020-03-31  8:14 Checking in Lisp if a given symbol has its original value Bruno Félix Rezende Ribeiro
@ 2020-03-31 15:36 ` Drew Adams
  0 siblings, 0 replies; 2+ messages in thread
From: Drew Adams @ 2020-03-31 15:36 UTC (permalink / raw)
  To: Bruno Félix Rezende Ribeiro, help-gnu-emacs

> What’s the canonical way of checking if a given symbol has its
> original value, as reported by ‘describe-variable’?
> I’ve come up with:
>   (defun standard-value-p (symbol)
>     "Return non-nil if SYMBOL has its original value."
>       (equal (eval (car (get symbol 'standard-value)))
>              symbol))

That's only for user options, aka customizable variables,
aka variables defined with defcustom.  See the Elisp
manual, node Standard Properties.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Standard-Properties.html

There's no way to check other variables, in general.

For any given variable whose creation you control or
monitor, you can of course record its initial value
in some way.

You can also use function `add-variable-watcher' to
monitor changes to a variable's value.  But again, you
would want to do this from the outset, when it is
created.  See the Elisp manual, node Watching Variables.

https://www.gnu.org/software/emacs/manual/html_node/elisp/Watching-Variables.html




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-31 15:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-31  8:14 Checking in Lisp if a given symbol has its original value Bruno Félix Rezende Ribeiro
2020-03-31 15:36 ` Drew Adams

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.