0

I would like to avoid using buffer *scratch*, so I set up (kill-buffer "*scratch*") in my init.el but it doesn't always work (sometimes it kills the buffer, sometimes it doesn't).

  • 2
    After several years of trying to control the creation of the *scratch* buffer, I finally gave up. To the extent you wish to go down the same road, you might wish to try attaching your kill-buffer function to the emacs-startup-hook which is the last hook to run when starting up. E.g., (add-hook 'emacs-startup-hook (lambda () (when (get-buffer "*scratch*") (kill-buffer "*scratch*")))) – lawlist Sep 10 '18 at 23:30
  • Unfortunately this does not always work either. – Francesco Cadei Sep 11 '18 at 8:23
  • Emacs will make sure there is always at least one buffer, usually *scratch* or *Messages*. One idea you may wish to explore on your journey is to create a different buffer before deleting the *scratch* buffer: (add-hook 'emacs-startup-hook (lambda () (find-file-noselect (concat user-emacs-directory ".scratch")) (when (get-buffer "*scratch*") (kill-buffer "*scratch*")))) That code does not select the new buffer, it just crates it. If it is an existing file on your hard drive, it will load the file/buffer. If not, then it will be a non-file-visiting buffer. – lawlist Sep 11 '18 at 21:01
  • If you were not already aware of the variable initial-buffer-choice, the doc-string states that: if the initial-buffer-choice is t, then Emacs will open/create the *scratch* buffer. However, Emacs also creates it when there are no other buffers -- there will always be at least one buffer. – lawlist Sep 11 '18 at 21:04
  • May I know what do you try to achieve please? You can either emacs /path/to/file or you can emacs then call find-file function. You can even start Emacs in dired mode. What is wrong with the *scratch* buffer? You can just ignore it right? – Nsukami _ Sep 12 '18 at 3:03

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.