Article View: gnu.emacs.bug
Article #99438Re: behavior of buffer-local variables
From: Dave Gillespie
Date: Sat, 08 Sep 1990 08:42
Date: Sat, 08 Sep 1990 08:42
89 lines
4088 bytes
4088 bytes
>>>>> On 7 Sep 90 03:02:27 GMT, jbw@bucsf.bu.edu (Joseph Wells) said:
> In article <9008310740.AA04666@csvax.cs.caltech.edu> daveg@CSVAX.CS.CALTECH.EDU (David Gillespie) writes:
> ... there is a
> window between the call to make-local-variable and the first setq in
> which a setq-default's effect is incorrectly visible.
> (setq foo 'one)
> (make-variable-buffer-local 'foo)
> (make-local-variable 'foo)
> foo => 'one
> (setq-default foo 'two)
> foo => 'two [this is inconsistent]
> (setq foo 'three)
> foo => 'three
> (setq-default foo 'four)
> foo => 'three [correct behavior]
> This is "correct" behavior. make-variable-buffer-local and
> make-local-variable leave the buffer-local value of the symbol unbound.
> When the buffer-local value of a symbol is unbound, it is shadowed by the
> default value of the symbol.
Actually, make-local-variable *does* copy the default value of the
variable to the buffer-local binding. The above experiment was
inconsistent with the following, which I just tried with Emacs 18.55:
(setq bar 'one)
(make-local-variable 'bar)
bar => 'one
(setq-default bar 'two)
bar => 'one
That is, once you have made a variable local to a buffer, it no
longer sees the default... *unless* the variable was flagged to
become buffer-local automagically but had not yet actually done so.
In node "Buffer Local Variables" my copy of the Lisp manual says,
with no if's, and's, or but's:
The buffer-local value of SYMBOL starts out as the same value
SYMBOL previously had.
> Strange fact: if a symbol has any buffer-local values, even unbound
> values, then that symbol's default value can not be unbound.
> Fact 2: you can undo the effects of any make-variable-buffer-local and
> make-local-variable calls with makunbound.
Hey, you're right!
There are explicit tests in both Fmake_variable_buffer_local and
Fmake_local_variable to change an unbound variable to nil. I
wonder why; it looks like it would work fine leaving the variable
unbound.
The second fact could, as far as I can see, be fixed by this
patch to Fmakunbound in data.c:
----
CHECK_SYMBOL (sym, 0);
! XSYMBOL (sym)->value = Qunbound;
return sym;
----
CHECK_SYMBOL (sym, 0); /* Actually redundant now. */
! Fset(sym, Qunbound); /* Looks like a kludge, but unbind_to() */
return sym; /* does this, too! */
----
Gee, I wonder if there should be a "makunbound-default" function? :-)
The Fboundp and specbind() functions would have to be enhanced to be able
to understand unbound buffer-local variables. One creative solution would
be to define a "safe-symbol-value" function that doesn't mind returning
Qunbound as the symbol value; where Qunbound would be interned under
some suitably obscure name. Then Fboundp and specbind() could use
this function, and there have even been a couple of times I could have
used it myself...
However, all of this is beginning to bring to mind the saying,
"if it works [well enough], don't fix it." :-/
-- Dave
--
Dave Gillespie
256-80 Caltech Pasadena CA USA 91125
daveg@csvax.cs.caltech.edu, ...!cit-vax!daveg
Technical Details
Message-ID:
<DAVEG.90Sep8014218@near.cs.caltech.edu>Path:
arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!jarthur!nntp-server.caltech.edu!laguna.ccsf.caltech.edu!davegReferences:
<9008310740.AA04666@csvax.cs.caltech.edu> <JBW.90Sep6230227@bucsf.bu.edu>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fb2f1,740930ec93aa18ac X-Google-Attributes: gidfb2f1,public X-Google-ArrivalTime: 1990-09-08 05:53:40 PST Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!jarthur!nntp-server.caltech.edu!laguna.ccsf.caltech.edu!daveg From: daveg@near.cs.caltech.edu (Dave Gillespie) Newsgroups: gnu.emacs.bug Subject: Re: behavior of buffer-local variables Message-ID: <DAVEG.90Sep8014218@near.cs.caltech.edu> Date: 8 Sep 90 08:42:18 GMT References: <9008310740.AA04666@csvax.cs.caltech.edu> <JBW.90Sep6230227@bucsf.bu.edu> Sender: news@laguna.ccsf.caltech.edu Distribution: gnu Organization: California Institute of Technology Lines: 89 Posted: Sat Sep 8 09:42:18 1990 In-Reply-To: jbw@bucsf.bu.edu's message of 7 Sep 90 03:02:27 GMT