aboutsummaryrefslogtreecommitdiffstats
path: root/src/undo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/undo.c')
-rw-r--r--src/undo.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/undo.c b/src/undo.c
index dd086db6c40..9fdc46a3b13 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -292,14 +292,15 @@ but another undo command will undo to the previous boundary. */)
292 292
293/* At garbage collection time, make an undo list shorter at the end, 293/* At garbage collection time, make an undo list shorter at the end,
294 returning the truncated list. 294 returning the truncated list.
295 MINSIZE and MAXSIZE are the limits on size allowed, as described below. 295 MINSIZE, MAXSIZE and LIMITSIZE are the limits on size allowed,
296 In practice, these are the values of undo-limit and 296 as described below.
297 undo-strong-limit. */ 297 In practice, these are the values of undo-limit,
298 undo-strong-limit, and undo-outer-limit. */
298 299
299Lisp_Object 300Lisp_Object
300truncate_undo_list (list, minsize, maxsize) 301truncate_undo_list (list, minsize, maxsize, limitsize)
301 Lisp_Object list; 302 Lisp_Object list;
302 int minsize, maxsize; 303 int minsize, maxsize, limitsize;
303{ 304{
304 Lisp_Object prev, next, last_boundary; 305 Lisp_Object prev, next, last_boundary;
305 int size_so_far = 0; 306 int size_so_far = 0;
@@ -308,7 +309,8 @@ truncate_undo_list (list, minsize, maxsize)
308 next = list; 309 next = list;
309 last_boundary = Qnil; 310 last_boundary = Qnil;
310 311
311 /* Always preserve at least the most recent undo record. 312 /* Always preserve at least the most recent undo record
313 unless it is really horribly big.
312 If the first element is an undo boundary, skip past it. 314 If the first element is an undo boundary, skip past it.
313 315
314 Skip, skip, skip the undo, skip, skip, skip the undo, 316 Skip, skip, skip the undo, skip, skip, skip the undo,
@@ -323,6 +325,7 @@ truncate_undo_list (list, minsize, maxsize)
323 prev = next; 325 prev = next;
324 next = XCDR (next); 326 next = XCDR (next);
325 } 327 }
328
326 while (CONSP (next) && ! NILP (XCAR (next))) 329 while (CONSP (next) && ! NILP (XCAR (next)))
327 { 330 {
328 Lisp_Object elt; 331 Lisp_Object elt;
@@ -338,13 +341,20 @@ truncate_undo_list (list, minsize, maxsize)
338 + SCHARS (XCAR (elt))); 341 + SCHARS (XCAR (elt)));
339 } 342 }
340 343
344 /* If we reach LIMITSIZE before the first boundary,
345 we're heading for memory full, so truncate the list to nothing. */
346 if (size_so_far > limitsize)
347 return Qnil;
348
341 /* Advance to next element. */ 349 /* Advance to next element. */
342 prev = next; 350 prev = next;
343 next = XCDR (next); 351 next = XCDR (next);
344 } 352 }
353
345 if (CONSP (next)) 354 if (CONSP (next))
346 last_boundary = prev; 355 last_boundary = prev;
347 356
357 /* Keep more if it fits. */
348 while (CONSP (next)) 358 while (CONSP (next))
349 { 359 {
350 Lisp_Object elt; 360 Lisp_Object elt;