changeset 6254:a147d798ed0d

(syms_of_undo): staticpro pending_boundary. (pending_boundary): New variable. (syms_of_undo): Initialize it. (Fundo_boundary): Use pending_boundary. (record_insert, record_delete, record_property_change): Set pending_boundary.
author Richard M. Stallman <rms@gnu.org>
date Tue, 08 Mar 1994 16:33:28 +0000
parents 42914264b095
children 277d9ace9f5d
files src/undo.c
diffstat 1 files changed, 35 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/undo.c	Tue Mar 08 06:53:48 1994 +0000
+++ b/src/undo.c	Tue Mar 08 16:33:28 1994 +0000
@@ -29,6 +29,13 @@
 
 Lisp_Object Qinhibit_read_only;
 
+/* The first time a command records something for undo.
+   it also allocates the undo-boundary object
+   which will be added to the list at the end of the command.
+   This ensures we can't run out of space while trying to make
+   an undo-boundary.  */
+Lisp_Object pending_boundary;
+
 /* Record an insertion that just happened or is about to happen,
    for LENGTH characters at position BEG.
    (It is possible to record an insertion before or after the fact
@@ -42,6 +49,10 @@
   if (EQ (current_buffer->undo_list, Qt))
     return;
 
+  /* Allocate a cons cell to be the undo boundary after this command.  */
+  if (NILP (pending_boundary))
+    pending_boundary = Fcons (Qnil, Qnil);
+
   if (current_buffer != XBUFFER (last_undo_buffer))
     Fundo_boundary ();
   XSET (last_undo_buffer, Lisp_Buffer, current_buffer);
@@ -82,6 +93,10 @@
   if (EQ (current_buffer->undo_list, Qt))
     return;
 
+  /* Allocate a cons cell to be the undo boundary after this command.  */
+  if (NILP (pending_boundary))
+    pending_boundary = Fcons (Qnil, Qnil);
+
   if (current_buffer != XBUFFER (last_undo_buffer))
     Fundo_boundary ();
   XSET (last_undo_buffer, Lisp_Buffer, current_buffer);
@@ -151,6 +166,10 @@
   if (EQ (XBUFFER (buffer)->undo_list, Qt))
     return;
 
+  /* Allocate a cons cell to be the undo boundary after this command.  */
+  if (NILP (pending_boundary))
+    pending_boundary = Fcons (Qnil, Qnil);
+
   if (!EQ (buffer, last_undo_buffer))
     boundary = 1;
   last_undo_buffer = buffer;
@@ -183,7 +202,19 @@
     return Qnil;
   tem = Fcar (current_buffer->undo_list);
   if (!NILP (tem))
-    current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list);
+    {
+      /* One way or another, cons nil onto the front of the undo list.  */
+      if (!NILP (pending_boundary))
+	{
+	  /* If we have preallocated the cons cell to use here,
+	     use that one.  */
+	  XCONS (pending_boundary)->cdr = current_buffer->undo_list;
+	  current_buffer->undo_list = pending_boundary;
+	  pending_boundary = Qnil;
+	}
+      else
+	current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list);
+    }
   return Qnil;
 }
 
@@ -425,6 +456,9 @@
   Qinhibit_read_only = intern ("inhibit-read-only");
   staticpro (&Qinhibit_read_only);
 
+  pending_boundary = Qnil;
+  staticpro (&pending_boundary);
+
   defsubr (&Sprimitive_undo);
   defsubr (&Sundo_boundary);
 }