CCE

Clean Buffers at a Regular Interval with Midnight Mode

I feel a little weird just enabling this, let's see what I think about auto-killing any buffer older than six hours. It won't run often, if I want it to run hourly, I could put it in to a repeating timer, myself.

emacs-lisp:tangle ~/nix/lisp/midnight-mode.el
(provide 'cce/midnight-mode)
(setq clean-buffer-list-delay-general 0.5)
(midnight-mode 1)

(setq clean-buffer-list-kill-regexps
      (append clean-buffer-list-kill-regexps
              (list (rx line-start "*Ement"))))
(setq clean-buffer-list-kill-never-buffer-names
      (append clean-buffer-list-kill-never-buffer-names
              (list "*Group*")))

I really wish this clean-buffers functionality could exclude based on mode, what an oversight! We can cheese it, however, with this function which can be added to clean-buffer-list-kill-never-regexps.

emacs-lisp:tangle ~/nix/lisp/midnight-mode.el
(defun cce/check-kill-exwm-mode (buffer-name)
  "Checks whether the buffer backing [`buffer-name'] is an EXWM-mode buffer to exclude from midnight-mode.

To enable this, add it to [`clean-buffer-list-kill-never-regexps'], which will get it funcall'd in the midnight-mode hook."
  (with-current-buffer buffer-name
    (eq major-mode 'exwm-mode)))

(add-to-list 'clean-buffer-list-kill-never-regexps #'cce/check-kill-exwm-mode)