bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#48264: [PATCH v3 03/15] Add and use BUFFER_DEFAULT_VALUE_P


From: Spencer Baugh
Subject: bug#48264: [PATCH v3 03/15] Add and use BUFFER_DEFAULT_VALUE_P
Date: Thu, 6 May 2021 17:33:34 -0400

This makes the code more clear and allows us to more easily change how
this property is determined.

* src/buffer.h (BUFFER_DEFAULT_VALUE_P):
New function.
* src/buffer.c (reset_buffer_local_variables):
* src/data.c (set_default_internal, Fkill_local_variable):
Use BUFFER_DEFAULT_VALUE_P
---
 src/buffer.c |  2 +-
 src/buffer.h | 10 ++++++++++
 src/data.c   |  5 ++---
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c
index c395c6ec98..3427022ace 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1108,7 +1108,7 @@ reset_buffer_local_variables (struct buffer *b, bool 
permanent_too)
   FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
     {
       int idx = PER_BUFFER_IDX (offset);
-      if ((idx > 0
+      if ((BUFFER_DEFAULT_VALUE_P (offset)
           && (permanent_too
               || buffer_permanent_local_flags[idx] == 0)))
        set_per_buffer_value (b, offset, per_buffer_default (offset));
diff --git a/src/buffer.h b/src/buffer.h
index 7367c2cb2b..2125d1b907 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1481,6 +1481,16 @@ set_per_buffer_value (struct buffer *b, int offset, 
Lisp_Object value)
   *(Lisp_Object *)(offset + (char *) b) = value;
 }
 
+/* Value is true if the variable with offset OFFSET has a default
+   value; false if the variable has no default, and is therefore
+   always local. */
+
+INLINE bool
+BUFFER_DEFAULT_VALUE_P (int offset)
+{
+  return PER_BUFFER_IDX (offset) > 0;
+}
+
 /* Value is true if the variable with offset OFFSET has a local value
    in buffer B.  */
 
diff --git a/src/data.c b/src/data.c
index bd399e0439..9bd935fe09 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1879,13 +1879,12 @@ set_default_internal (Lisp_Object symbol, Lisp_Object 
value,
        if (BUFFER_OBJFWDP (valcontents))
          {
            int offset = XBUFFER_OBJFWD (valcontents)->offset;
-           int idx = PER_BUFFER_IDX (offset);
 
            set_per_buffer_default (offset, value);
 
            /* If this variable is not always local in all buffers,
               set it in the buffers that don't nominally have a local value.  
*/
-           if (idx > 0)
+           if (BUFFER_DEFAULT_VALUE_P (offset))
              {
                Lisp_Object buf, tail;
 
@@ -2157,7 +2156,7 @@ From now on the default value will apply in this buffer.  
Return VARIABLE.  */)
            int offset = XBUFFER_OBJFWD (valcontents)->offset;
            int idx = PER_BUFFER_IDX (offset);
 
-           if (idx > 0)
+           if (BUFFER_DEFAULT_VALUE_P (offset))
              {
                SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
                set_per_buffer_value (current_buffer, offset,
-- 
2.31.1






reply via email to

[Prev in Thread] Current Thread [Next in Thread]