emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 0f3c1db: C


From: Phillip Lord
Subject: [Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 0f3c1db: Changed semantics of first-undoable-change-hook.
Date: Mon, 28 Sep 2015 13:49:36 +0000

branch: fix/no-undo-boundary-on-secondary-buffer-change
commit 0f3c1db57fd55be30c212947e85a9f218285444b
Author: Phillip Lord <address@hidden>
Commit: Phillip Lord <address@hidden>

    Changed semantics of first-undoable-change-hook.
    
    autoboundary now runs on post-command-hook as well as timer.
    Created a temporary logger to test that it's all working.
---
 lisp/simple.el |   41 ++++++++++++++++++++++++++++-------------
 src/undo.c     |   50 +++++++++++++++++++++++++-------------------------
 2 files changed, 53 insertions(+), 38 deletions(-)

diff --git a/lisp/simple.el b/lisp/simple.el
index 68299cb..7aa3598 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -2766,12 +2766,25 @@ with < or <= based on USE-<."
 ;; removed from a buffer with any rapidity and no undo-boundary. In
 ;; this case, the `undo-outer-limit' machinary will operate; this is
 ;; considered to be exceptional the user is warned.
-(defun undo-has-two-boundary-p ()
-  "Returns t if `buffer-undo-list' contains a boundary."
-  (when
-      (member nil
-              (member nil buffer-undo-list))
-    t))
+(defmacro undo-auto-message (&rest args)
+  `(with-current-buffer
+       (get-buffer-create
+        "*undo-auto-log*")
+     (goto-char (point-max))
+     (insert (format ,@args))
+     (insert "\n")))
+
+(undo-auto-message "initialized")
+(with-current-buffer "*undo-auto-log*"
+  (setq buffer-undo-list t))
+
+(defun undo-needs-boundary-p ()
+  "Returns t if `buffer-undo-list' needs a boundary at the start."
+  (and
+   ;; buffer-undo-list can be t
+   (listp buffer-undo-list)
+   ;; first element of buffer-undo-list is nil
+   (not (car buffer-undo-list))))
 
 (defun undo-ensure-boundary ()
   "Add an `undo-boundary' if `buffer-undo-list' is long.
@@ -2795,9 +2808,7 @@ for adding an `undo-boundary' which retains data where 
possible,
 without signalling warnings to the user."
   (when (and
          buffer-undo-list
-         (not (undo-has-two-boundary-p))
-         (> (undo-size)
-            undo-limit))
+         (undo-needs-boundary-p))
     (undo-boundary)
     t))
 
@@ -2809,10 +2820,9 @@ See also `undo-ensure-boundary'."
    (lambda (b)
      (when (buffer-live-p b)
        (with-current-buffer b
-         (message "undo-auto-boundary checking %s" b)
-         (setq undo-buffer-undoably-changed nil)
+         (undo-auto-message "undo-auto-boundary checking %s" b)
          (when (undo-ensure-boundary)
-           (message "undo-auto-boundary boundary added %s" b)))))
+           (undo-auto-message "undo-auto-boundary boundary added %s" b)))))
    undo-undoably-changed-buffers)
   (setq undo-undoably-changed-buffers nil))
 
@@ -2821,12 +2831,14 @@ See also `undo-ensure-boundary'."
 
 (defun undo-auto-boundary-timer ()
   "Timer which will run `undo-auto-boundary-timer'."
+  (undo-auto-message "running on timer")
   (undo-auto-boundary)
   (setq undo-auto-current-boundary-timer nil))
 
 (defun undo-auto-boundary-ensure-timer ()
   "Ensure that the `undo-auto-boundary-timer is set."
   (unless undo-auto-current-boundary-timer
+    (undo-auto-message "Starting timer")
     (setq undo-auto-current-boundary-timer
           (run-at-time 10 nil 'undo-auto-boundary-timer))))
 
@@ -2842,13 +2854,16 @@ See also `undo-buffer-undoably-changed'.")
 
 (defun undo-auto-boundary-first-undoable-change-hook ()
   "Default value of `undo-boundary-first-undoable-change-hook'."
-  (message "undo-auto adding-to-list %s" (current-buffer))
+  (undo-auto-message "undo-auto adding-to-list %s" (current-buffer))
   (add-to-list 'undo-undoably-changed-buffers (current-buffer))
   (undo-auto-boundary-ensure-timer))
 
 (add-hook 'undo-first-undoable-change-hook
           #'undo-auto-boundary-first-undoable-change-hook)
 
+(add-hook 'post-command-hook
+          #'undo-auto-boundary)
+
 (defcustom undo-ask-before-discard nil
   "If non-nil ask about discarding undo info for the current command.
 Normally, Emacs discards the undo info for the current command if
diff --git a/src/undo.c b/src/undo.c
index 9f9dece..a5776be 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -37,6 +37,25 @@ static ptrdiff_t last_boundary_position;
    an undo-boundary.  */
 static Lisp_Object pending_boundary;
 
+
+/*
+  Run the first-undo-hook if needed
+ */
+void
+run_first_undo_hook()
+{
+  Lisp_Object list;
+
+  list = BVAR(current_buffer, undo_list);
+
+  if (CONSP (list) && NILP (XCAR (list)))
+    {
+      safe_run_hooks(Qundo_first_undoable_change_hook);
+    }
+}
+
+
+
 /* Record point as it was at beginning of this command (if necessary)
    and prepare the undo info for recording a change.
    PT is the position of point that will naturally occur as a result of the
@@ -55,10 +74,7 @@ record_point (ptrdiff_t pt)
   if (NILP (pending_boundary))
     pending_boundary = Fcons (Qnil, Qnil);
 
-  if(NILP (Vundo_buffer_undoably_changed)){
-    Fset (Qundo_buffer_undoably_changed,Qt);
-    safe_run_hooks (Qundo_first_undoable_change_hook);
-  }
+  run_first_undo_hook(current_buffer);
 
   at_boundary = ! CONSP (BVAR (current_buffer, undo_list))
                 || NILP (XCAR (BVAR (current_buffer, undo_list)));
@@ -131,10 +147,7 @@ record_marker_adjustments (ptrdiff_t from, ptrdiff_t to)
     pending_boundary = Fcons (Qnil, Qnil);
 
 
-  if(NILP (Vundo_buffer_undoably_changed)){
-    Fset (Qundo_buffer_undoably_changed,Qt);
-    safe_run_hooks (Qundo_first_undoable_change_hook);
-  }
+  run_first_undo_hook(current_buffer);
 
   for (m = BUF_MARKERS (current_buffer); m; m = m->next)
     {
@@ -248,14 +261,11 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
   if (NILP (pending_boundary))
     pending_boundary = Fcons (Qnil, Qnil);
 
-  if(NILP (Vundo_buffer_undoably_changed)){
-    Fset (Qundo_buffer_undoably_changed,Qt);
-    safe_run_hooks (Qundo_first_undoable_change_hook);
-  }
-
   /* Switch temporarily to the buffer that was changed.  */
   current_buffer = buf;
 
+  run_first_undo_hook(buf);
+
   if (MODIFF <= SAVE_MODIFF)
     record_first_change ();
 
@@ -268,6 +278,7 @@ record_property_change (ptrdiff_t beg, ptrdiff_t length,
   current_buffer = obuf;
 }
 
+
 DEFUN ("undo-boundary", Fundo_boundary, Sundo_boundary, 0, 0, 0,
        doc: /* Mark a boundary between units of undo.
 An undo command will stop at this point,
@@ -492,7 +503,6 @@ syms_of_undo (void)
 {
   DEFSYM (Qinhibit_read_only, "inhibit-read-only");
   DEFSYM (Qundo_first_undoable_change_hook, "undo-first-undoable-change-hook");
-  DEFSYM (Qundo_buffer_undoably_changed, "undo-buffer-undoably-changed");
 
   /* Marker for function call undo list elements.  */
   DEFSYM (Qapply, "apply");
@@ -564,16 +574,6 @@ so it must make sure not to do a lot of consing.  */);
                doc: /* Normal hook run when a buffer has its first recent 
undo-able change.
 
 This hook will be run with `current-buffer' as the buffer that has
-changed.  Recent means since the value of
-`undo-buffer-undoably-changed' was last set to nil. */);
+changed.  Recent means since the last boundary. */);
   Vundo_first_undoable_change_hook = Qnil;
-
-  DEFVAR_LISP ("undo-buffer-undoably-changed",
-               Vundo_buffer_undoably_changed,
-               doc: /* Non-nil means that that the buffer has had a recent 
undo-able change.
-
-Recent means since the value of this variable was last set explicitly to nil,
-usually as part of the undo machinary.*/);
-
-  Fmake_variable_buffer_local (Qundo_buffer_undoably_changed);
 }



reply via email to

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