GNU bug report logs -
#27214
truncate_undo_list in undo.c: exclusions, warnings, documentation.
Previous Next
Full log
Message #8 received at 27214 <at> debbugs.gnu.org (full text, mbox):
Here is an example of how I am modifying `undo.c` for my own usage, which is specifically tailored to the undo-tree.el library and also the fork that I am working on:
In the definition for `syms_of_undo`, add the following:
DEFSYM (Qundo_tree_canary, "undo-tree-canary");
And, modify `truncate_undo_list` as follows -- the modified section is labeled with an "undo-tree" notation:
void
truncate_undo_list (struct buffer *b)
{
Lisp_Object list;
Lisp_Object prev, next, last_boundary;
EMACS_INT size_so_far = 0;
/* Make sure that calling undo-outer-limit-function
won't cause another GC. */
ptrdiff_t count = inhibit_garbage_collection ();
/* Make the buffer current to get its local values of variables such
as undo_limit. Also so that Vundo_outer_limit_function can
tell which buffer to operate on. */
record_unwind_current_buffer ();
set_buffer_internal (b);
list = BVAR (b, undo_list);
prev = Qnil;
next = list;
last_boundary = Qnil;
/* If the first element is an undo boundary, skip past it. */
if (CONSP (next) && NILP (XCAR (next)))
{
/* Add in the space occupied by this element and its chain link. */
size_so_far += sizeof (struct Lisp_Cons);
/* Advance to next element. */
prev = next;
next = XCDR (next);
}
/* Always preserve at least the most recent undo record
unless it is really horribly big.
Skip, skip, skip the undo, skip, skip, skip the undo,
Skip, skip, skip the undo, skip to the undo bound'ry. */
while (CONSP (next) && ! NILP (XCAR (next)))
{
Lisp_Object elt;
elt = XCAR (next);
/* Add in the space occupied by this element and its chain link. */
size_so_far += sizeof (struct Lisp_Cons);
if (CONSP (elt))
{
size_so_far += sizeof (struct Lisp_Cons);
if (STRINGP (XCAR (elt)))
size_so_far += (sizeof (struct Lisp_String) - 1
+ SCHARS (XCAR (elt)));
}
/* Advance to next element. */
prev = next;
next = XCDR (next);
}
/* If by the first boundary we have already passed undo_outer_limit,
we're heading for memory full, so offer to clear out the list. */
if (INTEGERP (Vundo_outer_limit)
&& size_so_far > XINT (Vundo_outer_limit)
&& !NILP (Vundo_outer_limit_function))
{
Lisp_Object tem;
/* Normally the function this calls is undo-outer-limit-truncate. */
tem = call1 (Vundo_outer_limit_function, make_number (size_so_far));
if (! NILP (tem))
{
/* The function is responsible for making
any desired changes in buffer-undo-list. */
unbind_to (count, Qnil);
return;
}
}
if (CONSP (next))
last_boundary = prev;
/* Keep additional undo data, if it fits in the limits. */
while (CONSP (next))
{
Lisp_Object elt;
elt = XCAR (next);
/* When we get to a boundary, decide whether to truncate
either before or after it. The lower threshold, undo_limit,
tells us to truncate after it. If its size pushes past
the higher threshold undo_strong_limit, we truncate before it. */
if (NILP (elt))
{
if (size_so_far > undo_strong_limit)
break;
last_boundary = prev;
if (size_so_far > undo_limit)
break;
}
/* Add in the space occupied by this element and its chain link. */
size_so_far += sizeof (struct Lisp_Cons);
if (CONSP (elt))
{
size_so_far += sizeof (struct Lisp_Cons);
if (STRINGP (XCAR (elt)))
size_so_far += (sizeof (struct Lisp_String) - 1
+ SCHARS (XCAR (elt)));
}
/* Advance to next element. */
prev = next;
next = XCDR (next);
}
/* If we scanned the whole list, it is short enough; don't change it. */
if (NILP (next))
;
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */
/* undo-tree */
/* Truncate at the boundary where we decided to truncate. */
else if (!NILP (last_boundary))
{
if (Fmemq (Qundo_tree_canary, last_boundary))
{
AUTO_STRING (my_string, "truncate_undo_list: %s");
CALLN (Fmessage, my_string, last_boundary);
}
else
XSETCDR (last_boundary, Qnil);
}
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */
/* There's nothing we decided to keep, so clear it out. */
else
bset_undo_list (b, Qnil);
unbind_to (count, Qnil);
}
This bug report was last modified 7 years and 333 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.