summaryrefslogtreecommitdiff
path: root/src/undo.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1994-03-08 16:33:28 +0000
committerRichard M. Stallman <rms@gnu.org>1994-03-08 16:33:28 +0000
commit5e15258c884685c9ea94b233593e8d00a0a39dcc (patch)
tree6685cc2f968ec56060430c9e35ace5c857b5edad /src/undo.c
parentb59cfd6e2e4d682fd84f20004f0df1973a4f6bf1 (diff)
downloademacs-5e15258c884685c9ea94b233593e8d00a0a39dcc.tar.gz
(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.
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/undo.c b/src/undo.c
index 64f773d62c8..683fa66b89a 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -29,6 +29,13 @@ Lisp_Object last_undo_buffer;
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 @@ record_insert (beg, length)
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 @@ record_delete (beg, length)
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 @@ record_property_change (beg, length, prop, value, buffer)
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 @@ but another undo command will undo to the previous boundary.")
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 @@ syms_of_undo ()
Qinhibit_read_only = intern ("inhibit-read-only");
staticpro (&Qinhibit_read_only);
+ pending_boundary = Qnil;
+ staticpro (&pending_boundary);
+
defsubr (&Sprimitive_undo);
defsubr (&Sundo_boundary);
}