Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;;; Commentary:
- ;; Kills buffers that I never use, and that annoy me when completion
- ;; offers their names.
- ;; Note that this may be overkill (ha); given that I use "ido", it
- ;; might suffice to simply add something to ido-make-buffer-list-hook,
- ;; that puts these buffers at the end of the list.
- ;; This code all depends on a buffer-local variable named
- ;; buffer-creation-time. That variable doesn't (yet) exist in
- ;; anyone's Emacs but mine, since I hacked it in myself.
- (if (fboundp 'buffer-creation-time)
- (progn
- (defun kill-them-buffers ()
- (mapc
- (lambda (p)
- (flet ((time->string
- (time)
- (format-seconds "%Y, %D, %H, %M, %z%S" (float-time time))))
- (let ((victim (get-buffer (car p))))
- (when victim
- ;; if the buffer is not old enough, spare its life.
- (let ((allotted-lifespan (cdr p))
- (age (time-subtract
- (current-time)
- (with-current-buffer victim
- ;; Ideally we'd consider the
- ;; last-modification time of the buffer
- ;; too, and kill it only if _both_ those
- ;; times are old. But we don't keep
- ;; track of that time (yet :-).
- (buffer-creation-time)))))
- (if (time-less-p allotted-lifespan age)
- (progn
- ;; if it's displayed in some window, nix the window.
- (let ((window-victim (get-buffer-window victim t)))
- (while window-victim
- (delete-window window-victim)
- (setq window-victim (get-buffer-window victim t))))
- (message "Killing buffer %s -- it's %s old (which is more than %s)!!"
- victim
- (time->string age)
- (time->string allotted-lifespan))
- (kill-buffer victim))
- (message "Spared buffer %s -- it's only %s old"
- victim
- (time->string age))))))))
- ;; These are buffers whose names make them likely to get in my
- ;; way when I'm looking for some other, similarly-named,
- ;; buffer. Ido probably makes this problem worse.
- `(
- ;; Times are pairs of (HIGH LOW) seconds; see 'current-time'
- ("*Completions*" . (0 3))
- ("*Shell Command Output*" . (0 120))
- ("*vc-diff*" . (0 60))
- )))
- (setq *reaper-timer*
- (run-with-idle-timer 5 t 'kill-them-buffers))
- (when nil
- (cancel-timer *reaper-timer*)))
- (message "There's no function named buffer-creation-time, so I cannot start the reaper."))
Add Comment
Please, Sign In to add comment