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 032bbe7 1/


From: Phillip Lord
Subject: [Emacs-diffs] fix/no-undo-boundary-on-secondary-buffer-change 032bbe7 1/2: Add an `undo-size' function.
Date: Fri, 21 Aug 2015 09:36:07 +0000

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

    Add an `undo-size' function.
    
    This function reports the size of the current buffer-undo-list in a way
    which is comparable to `undo-limit' and associated variables.
    Previously, it was not possible to access this information from lisp.
---
 src/undo.c |   38 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/src/undo.c b/src/undo.c
index 1bc32c6..2b7bd3d 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -282,6 +282,43 @@ but another undo command will undo to the previous 
boundary.  */)
   return Qnil;
 }
 
+DEFUN ("undo-size", Fundo_size, Sundo_size, 0, 0, 0,
+       doc: /* Return the size of `buffer-undo-list'.
+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)
+{
+  // 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;
+
+  prev = Qnil;
+  next = BVAR (current_buffer, undo_list);
+
+  while(CONSP (next))
+    {
+      Lisp_Object elt;
+      elt = XCAR (next);
+
+      size_so_far += sizeof (struct Lisp_Cons);
+      if (CONSP (elt))
+        {
+          if (STRINGP (XCAR (elt)))
+            size_so_far += (sizeof (struct Lisp_String) - 1
+                            + SCHARS (XCAR (elt)));
+        }
+
+      // and advance
+      prev = next;
+      next = XCDR (next);
+    }
+
+  return make_number (size_so_far);
+ }
+
 /* At garbage collection time, make an undo list shorter at the end,
    returning the truncated list.  How this is done depends on the
    variables undo-limit, undo-strong-limit and undo-outer-limit.
@@ -430,6 +467,7 @@ syms_of_undo (void)
 
   last_boundary_buffer = NULL;
 
+  defsubr (&Sundo_size);
   defsubr (&Sundo_boundary);
 
   DEFVAR_INT ("undo-limit", undo_limit,



reply via email to

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