6

I use desktop-save-mode in order to restore buffers on startup. However, the buffer which is visible immediately after startup is *scratch*, *Messages*, .bbdb, etc. I am not interested in those. Is there a way to have Emacs after a restart in the same buffer state, including ordering, as when it was closed?

Torsten Bronger
  • 329
  • 2
  • 6

1 Answers1

4

I have the following in my equivalent of a .emacs file:

(defun my-bury-star-buffers ()
  "Bury all star buffers."
  (interactive)
  (mapc (lambda (buf)
          (when (string-match-p "\\`\\*.*\\*\\'" (buffer-name buf))
            (bury-buffer buf)))
        (buffer-list)))
(add-hook 'desktop-after-read-hook #'my-bury-star-buffers)

I don't remember where I got it. You'll need to extend the regex for any other files you want buried (like .bbdb). The non-buried buffers seem to be in the right order.

Kaushal Modi
  • 25,203
  • 3
  • 74
  • 179
Tad Ashlock
  • 596
  • 4
  • 6
  • Is it safe to just kill them? – Torsten Bronger Feb 03 '16 at 16:55
  • @TorstenBronger, it's safe to kill the "star" buffers, but not recommended. The `*Messages*` buffer will just come back next time a message is generated, but you will have lost all messages that happened before. And the `*scratch*` buffer can be handy, but easily recreated if necessary. – Tad Ashlock Feb 03 '16 at 18:28
  • I thought about it again and I remember that "File xy has recoverable data" messages have been important to me quite often. Thus, I don't feel comfortable with just killing all star buffers. Of course, one could switch your code off if one sees such messages in the minibuffer blinking during start-up and re-start Emacs; but I wouldn't know what annoys more. – Torsten Bronger Feb 06 '16 at 11:48