# HG changeset patch # User Richard M. Stallman # Date 902707272 0 # Node ID ff793b9329c9b5d563b71ac14454a902b1cbac92 # Parent ea0e3bbd37035f191933174b35198cfef487cbf5 (clean-buffer-list-kill-buffer-names): Add `*diff*'. (clean-buffer-list): Check `buffer-modified-p' only when the buffer is associated with a file. (midnight-delay-set): Improve doc. (midnight-find): Don't use `find'. diff -r ea0e3bbd3703 -r ff793b9329c9 lisp/midnight.el --- a/lisp/midnight.el Sun Aug 09 22:42:36 1998 +0000 +++ b/lisp/midnight.el Mon Aug 10 00:01:12 1998 +0000 @@ -36,6 +36,8 @@ ;; keeping `clean-buffer-list-kill-never-buffer-names' and ;; `clean-buffer-list-kill-never-regexps'. +;;; Code: + (eval-when-compile (require 'cl) (require 'timer)) @@ -110,7 +112,7 @@ (defcustom clean-buffer-list-kill-buffer-names '("*Help*" "*Apropos*" "*Man " "*Buffer List*" "*Compile-Log*" "*info*" - "*vc*" "*vc-diff*") + "*vc*" "*vc-diff*" "*diff*") "*List of strings saying which buffers will be killed at midnight. Buffers with names in this list, which were not displayed in the last `clean-buffer-list-delay-special' seconds, are killed by `clean-buffer-list' @@ -146,11 +148,9 @@ (defun midnight-find (el ls test &optional key) "A stopgap solution to the absence of `find' in ELisp." - (if (fboundp 'find) - (find el ls :test test :key (or key 'eql)) - (dolist (rr ls) - (when (funcall test el (if key (funcall key rr) rr)) - (return rr))))) + (dolist (rr ls) + (when (funcall test el (if key (funcall key rr) rr)) + (return rr)))) (defun clean-buffer-list-delay (name) "Return the delay, in seconds, before killing a buffer named NAME. @@ -165,21 +165,28 @@ (defun clean-buffer-list () "Kill old buffers that have not been displayed recently. -The relevant vartiables are `clean-buffer-list-delay-general', +The relevant variables are `clean-buffer-list-delay-general', `clean-buffer-list-delay-special', `clean-buffer-list-kill-buffer-names', `clean-buffer-list-kill-never-buffer-names', -`clean-buffer-list-kill-regexps' and `clean-buffer-list-kill-never-regexps'." +`clean-buffer-list-kill-regexps' and +`clean-buffer-list-kill-never-regexps'. +While processing buffers, this procedure displays messages containing +the current date/time, buffer name, how many seconds ago it was +displayed (can be NIL if the buffer was never displayed) and its +lifetime, i.e., its `age' when it will be purged." (interactive) - (let ((tm (float-time)) bts (ts (format-time-string "%Y-%m-%d %T")) bn) - (dolist (buf (buffer-list)) - (message "[%s] processing `%s'..." ts buf) - (setq bts (buffer-display-time buf) bn (buffer-name buf)) + (let ((tm (float-time)) bts (ts (format-time-string "%Y-%m-%d %T")) bn + (bufs (buffer-list)) buf delay cbld) + (while (setq buf (pop bufs)) + (setq bts (buffer-display-time buf) bn (buffer-name buf) + delay (if bts (- tm bts) 0) cbld (clean-buffer-list-delay bn)) + (message "[%s] `%s' [%s %d]" ts bn (if bts (round delay)) cbld) (unless (or (midnight-find bn clean-buffer-list-kill-never-regexps 'string-match) (midnight-find bn clean-buffer-list-kill-never-buffer-names 'string-equal) - (buffer-modified-p buf) (get-buffer-window buf 'visible) - (null bts) (< (- tm bts) (clean-buffer-list-delay bn))) + (and (buffer-file-name buf) (buffer-modified-p buf)) + (get-buffer-window buf 'visible) (< delay cbld)) (message "[%s] killing `%s'" ts bn) (kill-buffer buf))))) @@ -207,10 +214,10 @@ ;;;###autoload (defun midnight-delay-set (symb tm) "Modify `midnight-timer' according to `midnight-delay'. -Sets the first argument (which must be symbol `midnight-delay') -to its second argument." - (unless (eq symb 'midnight-delay) - (error "Illegal argument to `midnight-delay-set': `%s'" symb)) +Sets the first argument SYMB (which must be symbol `midnight-delay') +to its second argument TM." + (assert (eq symb 'midnight-delay) t + "Illegal argument to `midnight-delay-set': `%s'" symb) (set symb tm) (when (timerp midnight-timer) (cancel-timer midnight-timer)) (setq midnight-timer