Compact buffers when idle.
[bpt/emacs.git] / lisp / compact.el
1 ;;; compact.el --- compact buffers when idle
2
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
4
5 ;; Maintainer: FSF
6 ;; Package: emacs
7
8 ;; This file is part of GNU Emacs.
9
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
14
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22
23 ;;; Commentary:
24
25 ;; This package provides the ability to compact buffers when Emacs is idle.
26 ;; Initially written by Dmitry Antipov <dmantipov@yandex.ru>.
27
28 ;;; Code:
29
30 (require 'timer)
31
32 (defun compact-buffers ()
33 "Run `compact-buffer' for each buffer except current buffer.
34 Schedule next compaction if `compact-buffers-when-idle' is greater than zero."
35 (mapc (lambda (buffer)
36 (and (not (eq buffer (current-buffer)))
37 (compact-buffer buffer)))
38 (buffer-list))
39 (compact-buffers-idle))
40
41 (defun compact-buffers-idle ()
42 "Compact buffers if `compact-buffers-when-idle' is greater than zero."
43 (and (floatp compact-buffers-when-idle)
44 (> compact-buffers-when-idle 0.0)
45 (run-with-idle-timer compact-buffers-when-idle nil 'compact-buffers)))
46
47 (defcustom compact-buffers-when-idle 1.0
48 "Compact all buffers when Emacs is idle more than this period of time.
49 Compaction is done by truncating `buffer-undo-list' and shrinking the gap.
50 Value less than or equal to zero disables idle compaction."
51 :type 'float
52 :group 'alloc
53 :set (lambda (symbol value)
54 (progn (set-default symbol value)
55 (compact-buffers-idle)))
56 :version "24.2")
57
58 (provide 'compact)
59
60 ;;; compact.el ends here