changeset 40725:a8af2e89346c

(Fbuffer_local_value): New function. (syms_of_buffer): defsubr it.
author Richard M. Stallman <rms@gnu.org>
date Mon, 05 Nov 2001 00:10:49 +0000
parents 867ed25daefa
children 769273502112
files src/buffer.c
diffstat 1 files changed, 53 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c	Mon Nov 05 00:08:57 2001 +0000
+++ b/src/buffer.c	Mon Nov 05 00:10:49 2001 +0000
@@ -808,6 +808,58 @@
   return base_buffer;
 }
 
+DEFUN ("buffer-local-value", Fbuffer_local_value,
+       Sbuffer_local_value, 2, 2, 0, 
+       doc: /* Return the value of VARIABLE in BUFFER.
+If VARIABLE does not have a buffer-local binding in BUFFER, the value
+is the default binding of variable. */)
+     (symbol, buffer)
+     register Lisp_Object symbol;
+     register Lisp_Object buffer;
+{
+  register struct buffer *buf;
+  register Lisp_Object result;
+
+  CHECK_SYMBOL (symbol, 0);
+  CHECK_BUFFER (buffer, 0);
+  buf = XBUFFER (buffer);
+
+  /* Look in local_var_list */
+  result = Fassoc (symbol, buf->local_var_alist);
+  if (NILP (result)) 
+    {
+      int offset, idx;
+      int found = 0;
+
+      /* Look in special slots */
+      for (offset = PER_BUFFER_VAR_OFFSET (name);
+	   offset < sizeof (struct buffer);
+	   /* sizeof EMACS_INT == sizeof Lisp_Object */
+	   offset += (sizeof (EMACS_INT)))
+	{
+	  idx = PER_BUFFER_IDX (offset);
+	  if ((idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
+	      && SYMBOLP (PER_BUFFER_SYMBOL (offset)) 
+	      && EQ (PER_BUFFER_SYMBOL (offset), symbol)) 
+	    {
+	      result = PER_BUFFER_VALUE (buf, offset);
+	      found = 1;
+	      break;
+	    }
+	}
+
+      if (!found)
+	result = Fdefault_value (symbol);
+    }
+  else
+    result = XCDR (result);
+
+  if (EQ (result, Qunbound))
+    return Fsignal (Qvoid_variable, Fcons (symbol, Qnil));
+
+  return result;
+}
+
 DEFUN ("buffer-local-variables", Fbuffer_local_variables,
        Sbuffer_local_variables, 0, 1, 0,
        doc: /* Return an alist of variables that are buffer-local in BUFFER.
@@ -5571,6 +5623,7 @@
 /*defsubr (&Sbuffer_number);*/
   defsubr (&Sbuffer_file_name);
   defsubr (&Sbuffer_base_buffer);
+  defsubr (&Sbuffer_local_value);
   defsubr (&Sbuffer_local_variables);
   defsubr (&Sbuffer_modified_p);
   defsubr (&Sset_buffer_modified_p);