changeset 93663:959f4471c16e

(last_boundary_buffer, last_boundary_position): New vars. (Fundo_boundary): Set them. (syms_of_undo): Initialize them. (record_point): Use them instead of last_point_position*. (last_undo_buffer): Change type.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 04 Apr 2008 16:59:52 +0000
parents 3f94f995598c
children c7dd307b0ec5
files src/ChangeLog src/undo.c
diffstat 2 files changed, 39 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Apr 04 16:16:23 2008 +0000
+++ b/src/ChangeLog	Fri Apr 04 16:59:52 2008 +0000
@@ -1,7 +1,15 @@
+2008-04-04  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* undo.c (last_boundary_buffer, last_boundary_position): New vars.
+	(Fundo_boundary): Set them.
+	(syms_of_undo): Initialize them.
+	(record_point): Use them instead of last_point_position*.
+	(last_undo_buffer): Change type.
+
 2008-04-04  Jason Rumney  <jasonr@gnu.org>
 
 	* w32uniscribe.c (uniscribe_check_otf): Fix last change.
-	(uniscribe_check_otf): Add GC protection before consing. 
+	(uniscribe_check_otf): Add GC protection before consing.
 	Rearrange loop for counting features.
 
 2008-04-03  Stefan Monnier  <monnier@iro.umontreal.ca>
@@ -52,7 +60,7 @@
 	Handle :otf spec for uniscribe backend.
 	(add_font_entity_to_list): Match truetype fonts in uniscribe backend.
 	(fill_in_logfont): Use DEFAULT_CHARSET when charset not supplied.
-	
+
 	* w32fns.c (Fx_create_frame): Conditionally register uniscribe
 	font backend.
 	(globals_of_w32fns): Initialize uniscribe font backend.
--- a/src/undo.c	Fri Apr 04 16:16:23 2008 +0000
+++ b/src/undo.c	Fri Apr 04 16:59:52 2008 +0000
@@ -38,7 +38,12 @@
 Lisp_Object Vundo_outer_limit_function;
 
 /* Last buffer for which undo information was recorded.  */
-Lisp_Object last_undo_buffer;
+/* BEWARE: This is not traced by the GC, so never dereference it!  */
+struct buffer *last_undo_buffer;
+
+/* Position of point last time we inserted a boundary.  */
+struct buffer *last_boundary_buffer;
+EMACS_INT last_boundary_position;
 
 Lisp_Object Qinhibit_read_only;
 
@@ -68,11 +73,7 @@
 {
   int at_boundary;
 
-  /* Don't record position of pt when undo_inhibit_record_point holds.
-     Needed to avoid inserting a position record in buffer-undo-list
-     when last_point_position has not been set up correctly by
-     command_loop_1, for example, when running a repeat-repeat-char
-     event.  */
+  /* Don't record position of pt when undo_inhibit_record_point holds.  */
   if (undo_inhibit_record_point)
     return;
 
@@ -80,10 +81,9 @@
   if (NILP (pending_boundary))
     pending_boundary = Fcons (Qnil, Qnil);
 
-  if (!BUFFERP (last_undo_buffer)
-      || current_buffer != XBUFFER (last_undo_buffer))
+  if (current_buffer != last_undo_buffer)
     Fundo_boundary ();
-  XSETBUFFER (last_undo_buffer, current_buffer);
+  last_undo_buffer = current_buffer;
 
   if (CONSP (current_buffer->undo_list))
     {
@@ -113,19 +113,10 @@
   /* If we are just after an undo boundary, and
      point wasn't at start of deleted range, record where it was.  */
   if (at_boundary
-      && BUFFERP (last_point_position_buffer)
-      /* If we're called from batch mode, this could be nil.  */
-      && current_buffer == XBUFFER (last_point_position_buffer))
-    {
-      /* If we have switched windows, use the point value
-	 from the window we are in.  */
-      if (! EQ (last_point_position_window, selected_window))
-	last_point_position = marker_position (XWINDOW (selected_window)->pointm);
-
-      if (last_point_position != pt)
-	current_buffer->undo_list
-	  = Fcons (make_number (last_point_position), current_buffer->undo_list);
-    }
+      && current_buffer == last_boundary_buffer
+      && last_boundary_position != pt)
+    current_buffer->undo_list
+      = Fcons (make_number (last_boundary_position), current_buffer->undo_list);
 }
 
 /* Record an insertion that just happened or is about to happen,
@@ -211,10 +202,9 @@
   if (NILP (pending_boundary))
     pending_boundary = Fcons (Qnil, Qnil);
 
-  if (!BUFFERP (last_undo_buffer)
-      || current_buffer != XBUFFER (last_undo_buffer))
+  if (current_buffer != last_undo_buffer)
     Fundo_boundary ();
-  XSETBUFFER (last_undo_buffer, current_buffer);
+  last_undo_buffer = current_buffer;
 
   current_buffer->undo_list
     = Fcons (Fcons (marker, make_number (adjustment)),
@@ -246,10 +236,9 @@
   if (EQ (current_buffer->undo_list, Qt))
     return;
 
-  if (!BUFFERP (last_undo_buffer)
-      || current_buffer != XBUFFER (last_undo_buffer))
+  if (current_buffer != last_undo_buffer)
     Fundo_boundary ();
-  XSETBUFFER (last_undo_buffer, current_buffer);
+  last_undo_buffer = current_buffer;
 
   if (base_buffer->base_buffer)
     base_buffer = base_buffer->base_buffer;
@@ -268,22 +257,22 @@
      Lisp_Object prop, value, buffer;
 {
   Lisp_Object lbeg, lend, entry;
-  struct buffer *obuf = current_buffer;
+  struct buffer *obuf = current_buffer, *buf = XBUFFER (buffer);
   int boundary = 0;
 
-  if (EQ (XBUFFER (buffer)->undo_list, Qt))
+  if (EQ (buf->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))
+  if (buf != last_undo_buffer)
     boundary = 1;
-  last_undo_buffer = buffer;
+  last_undo_buffer = buf;
 
   /* Switch temporarily to the buffer that was changed.  */
-  current_buffer = XBUFFER (buffer);
+  current_buffer = buf;
 
   if (boundary)
     Fundo_boundary ();
@@ -323,6 +312,8 @@
       else
 	current_buffer->undo_list = Fcons (Qnil, current_buffer->undo_list);
     }
+  last_boundary_position = PT;
+  last_boundary_buffer = current_buffer;
   return Qnil;
 }
 
@@ -398,7 +389,8 @@
       && size_so_far > XINT (Vundo_outer_limit)
       && !NILP (Vundo_outer_limit_function))
     {
-      Lisp_Object temp = last_undo_buffer, tem;
+      Lisp_Object tem;
+      struct buffer *temp = last_undo_buffer;
 
       /* Normally the function this calls is undo-outer-limit-truncate.  */
       tem = call1 (Vundo_outer_limit_function, make_number (size_so_far));
@@ -679,6 +671,9 @@
   pending_boundary = Qnil;
   staticpro (&pending_boundary);
 
+  last_undo_buffer = NULL;
+  last_boundary_buffer = NULL;
+
   defsubr (&Sprimitive_undo);
   defsubr (&Sundo_boundary);