🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98355

Problem with setting default values for buffer local variables

#98355
From: Julian Cowley
Date: Fri, 23 Aug 1991 09:43
73 lines
3243 bytes
Suppose I am in the *scratch* buffer of a newly spawned Emacs
version 18.55, and type the following expressions:

    (setq foo 'old-value)
    ==> old-value
    (make-local-variable 'foo)
    ==> foo
    foo
    ==> old-value
    (default-value 'foo)
    ==> old-value
    (setq foo 'local-value)
    ==> local-value
    (default-value 'foo)
    ==> old-value

Ok, so far so good.  Things are working as expected.  Now switch
to a new buffer and set lisp-interaction-mode.

    (default-value 'foo)
    ==> old-value
    (setq foo 'new-value)
    ==> new-value
    (default-value 'foo)
    ==> old-value
    (setq foo 'new-improved-value)
    ==> new-improved-value
    (default-value 'foo)
    ==> old-value

Eh?  This buffer does not have its own value for FOO, so by
setting it, I should also be setting the default value, but that
is not what is happening.

The reason for this anomalous behavior lies in the function Fset.
When the current buffer sees the default value, presently only
REALVALUE is set, whereas the DEFAULT-VALUE should be set at the
same time so that default-value can find it.

*** /usr/uh/src/gnu/emacs/dist-18.55/src/data.c	Fri Feb 10 20:15:57 1989
--- data.c	Thu Aug 22 22:52:49 1991
***************
*** 693,696 ****
--- 693,700 ----
  	  XSET (XCONS (XCONS (valcontents)->cdr)->car, Lisp_Buffer, bf_cur);
  	}
+       /* If the current buffer sees the default value, make sure that the
+ 	 default value is set, too.  */
+       if (XCONS (XCONS (valcontents)->cdr)->cdr == current_alist_element)
+ 	XCONS (current_alist_element)->cdr = newval;
        valcontents = XCONS (valcontents)->car;
      }

Actually, the whole section of Fset dealing with buffer-local
variables could use a slight tune-up.  For instance, this
expression starting on line 673 seems to be quite wrong:

      if (bf_cur != ((XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value)
		     ? XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)
		     : XBUFFER (XCONS (current_alist_element)->car)))

Why is the car of current_alist_element cast to a buffer pointer?
I would have expected it to look more like the following:

      if (bf_cur != XBUFFER (XCONS (XCONS (valcontents)->cdr)->cdr))

Note that since BUFFER can be Qnil, this is not strictly correct,
but it still works since the test is a pointer comparison and no
buffer will occupy the same address as the struct Lisp_Symbol.

ps. These patches are *untested*.  Proceed with caution!

Julian Cowley <julian@uhunix.uhcc.hawaii.edu>
Technical Details
Message-ID: <9108230943.AA08907@uhunix.uhcc.Hawaii.Edu>
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!uhunix.uhcc.hawaii.edu!julian

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,50e2d1172eebd9ae,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-08-23 02:43:29 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!fauern!ira.uka.de!sol.ctr.columbia.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!uhunix.uhcc.hawaii.edu!julian
From: julian@uhunix.uhcc.hawaii.edu (Julian Cowley)
Newsgroups: gnu.emacs.bug
Subject: Problem with setting default values for buffer local variables
Message-ID: <9108230943.AA08907@uhunix.uhcc.Hawaii.Edu>
Date: 23 Aug 91 09:43:29 GMT
Sender: gnulists@ai.mit.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 73
Approved: bug-gnu-emacs@prep.ai.mit.edu