diff options
| author | Dmitry Antipov | 2012-07-19 12:56:53 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-07-19 12:56:53 +0400 |
| commit | 9cd47b72e021f76a6e2481d986ce4b0cb0b859d3 (patch) | |
| tree | 73912e8be2147fe90acf8f5dd20bb1c238d354df /src/alloc.c | |
| parent | 1d6fc0df363db43f2c1db696fad40f068287500b (diff) | |
| download | emacs-9cd47b72e021f76a6e2481d986ce4b0cb0b859d3.tar.gz emacs-9cd47b72e021f76a6e2481d986ce4b0cb0b859d3.zip | |
Compact buffers when idle.
* lisp/compact.el: New file.
* src/buffer.c (compact_buffer, Fcompact_buffer): New function.
(syms_of_buffer): Register Fcompact_buffer.
* src/alloc.c (Fgarbage_collect): Use compact_buffer.
* src/buffer.h (compact_buffer): New prototype.
(struct buffer_text): New member.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 28 |
1 files changed, 1 insertions, 27 deletions
diff --git a/src/alloc.c b/src/alloc.c index 166f5b72449..233137e368e 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -5413,33 +5413,7 @@ See Info node `(elisp)Garbage Collection'. */) | |||
| 5413 | /* Don't keep undo information around forever. | 5413 | /* Don't keep undo information around forever. |
| 5414 | Do this early on, so it is no problem if the user quits. */ | 5414 | Do this early on, so it is no problem if the user quits. */ |
| 5415 | for_each_buffer (nextb) | 5415 | for_each_buffer (nextb) |
| 5416 | { | 5416 | compact_buffer (nextb); |
| 5417 | /* If a buffer's undo list is Qt, that means that undo is | ||
| 5418 | turned off in that buffer. Calling truncate_undo_list on | ||
| 5419 | Qt tends to return NULL, which effectively turns undo back on. | ||
| 5420 | So don't call truncate_undo_list if undo_list is Qt. */ | ||
| 5421 | if (! NILP (nextb->BUFFER_INTERNAL_FIELD (name)) | ||
| 5422 | && ! EQ (nextb->BUFFER_INTERNAL_FIELD (undo_list), Qt)) | ||
| 5423 | truncate_undo_list (nextb); | ||
| 5424 | |||
| 5425 | /* Shrink buffer gaps, but skip indirect and dead buffers. */ | ||
| 5426 | if (nextb->base_buffer == 0 && !NILP (nextb->BUFFER_INTERNAL_FIELD (name)) | ||
| 5427 | && ! nextb->text->inhibit_shrinking) | ||
| 5428 | { | ||
| 5429 | /* If a buffer's gap size is more than 10% of the buffer | ||
| 5430 | size, or larger than 2000 bytes, then shrink it | ||
| 5431 | accordingly. Keep a minimum size of 20 bytes. */ | ||
| 5432 | int size = min (2000, max (20, (nextb->text->z_byte / 10))); | ||
| 5433 | |||
| 5434 | if (nextb->text->gap_size > size) | ||
| 5435 | { | ||
| 5436 | struct buffer *save_current = current_buffer; | ||
| 5437 | current_buffer = nextb; | ||
| 5438 | make_gap (-(nextb->text->gap_size - size)); | ||
| 5439 | current_buffer = save_current; | ||
| 5440 | } | ||
| 5441 | } | ||
| 5442 | } | ||
| 5443 | 5417 | ||
| 5444 | t1 = current_emacs_time (); | 5418 | t1 = current_emacs_time (); |
| 5445 | 5419 | ||