From: Keith David Bershatsky <esq@lawlist.com>
To: 27214@debbugs.gnu.org
Subject: bug#27214: truncate_undo_list in undo.c: exclusions, warnings, documentation.
Date: Wed, 19 Jul 2017 15:41:27 -0700 [thread overview]
Message-ID: <m2y3rkvylk.wl%esq@lawlist.com> (raw)
In-Reply-To: <m2d1aldkr3.wl%esq@lawlist.com>
I opted to prevent truncate_undo_list from truncating the buffer-undo-list when undo-tree-canary is present, except if the undo-outer-limit is exceeded. Here is the revision:
/* 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.
In some cases this works by calling undo-outer-limit-function. */
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;
}
}
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */
/* undo-tree */
if (CONSP (list)
&& ! NILP (Fmemq (Qundo_tree_canary, 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))
;
/* Truncate at the boundary where we decided to truncate. */
else if (!NILP (last_boundary))
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);
}
\f
void
syms_of_undo (void)
{
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */
/* undo-tree */
DEFSYM (Qundo_tree_canary, "undo-tree-canary");
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; */
* * *
prev parent reply other threads:[~2017-07-19 22:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-03 17:49 bug#27214: truncate_undo_list in undo.c: exclusions, warnings, documentation Keith David Bershatsky
2017-07-05 14:17 ` Keith David Bershatsky
2017-07-19 22:41 ` Keith David Bershatsky [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m2y3rkvylk.wl%esq@lawlist.com \
--to=esq@lawlist.com \
--cc=27214@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.