292 |
|
|
293 |
/* At garbage collection time, make an undo list shorter at the end, |
/* At garbage collection time, make an undo list shorter at the end, |
294 |
returning the truncated list. |
returning the truncated list. |
295 |
MINSIZE and MAXSIZE are the limits on size allowed, as described below. |
MINSIZE, MAXSIZE and LIMITSIZE are the limits on size allowed, |
296 |
In practice, these are the values of undo-limit and |
as described below. |
297 |
undo-strong-limit. */ |
In practice, these are the values of undo-limit, |
298 |
|
undo-strong-limit, and undo-outer-limit. */ |
299 |
|
|
300 |
Lisp_Object |
Lisp_Object |
301 |
truncate_undo_list (list, minsize, maxsize) |
truncate_undo_list (list, minsize, maxsize, limitsize) |
302 |
Lisp_Object list; |
Lisp_Object list; |
303 |
int minsize, maxsize; |
int minsize, maxsize, limitsize; |
304 |
{ |
{ |
305 |
Lisp_Object prev, next, last_boundary; |
Lisp_Object prev, next, last_boundary; |
306 |
int size_so_far = 0; |
int size_so_far = 0; |
309 |
next = list; |
next = list; |
310 |
last_boundary = Qnil; |
last_boundary = Qnil; |
311 |
|
|
312 |
/* Always preserve at least the most recent undo record. |
/* Always preserve at least the most recent undo record |
313 |
|
unless it is really horribly big. |
314 |
If the first element is an undo boundary, skip past it. |
If the first element is an undo boundary, skip past it. |
315 |
|
|
316 |
Skip, skip, skip the undo, skip, skip, skip the undo, |
Skip, skip, skip the undo, skip, skip, skip the undo, |
325 |
prev = next; |
prev = next; |
326 |
next = XCDR (next); |
next = XCDR (next); |
327 |
} |
} |
328 |
|
|
329 |
while (CONSP (next) && ! NILP (XCAR (next))) |
while (CONSP (next) && ! NILP (XCAR (next))) |
330 |
{ |
{ |
331 |
Lisp_Object elt; |
Lisp_Object elt; |
341 |
+ SCHARS (XCAR (elt))); |
+ SCHARS (XCAR (elt))); |
342 |
} |
} |
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 |
|
|
349 |
/* Advance to next element. */ |
/* Advance to next element. */ |
350 |
prev = next; |
prev = next; |
351 |
next = XCDR (next); |
next = XCDR (next); |
352 |
} |
} |
353 |
|
|
354 |
if (CONSP (next)) |
if (CONSP (next)) |
355 |
last_boundary = prev; |
last_boundary = prev; |
356 |
|
|
357 |
|
/* Keep more if it fits. */ |
358 |
while (CONSP (next)) |
while (CONSP (next)) |
359 |
{ |
{ |
360 |
Lisp_Object elt; |
Lisp_Object elt; |