changeset 27703:2ff09a66fbf1

(set_internal): Don't make variable buffer-local if within a let-binding for the same buffer. (let_shadows_buffer_binding_p): New function.
author Richard M. Stallman <rms@gnu.org>
date Tue, 15 Feb 2000 09:57:33 +0000
parents 50df459c86d1
children e809aae28ae6
files src/data.c
diffstat 1 files changed, 28 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/data.c	Tue Feb 15 09:56:18 2000 +0000
+++ b/src/data.c	Tue Feb 15 09:57:33 2000 +0000
@@ -962,6 +962,23 @@
   return set_internal (symbol, newval, current_buffer, 0);
 }
 
+/* Return 1 if SYMBOL currently has a let-binding
+   which was made in the buffer that is now current.  */
+
+static int
+let_shadows_buffer_binding_p (symbol)
+     Lisp_Object symbol;
+{
+  struct specbinding *p;
+
+  for (p = specpdl_ptr - 1; p >= specpdl; p--)
+    if (p->func == 0 && CONSP (p->symbol)
+	&& XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
+      return 1;
+
+  return 0;
+}
+
 /* Store the value NEWVAL into SYMBOL.
    If buffer-locality is an issue, BUF specifies which buffer to use.
    (0 stands for the current buffer.)
@@ -1000,7 +1017,8 @@
       register int idx = XBUFFER_OBJFWD (valcontents)->offset;
       register int mask = XINT (*((Lisp_Object *)
 				  (idx + (char *)&buffer_local_flags)));
-      if (mask > 0 && ! bindflag)
+      if (mask > 0 && ! bindflag
+	  && ! let_shadows_buffer_binding_p (symbol))
 	buf->local_var_flags |= mask;
     }
 
@@ -1068,8 +1086,11 @@
 	      /* If the variable is a Lisp_Some_Buffer_Local_Value,
 		 or if this is `let' rather than `set',
 		 make CURRENT-ALIST-ELEMENT point to itself,
-		 indicating that we're seeing the default value.  */
-	      if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents))
+		 indicating that we're seeing the default value.
+		 Likewise if the variable has been let-bound
+		 in the current buffer.  */
+	      if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents)
+		  || let_shadows_buffer_binding_p (symbol))
 		{
 		  XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
 
@@ -1083,8 +1104,10 @@
 		    tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
 		}
 	      /* If it's a Lisp_Buffer_Local_Value, being set not bound,
-		 give this buffer a new assoc for a local value and set
-		 CURRENT-ALIST-ELEMENT to point to that.  */
+		 and we're not within a let that was made for this buffer,
+		 create a new buffer-local binding for the variable.
+		 That means, give this buffer a new assoc for a local value
+		 and set CURRENT-ALIST-ELEMENT to point to that.  */
 	      else
 		{
 		  tem1 = Fcons (symbol, Fcdr (current_alist_element));