summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorDmitry Antipov <dmantipov@yandex.ru>2012-07-19 12:56:53 +0400
committerDmitry Antipov <dmantipov@yandex.ru>2012-07-19 12:56:53 +0400
commit9cd47b72e021f76a6e2481d986ce4b0cb0b859d3 (patch)
tree73912e8be2147fe90acf8f5dd20bb1c238d354df /lisp
parent1d6fc0df363db43f2c1db696fad40f068287500b (diff)
downloademacs-9cd47b72e021f76a6e2481d986ce4b0cb0b859d3.tar.gz
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 'lisp')
-rw-r--r--lisp/ChangeLog5
-rw-r--r--lisp/compact.el60
2 files changed, 65 insertions, 0 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 072de2b6caa..25f99d2b824 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2012-07-19 Dmitry Antipov <dmantipov@yandex.ru>
+
+ Compact buffers when idle.
+ * compact.el: New file.
+
2012-07-19 Stefan Monnier <monnier@iro.umontreal.ca>
* subr.el (eventp): Presume that if it looks vaguely like an event,
diff --git a/lisp/compact.el b/lisp/compact.el
new file mode 100644
index 00000000000..0d9523147bc
--- /dev/null
+++ b/lisp/compact.el
@@ -0,0 +1,60 @@
+;;; compact.el --- compact buffers when idle
+
+;; Copyright (C) 2012 Free Software Foundation, Inc.
+
+;; Maintainer: FSF
+;; Package: emacs
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This package provides the ability to compact buffers when Emacs is idle.
+;; Initially written by Dmitry Antipov <dmantipov@yandex.ru>.
+
+;;; Code:
+
+(require 'timer)
+
+(defun compact-buffers ()
+ "Run `compact-buffer' for each buffer except current buffer.
+Schedule next compaction if `compact-buffers-when-idle' is greater than zero."
+ (mapc (lambda (buffer)
+ (and (not (eq buffer (current-buffer)))
+ (compact-buffer buffer)))
+ (buffer-list))
+ (compact-buffers-idle))
+
+(defun compact-buffers-idle ()
+ "Compact buffers if `compact-buffers-when-idle' is greater than zero."
+ (and (floatp compact-buffers-when-idle)
+ (> compact-buffers-when-idle 0.0)
+ (run-with-idle-timer compact-buffers-when-idle nil 'compact-buffers)))
+
+(defcustom compact-buffers-when-idle 1.0
+ "Compact all buffers when Emacs is idle more than this period of time.
+Compaction is done by truncating `buffer-undo-list' and shrinking the gap.
+Value less than or equal to zero disables idle compaction."
+ :type 'float
+ :group 'alloc
+ :set (lambda (symbol value)
+ (progn (set-default symbol value)
+ (compact-buffers-idle)))
+ :version "24.2")
+
+(provide 'compact)
+
+;;; compact.el ends here