From: Luc Teirlinck <teirllm@dms.auburn.edu>
Cc: emacs-devel@gnu.org
Subject: Re: void variable
Date: Sun, 25 Jul 2004 15:46:15 -0500 (CDT) [thread overview]
Message-ID: <200407252046.i6PKkFH29813@raven.dms.auburn.edu> (raw)
In-Reply-To: <4104091E.4040007@math.ku.dk> (message from Lars Hansen on Sun, 25 Jul 2004 21:25:18 +0200)
Lars Hansen wrote:
I now see that the docstring of defvar clearly says that the variable is
set only if it is void. So
(let ((foo 'y)) (defvar foo 'x))
should leave foo void as it does.
It has nothing to do with the fact that defvar only sets the variable
if void. You get the same result with:
(let ((foo 'y)) (makunbound 'foo) (defvar foo 'x))
See the ielm run at the end of this posting.
What it has to do with is the following quote from
`(elisp)Defining Variables':
*Warning:* If the `defconst' and `defvar' special forms are
used while the variable has a local binding (made with `let', or a
function argument), they set the local-binding's value; the
top-level binding is not changed. This is not what you usually
want. To prevent it, use these special forms at top level in a
file, where normally no local binding is in effect, and make sure
to load the file before making a local binding for the variable.
This also applies to defcustom.
So there is no problem :-)
Unless other people might be confused by this too. Maybe it might be
good to add the above warning to the involved docstrings.
What about the following patches?
===File ~/eval.c-diff=======================================
*** eval.c 19 Jul 2004 07:02:32 -0500 1.220
--- eval.c 25 Jul 2004 15:19:42 -0500
***************
*** 742,747 ****
--- 742,754 ----
This means that M-x set-variable recognizes it.
See also `user-variable-p'.
If INITVALUE is missing, SYMBOL's value is not set.
+
+ If SYMBOL has a local binding, then this form affects the local
+ binding. This is usually not what you want. Thus, if you need to
+ load a file defining variables, with this form or with `defconst' or
+ `defcustom', you should always load that file _outside_ any bindings
+ for these variables. \(`defconst' and `defcustom' behave similarly in
+ this respect.)
usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
(args)
Lisp_Object args;
***************
*** 784,789 ****
--- 791,800 ----
If SYMBOL is buffer-local, its default value is what is set;
buffer-local values are not affected.
DOCSTRING is optional.
+
+ If SYMBOL has a local binding, then this form sets the local binding's
+ value. However, you should normally not make local bindings for
+ variables defined with this form.
usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
(args)
Lisp_Object args;
============================================================
===File ~/custom.el-diff====================================
*** custom.el 05 Jun 2004 22:41:36 -0500 1.75
--- custom.el 25 Jul 2004 15:19:30 -0500
***************
*** 246,251 ****
--- 246,258 ----
Specifies that SYMBOL should be set after the list of variables
VARIABLES when both have been customized.
+ If SYMBOL has a local binding, then this form affects the local
+ binding. This is normally not what you want. Thus, if you need
+ to load a file defining variables with this form, or with
+ `defvar' or `defconst', you should always load that file
+ _outside_ any bindings for these variables. \(`defvar' and
+ `defconst' behave similarly in this respect.)
+
Read the section about customization in the Emacs Lisp manual for more
information."
;; It is better not to use backquote in this file,
============================================================
Just to illustrate:
===File ~/foo-ielm==========================================
*** Welcome to IELM *** Type (describe-mode) for help.
ELISP> (let ((foo 1)) (defvar foo 2) foo)
1
ELISP> (boundp 'foo)
nil
ELISP> (let ((foo 1)) (makunbound 'foo) (defvar foo 2) foo)
2
ELISP> (boundp 'foo)
nil
ELISP> (let ((foo 1)) (defconst foo 2) foo)
2
ELISP> (boundp 'foo)
nil
ELISP> (defvar foo 3)
foo
ELISP> (let ((foo 1)) (makunbound 'foo) (defvar foo 2) foo)
2
ELISP> foo
3
ELISP> (makunbound 'foo)
foo
ELISP> (let ((foo 1)) (makunbound 'foo) (defcustom foo 2 "blabla") foo)
2
ELISP> (boundp 'foo)
nil
ELISP> (defcustom foo 3 "blabla")
foo
ELISP> (let ((foo 1)) (makunbound 'foo) (defcustom foo 2 "blabla") foo)
2
ELISP> foo
3
ELISP>
============================================================
next prev parent reply other threads:[~2004-07-25 20:46 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-25 6:32 void variable Lars Hansen
2004-07-25 7:56 ` Adrian Aichner
2004-07-25 19:25 ` Lars Hansen
2004-07-25 20:46 ` Luc Teirlinck [this message]
2004-07-25 21:54 ` Lars Hansen
2004-07-25 23:39 ` Luc Teirlinck
2004-07-25 23:54 ` Luc Teirlinck
2004-07-26 1:52 ` Luc Teirlinck
2004-07-26 2:13 ` Luc Teirlinck
2004-07-26 14:30 ` Richard Stallman
2004-07-26 15:12 ` Lars Hansen
2004-07-27 18:18 ` Richard Stallman
2004-07-29 2:31 ` Luc Teirlinck
2004-07-29 7:19 ` Lars Hansen
2004-07-30 3:21 ` Luc Teirlinck
2004-07-30 6:56 ` Lars Hansen
2004-07-30 4:55 ` Richard Stallman
2004-07-26 15:21 ` Luc Teirlinck
2004-07-27 18:18 ` Richard Stallman
2004-07-26 16:05 ` Kai Grossjohann
2004-07-26 18:40 ` Lars Hansen
2004-07-27 18:18 ` Richard Stallman
2004-07-26 3:13 ` Richard Stallman
2004-07-26 19:23 ` Stefan Monnier
2004-07-26 19:46 ` Lars Hansen
2004-07-26 19:46 ` David Kastrup
2004-07-26 20:41 ` Luc Teirlinck
2004-07-26 21:13 ` Stefan Monnier
2004-07-27 2:59 ` Luc Teirlinck
2004-07-27 3:07 ` Luc Teirlinck
2004-07-27 3:09 ` Luc Teirlinck
2004-07-28 16:00 ` Richard Stallman
2004-07-29 2:00 ` Luc Teirlinck
2004-08-19 19:33 ` Stefan Monnier
2004-08-19 20:12 ` Adrian Aichner
2004-08-19 20:45 ` Davis Herring
2004-08-20 21:08 ` Richard Stallman
2004-08-20 22:08 ` Stefan Monnier
2004-08-19 21:54 ` Andreas Schwab
2004-08-19 22:20 ` Stefan Monnier
2004-08-19 22:25 ` David Kastrup
2004-08-20 1:27 ` Luc Teirlinck
2004-08-20 14:54 ` Stefan Monnier
2004-08-21 16:49 ` Richard Stallman
2004-08-20 21:08 ` Richard Stallman
2004-07-26 1:29 ` Richard Stallman
-- strict thread matches above, loose matches on Subject: below --
2008-04-17 19:54 J. David Boyd
2008-04-18 8:03 ` Carsten Dominik
2008-04-18 14:34 ` J. David Boyd
2008-04-18 15:02 ` J. David Boyd
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200407252046.i6PKkFH29813@raven.dms.auburn.edu \
--to=teirllm@dms.auburn.edu \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.