(Info-fontify-node): Add mouse-face properties.
[bpt/emacs.git] / src / undo.c
index 3d71516..683fa66 100644 (file)
@@ -22,12 +22,20 @@ and this notice must be preserved on all copies.  */
 #include <config.h>
 #include "lisp.h"
 #include "buffer.h"
+#include "commands.h"
 
 /* Last buffer for which undo information was recorded.  */
 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
@@ -41,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);
@@ -81,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);
@@ -95,10 +111,10 @@ record_delete (beg, length)
   XFASTINT (lbeg) = beg;
   XFASTINT (lend) = beg + length;
 
-  /* If point isn't at start of deleted range, record where it is.  */
-  if (PT != XFASTINT (sbeg))
+  /* If point wasn't at start of deleted range, record where it was.  */
+  if (last_point_position != XFASTINT (sbeg))
     current_buffer->undo_list
-      = Fcons (make_number (PT), current_buffer->undo_list);
+      = Fcons (make_number (last_point_position), current_buffer->undo_list);
 
   current_buffer->undo_list
     = Fcons (Fcons (Fbuffer_substring (lbeg, lend), sbeg),
@@ -123,6 +139,14 @@ record_change (beg, length)
 record_first_change ()
 {
   Lisp_Object high, low;
+
+  if (EQ (current_buffer->undo_list, Qt))
+    return;
+
+  if (current_buffer != XBUFFER (last_undo_buffer))
+    Fundo_boundary ();
+  XSET (last_undo_buffer, Lisp_Buffer, current_buffer);
+
   XFASTINT (high) = (current_buffer->modtime >> 16) & 0xffff;
   XFASTINT (low) = current_buffer->modtime & 0xffff;
   current_buffer->undo_list = Fcons (Fcons (Qt, Fcons (high, low)), current_buffer->undo_list);
@@ -139,9 +163,13 @@ record_property_change (beg, length, prop, value, buffer)
   struct buffer *obuf = current_buffer;
   int boundary = 0;
 
-  if (EQ (current_buffer->undo_list, Qt))
+  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;
@@ -174,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;
 }
 
@@ -416,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);
 }