I have Emacs run in daemon mode at system startup, and run emacsclient automatically when I login to X. I also recently started running midnight-mode, which regularly runs clean-buffer-list, which wants to kill the buffer showing my home folder since I rarely visit it. This is a problem because that buffer is associated with the emacsclient invocation, so killing it closes all my frames.

Is there a way to decouple emacsclient from that particular buffer? I have to run emacsclient on something in order for it to open a window, so I give it $HOME.

Alternatively, is there a way to get clean-buffer-list to look at server-buffer-clients and skip buffers with it set?

1 Answer 1


Oddly enough, clean-buffer-list doesn't directly offer a convenient hook for that, no. But I think you can get the behavior you're asking for with a hack like:

(defun my-midnight-hack (orig-fun buffer)
  (with-current-buffer buffer
    (if server-buffer-clients
         ;; Return the current time, to pretend it's in use.
      (funcall orig-fun buffer))))
(advice-add 'midnight-buffer-display-time :around #'my-midnight-hack)

Another approach would be to run emacsclient -n ... so that emacsclient immediately returns and killing that buffer should then not kill all your frames (because the buffer is not marked as belonging to an emacsclient).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.