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

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

bug#48264: [PATCH v4 11/14] Set buffer_defaults fields without a default


From: Spencer Baugh
Subject: bug#48264: [PATCH v4 11/14] Set buffer_defaults fields without a default to Qunbound
Date: Fri, 7 May 2021 22:09:02 -0400

In this way, we can be more sure that we aren't accidentally using
these fields.  We can also use the fact that fields without a default
are set to Qunbound to implement BUFFER_DEFAULT_VALUE_P.

* src/buffer.c (init_buffer_once): Set unused buffer_defaults fields
to Qunbound.
* src/buffer.h (BUFFER_DEFAULT_VALUE_P): Check if field is Qunbound to
determine if there's a default.
---
 src/buffer.c | 42 ++++++++++++++++++++++++++++++------------
 src/buffer.h |  6 ++++--
 src/emacs.c  |  4 ++--
 3 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c
index a7d31c1e5b..a5606ce1d1 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -53,7 +53,9 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 /* This structure holds the default values of the buffer-local variables
    defined with DEFVAR_PER_BUFFER, that have special slots in each buffer.
    The default value occupies the same slot in this structure
-   as an individual buffer's value occupies in that buffer.  */
+   as an individual buffer's value occupies in that buffer.
+   Slots in this structure which are set to Qunbound are permanently
+   buffer-local.  */
 
 struct buffer buffer_defaults;
 
@@ -5251,6 +5253,10 @@ init_buffer_once (void)
 
   /* Set up the default values of various buffer slots.  */
   /* Must do these before making the first buffer! */
+  int offset;
+  FOR_EACH_PER_BUFFER_OBJECT_AT (offset)
+    set_per_buffer_default (offset, Qunbound);
+  set_per_buffer_default (PER_BUFFER_VAR_OFFSET (undo_list), Qunbound);
 
   /* real setup is done in bindings.el */
   bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-"));
@@ -5264,13 +5270,9 @@ init_buffer_once (void)
   bset_selective_display_ellipses (&buffer_defaults, Qt);
   bset_abbrev_table (&buffer_defaults, Qnil);
   bset_display_table (&buffer_defaults, Qnil);
-  bset_undo_list (&buffer_defaults, Qnil);
-  bset_mark_active (&buffer_defaults, Qnil);
-  bset_file_format (&buffer_defaults, Qnil);
-  bset_auto_save_file_format (&buffer_defaults, Qt);
-  set_buffer_overlays_before (&buffer_defaults, NULL);
-  set_buffer_overlays_after (&buffer_defaults, NULL);
-  buffer_defaults.overlay_center = BEG;
+  /* Later further initialized by init_{syntax,category}_once.  */
+  BVAR (&buffer_defaults, syntax_table) = Qnil;
+  BVAR (&buffer_defaults, category_table) = Qnil;
 
   XSETFASTINT (BVAR (&buffer_defaults, tab_width), 8);
   bset_truncate_lines (&buffer_defaults, Qnil);
@@ -5284,13 +5286,10 @@ init_buffer_once (void)
   bset_extra_line_spacing (&buffer_defaults, Qnil);
   bset_cursor_in_non_selected_windows (&buffer_defaults, Qt);
 
-  bset_enable_multibyte_characters (&buffer_defaults, Qt);
   bset_buffer_file_coding_system (&buffer_defaults, Qnil);
   XSETFASTINT (BVAR (&buffer_defaults, fill_column), 70);
   XSETFASTINT (BVAR (&buffer_defaults, left_margin), 0);
   bset_cache_long_scans (&buffer_defaults, Qt);
-  bset_file_truename (&buffer_defaults, Qnil);
-  XSETFASTINT (BVAR (&buffer_defaults, display_count), 0);
   XSETFASTINT (BVAR (&buffer_defaults, left_margin_cols), 0);
   XSETFASTINT (BVAR (&buffer_defaults, right_margin_cols), 0);
   bset_left_fringe_width (&buffer_defaults, Qnil);
@@ -5306,7 +5305,6 @@ init_buffer_once (void)
   bset_fringe_cursor_alist (&buffer_defaults, Qnil);
   bset_scroll_up_aggressively (&buffer_defaults, Qnil);
   bset_scroll_down_aggressively (&buffer_defaults, Qnil);
-  bset_display_time (&buffer_defaults, Qnil);
 
   /* Assign the local-flags to the slots that have default values.
      The local flag is a bit that is used in the buffer
@@ -5332,6 +5330,26 @@ init_buffer_once (void)
   DEFSYM (Qkill_buffer_hook, "kill-buffer-hook");
   Fput (Qkill_buffer_hook, Qpermanent_local, Qt);
 
+  /* Sanity check that we didn't set the default for slots which
+     are permanent-buffer-locals.  */
+  eassert (EQ (BVAR (&buffer_defaults, filename), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, directory), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, backed_up), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, save_length), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, auto_save_file_name), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, read_only), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, mode_name), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, undo_list), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, mark_active), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, point_before_scroll), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, file_truename), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, invisibility_spec), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, file_format), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, auto_save_file_format), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, display_count), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, display_time), Qunbound));
+  eassert (EQ (BVAR (&buffer_defaults, enable_multibyte_characters), 
Qunbound));
+
   /* Super-magic invisible buffer.  */
   Vprin1_to_string_buffer =
     Fget_buffer_create (build_pure_c_string (" prin1"), Qt);
diff --git a/src/buffer.h b/src/buffer.h
index 0445fe0edf..728dbb5272 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -1101,7 +1101,9 @@ BUFFER_CHECK_INDIRECTION (struct buffer *b)
 /* This structure holds the default values of the buffer-local variables
    that have special slots in each buffer.
    The default value occupies the same slot in this structure
-   as an individual buffer's value occupies in that buffer.  */
+   as an individual buffer's value occupies in that buffer.
+   Slots in this structure which are set to Qunbound are permanently
+   buffer-local. */
 
 extern struct buffer buffer_defaults;
 
@@ -1473,7 +1475,7 @@ set_per_buffer_value (struct buffer *b, int offset, 
Lisp_Object value)
 INLINE bool
 BVAR_HAS_DEFAULT_VALUE_P (int offset)
 {
-  return PER_BUFFER_IDX (offset) > 0;
+  return !EQ (per_buffer_default (offset), Qunbound);
 }
 
 /* Value is true if the variable with offset OFFSET has a local value
diff --git a/src/emacs.c b/src/emacs.c
index 9157cd84a9..a1ea9d8a8b 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -1787,10 +1787,10 @@ Using an Emacs configured with --with-x-toolkit=lucid 
does not have this problem
       init_eval_once ();
       init_charset_once ();
       init_coding_once ();
-      init_syntax_once ();     /* Create standard syntax table.  */
-      init_category_once ();   /* Create standard category table.  */
       init_casetab_once ();    /* Must be done before init_buffer_once.  */
       init_buffer_once ();     /* Create buffer table and some buffers.  */
+      init_syntax_once ();     /* Create standard syntax table.  */
+      init_category_once ();   /* Create standard category table.  */
       init_minibuf_once ();    /* Create list of minibuffers.  */
                                /* Must precede init_window_once.  */
 
-- 
2.31.1






reply via email to

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