* buffer.h (FOR_EACH_BUFFER): Rename from 'for_each_buffer'.
[emacs.git] / lisp / compact.el
blob0d9523147bcd8ea1ef9170b87279c9d327e7d329
1 ;;; compact.el --- compact buffers when idle
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
5 ;; Maintainer: FSF
6 ;; Package: emacs
8 ;; This file is part of GNU Emacs.
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.
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.
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/>.
23 ;;; Commentary:
25 ;; This package provides the ability to compact buffers when Emacs is idle.
26 ;; Initially written by Dmitry Antipov <dmantipov@yandex.ru>.
28 ;;; Code:
30 (require 'timer)
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))
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)))
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")
58 (provide 'compact)
60 ;;; compact.el ends here