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 c7a6601 1/


From: Phillip Lord
Subject: [Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change c7a6601 1/5: undo-size can count number of boundaries.
Date: Tue, 15 Sep 2015 15:21:29 +0000

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

    undo-size can count number of boundaries.
    
    undo-size can now take one argument which counts the number of
    boundaries before it returns (or count the entire size).
---
 src/undo.c |   24 ++++++++++++++++++++----
 1 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/undo.c b/src/undo.c
index 2b7bd3d..2169d6e 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -282,18 +282,26 @@ but another undo command will undo to the previous 
boundary.  */)
   return Qnil;
 }
 
-DEFUN ("undo-size", Fundo_size, Sundo_size, 0, 0, 0,
+DEFUN ("undo-size", Fundo_size, Sundo_size, 0, 1, 0,
        doc: /* Return the size of `buffer-undo-list'.
-Returns nil if `buffer-undo-list' is t, that is there is no undo list.
+
+If n count till the end of the nth boundary, or the whole list iff n
+is zero.
+
+Returns nil if `buffer-undo-list' is t; that is there is no undo list.
 Otherwise, returns the size of `buffer-undo-list' in bytes.*/)
-     (void)
+     (Lisp_Object n)
 {
   // we do not have an undo_list anyway
   if (EQ (BVAR (current_buffer, undo_list), Qt))
     return Qnil;
 
   Lisp_Object prev, next;
-  EMACS_INT size_so_far = 0;
+  EMACS_INT size_so_far, boundary_so_far, num;
+  if(n){
+    CHECK_NUMBER(n);
+    num = XINT(n);
+  }
 
   prev = Qnil;
   next = BVAR (current_buffer, undo_list);
@@ -306,6 +314,14 @@ Otherwise, returns the size of `buffer-undo-list' in 
bytes.*/)
       size_so_far += sizeof (struct Lisp_Cons);
       if (CONSP (elt))
         {
+          // we have a boundary, so check we do not have too many
+          if (XCAR (elt) == Qnil)
+            {
+              boundary_so_far = boundary_so_far + 1;
+              if(boundary_so_far >= num)
+                break;
+            }
+
           if (STRINGP (XCAR (elt)))
             size_so_far += (sizeof (struct Lisp_String) - 1
                             + SCHARS (XCAR (elt)));



reply via email to

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