aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-07-31 10:24:41 +0000
committerRichard M. Stallman1998-07-31 10:24:41 +0000
commit849ac8351dc494cdeedbbb9f68b724952210b7af (patch)
tree8667c7c980e945dec1efba27fae714151b54fccd
parentbbf1ae49ae6aca81dcef3771cfbe6e796ea987f6 (diff)
downloademacs-849ac8351dc494cdeedbbb9f68b724952210b7af.tar.gz
emacs-849ac8351dc494cdeedbbb9f68b724952210b7af.zip
Require timer.
(clean-buffer-list-kill-regexps): Match `*vc' buffers. (midnight-find): Use dolist, not loop. (clean-buffer-list-delay): Use assoc-default. (assoc-default): New function.
-rw-r--r--lisp/midnight.el43
1 files changed, 28 insertions, 15 deletions
diff --git a/lisp/midnight.el b/lisp/midnight.el
index 01b987320d9..fd9867daaaa 100644
--- a/lisp/midnight.el
+++ b/lisp/midnight.el
@@ -36,7 +36,9 @@
36;; keeping `clean-buffer-list-kill-never-buffer-names' and 36;; keeping `clean-buffer-list-kill-never-buffer-names' and
37;; `clean-buffer-list-kill-never-regexps'. 37;; `clean-buffer-list-kill-never-regexps'.
38 38
39(eval-when-compile (require 'cl)) 39(eval-when-compile
40 (require 'cl)
41 (require 'timer))
40 42
41(defgroup midnight nil 43(defgroup midnight nil
42 "Run something every day at midnight." 44 "Run something every day at midnight."
@@ -93,7 +95,7 @@ displayed more than this many seconds ago."
93 :type 'integer 95 :type 'integer
94 :group 'midnight) 96 :group 'midnight)
95 97
96(defcustom clean-buffer-list-kill-regexps nil 98(defcustom clean-buffer-list-kill-regexps '("\\*vc\\.")
97 "*List of regexps saying which buffers will be killed at midnight. 99 "*List of regexps saying which buffers will be killed at midnight.
98If buffer name matches a regexp in the list and the buffer was not displayed 100If buffer name matches a regexp in the list and the buffer was not displayed
99in the last `clean-buffer-list-delay-special' seconds, it is killed by 101in the last `clean-buffer-list-delay-special' seconds, it is killed by
@@ -145,23 +147,35 @@ two lists will NOT be killed if it also matches anything in this list."
145 "A stopgap solution to the absence of `find' in ELisp." 147 "A stopgap solution to the absence of `find' in ELisp."
146 (if (fboundp 'find) 148 (if (fboundp 'find)
147 (find el ls :test test :key (or key 'eql)) 149 (find el ls :test test :key (or key 'eql))
148 (loop for rr in ls when (funcall test el (if key (funcall key rr) rr)) 150 (dolist (rr ls)
149 return rr))) 151 (when (funcall test el (if key (funcall key rr) rr))
152 (return rr)))))
153
154(defun assoc-default (el alist test default)
155 "Find object EL in a pseudo-alist ALIST.
156ALIST is a list of conses or objects. EL is compared (using TEST) with
157CAR (or the object itself, if it is not a cons) of elements of ALIST.
158When TEST returns non-nil, CDR (or DEFAULT, if the object is not a cons)
159of the object is returned.
160This is a non-consing analogue of
161 (cdr (assoc el (mapcar (lambda (el) (if (consp el) el (cons el default)))
162 alist)
163 :test test))
164The calling sequence is: (ASSOC-DEFAULT EL ALIST TEST DEFAULT)"
165 (dolist (rr alist)
166 (when (funcall test el (if (consp rr) (car rr) rr))
167 (return (if (consp rr) (cdr rr) default)))))
150 168
151(defun clean-buffer-list-delay (bn) 169(defun clean-buffer-list-delay (bn)
152 "Return the delay, in seconds, before this buffer name is auto-killed. 170 "Return the delay, in seconds, before this buffer name is auto-killed.
153Uses `clean-buffer-list-kill-buffer-names', `clean-buffer-list-kill-regexps' 171Uses `clean-buffer-list-kill-buffer-names', `clean-buffer-list-kill-regexps'
154`clean-buffer-list-delay-general' and `clean-buffer-list-delay-special'. 172`clean-buffer-list-delay-general' and `clean-buffer-list-delay-special'.
155Autokilling is done by `clean-buffer-list'." 173Autokilling is done by `clean-buffer-list'."
156 (flet ((ff (ls ts) 174 (or (assoc-default bn clean-buffer-list-kill-buffer-names 'string=
157 (let ((zz (midnight-find 175 clean-buffer-list-delay-special)
158 bn ls ts (lambda (xx) (if (consp xx) (car xx) xx))))) 176 (assoc-default bn clean-buffer-list-kill-regexps 'string-match
159 (cond ((consp zz) (cdr zz)) 177 clean-buffer-list-delay-special)
160 ((null zz) nil) 178 (* clean-buffer-list-delay-general 24 60 60)))
161 (clean-buffer-list-delay-special)))))
162 (or (ff clean-buffer-list-kill-buffer-names 'string=)
163 (ff clean-buffer-list-kill-regexps 'string-match)
164 (* clean-buffer-list-delay-general 24 60 60))))
165 179
166(defun clean-buffer-list () 180(defun clean-buffer-list ()
167 "Kill old buffers. 181 "Kill old buffers.
@@ -174,8 +188,7 @@ The relevant vartiables are `clean-buffer-list-delay-general',
174 (dolist (buf (buffer-list)) 188 (dolist (buf (buffer-list))
175 (message "[%s] processing `%s'..." ts buf) 189 (message "[%s] processing `%s'..." ts buf)
176 (setq bts (buffer-display-time buf) bn (buffer-name buf)) 190 (setq bts (buffer-display-time buf) bn (buffer-name buf))
177 (unless (or ;; (string-match clean-buffer-list-kill-never bn) 191 (unless (or (midnight-find bn clean-buffer-list-kill-never-regexps
178 (midnight-find bn clean-buffer-list-kill-never-regexps
179 'string-match) 192 'string-match)
180 (midnight-find bn clean-buffer-list-kill-never-buffer-names 193 (midnight-find bn clean-buffer-list-kill-never-buffer-names
181 'string-equal) 194 'string-equal)