emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] fix/undo-point-in-wrong-place 6b3cfe4 4/4: Prepare for rec


From: Phillip Lord
Subject: [Emacs-diffs] fix/undo-point-in-wrong-place 6b3cfe4 4/4: Prepare for record now separate function.
Date: Fri, 20 Nov 2015 22:13:24 +0000

branch: fix/undo-point-in-wrong-place
commit 6b3cfe42032beac821df09a52865011f4c497821
Author: Phillip Lord <address@hidden>
Commit: Phillip Lord <address@hidden>

    Prepare for record now separate function.
---
 lisp/simple.el |    9 ---------
 problem.org    |   45 +++++++++++++++++++++++++++++++++++++++++++++
 src/undo.c     |   49 ++++++++++++++++++++++---------------------------
 3 files changed, 67 insertions(+), 36 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 24a712a..794871f 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2792,14 +2792,6 @@ with < or <= based on USE-<."
 ;; This section adds a new undo-boundary at either after a command is
 ;; called or in some cases on a timer called after a change is made in
 ;; any buffer.
-(defvar undo-test nil)
-
-(defun undo-test-change ()
-  (when undo-test
-    (with-current-buffer
-        (get-buffer-create "*undo-log*")
-      (insert "a"))))
-
 (defvar-local undo-auto--last-boundary-cause nil
   "Describe the cause of the last undo-boundary.
 
@@ -2860,7 +2852,6 @@ REASON describes the reason that the boundary is being 
added; see
   "Check recently changed buffers and add a boundary if necessary.
 REASON describes the reason that the boundary is being added; see
 `undo-last-boundary' for more information."
-  (undo-test-change)
   (dolist (b undo-auto--undoably-changed-buffers)
           (when (buffer-live-p b)
             (with-current-buffer b
diff --git a/problem.org b/problem.org
index 63105c5..f75df0c 100644
--- a/problem.org
+++ b/problem.org
@@ -231,3 +231,48 @@ way, we need a new way of storing this data which is not 
dependent on
 the buffer before the last.
 
 last_boundary_position should be local?
+
+
+** Walk Though of old undo
+
+Need to read this though backwards!
+
+#+begin_src emacs-lisp
+  (nil
+   (#("want" 0 4
+      (fontified t face font-lock-comment-face))
+    . 39)
+   (#<marker at 39 in *scratch*> . -4)
+   (#<marker at 39 in *scratch*> . -1)
+   (#<marker in no buffer> . -4)
+   (#<marker in no buffer> . -4)
+   43
+   nil
+   (#("buffer" 0 6
+      (fontified t face font-lock-comment-face))
+    . 183)
+   (#<marker at 39 in *scratch*> . -6)
+   (#<marker at 179 in *scratch*> . -4)
+   (#<marker at 179 in *scratch*> . -4)
+   (#<marker in no buffer> . -6)
+   (#<marker in no buffer> . -6)
+   ;; we (were) at the boundary, the last_boundary_buffer was
+   189
+   ;; We are about to delete so record_first_change adds this called
+   ;; from within record_point
+   (t . 0)
+   ;; undo-boundary -- last_boundary_position will be set to 192
+   ;; presumably?
+   nil
+   ;; text inserted -- 192 is after blurb and two new lines
+   (1 . 192)
+   ;; text modified the first time
+   (t . 0))
+#+end_src
+
+
+
+So, we only actually record point in this way before a delete, and
+only from one of the two calls from record_delete
+
+So, we can rewrite record_point into two functions
diff --git a/src/undo.c b/src/undo.c
index 214beae..ade47d1 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -23,10 +23,6 @@ along with GNU Emacs.  If not, see 
<http://www.gnu.org/licenses/>.  */
 #include "lisp.h"
 #include "buffer.h"
 
-/* Position of point last time we inserted a boundary.  */
-static struct buffer *last_boundary_buffer;
-static ptrdiff_t last_boundary_position;
-
 /* 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.
@@ -40,39 +36,42 @@ run_undoable_change (void)
   call0 (Qundo_auto__undoable_change);
 }
 
-/* Record point as it was at beginning of this command (if necessary)
-   and prepare the undo info for recording a change.
+/* Prepare the undo info for recording a change. */
+static void
+prepare_record ()
+{
+  /* Allocate a cons cell to be the undo boundary after this command.  */
+  if (NILP (pending_boundary))
+    pending_boundary = Fcons (Qnil, Qnil);
+
+  run_undoable_change ();
+
+  if (MODIFF <= SAVE_MODIFF)
+    record_first_change ();
+}
+
+/* Record point as it was at beginning of this command.
    PT is the position of point that will naturally occur as a result of the
    undo record that will be added just after this command terminates.  */
-
 static void
 record_point (ptrdiff_t pt)
 {
-  bool at_boundary;
-
   /* Don't record position of pt when undo_inhibit_record_point holds.  */
   if (undo_inhibit_record_point)
     return;
 
-  /* Allocate a cons cell to be the undo boundary after this command.  */
-  if (NILP (pending_boundary))
-    pending_boundary = Fcons (Qnil, Qnil);
-
-  run_undoable_change ();
+  bool at_boundary;
 
   at_boundary = ! CONSP (BVAR (current_buffer, undo_list))
                 || NILP (XCAR (BVAR (current_buffer, undo_list)));
 
-  if (MODIFF <= SAVE_MODIFF)
-    record_first_change ();
+  prepare_record();
 
   /* If we are just after an undo boundary, and
      point wasn't at start of deleted range, record where it was.  */
-  if (at_boundary
-      && current_buffer == last_boundary_buffer
-      && last_boundary_position != pt)
+  if (at_boundary)
     bset_undo_list (current_buffer,
-                   Fcons (make_number (last_boundary_position),
+                   Fcons (make_number (pt),
                           BVAR (current_buffer, undo_list)));
 }
 
@@ -89,7 +88,7 @@ record_insert (ptrdiff_t beg, ptrdiff_t length)
   if (EQ (BVAR (current_buffer, undo_list), Qt))
     return;
 
-  record_point (beg);
+  prepare_record ();
 
   /* If this is following another insertion and consecutive with it
      in the buffer, combine the two.  */
@@ -175,12 +174,12 @@ record_delete (ptrdiff_t beg, Lisp_Object string, bool 
record_markers)
   if (PT == beg + SCHARS (string))
     {
       XSETINT (sbeg, -beg);
-      record_point (PT);
+      prepare_record ();
     }
   else
     {
       XSETFASTINT (sbeg, beg);
-      record_point (beg);
+      record_point (beg + SCHARS (string));
     }
 
   /* primitive-undo assumes marker adjustments are recorded
@@ -286,8 +285,6 @@ but another undo command will undo to the previous 
boundary.  */)
        bset_undo_list (current_buffer,
                        Fcons (Qnil, BVAR (current_buffer, undo_list)));
     }
-  last_boundary_position = PT;
-  last_boundary_buffer = current_buffer;
 
   Fset (Qundo_auto__last_boundary_cause, Qexplicit);
   return Qnil;
@@ -442,8 +439,6 @@ syms_of_undo (void)
   pending_boundary = Qnil;
   staticpro (&pending_boundary);
 
-  last_boundary_buffer = NULL;
-
   defsubr (&Sundo_boundary);
 
   DEFVAR_INT ("undo-limit", undo_limit,



reply via email to

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