0

I realize when I open emacs using emacs -Q I can see *scratch* for a very short time. Sometimes 1ms or half a second.

=> How to prevent *scratch* or *Messages* buffer to show up when I open via emacs -Q along with a theme?


My eval file is:

(add-to-list 'custom-theme-load-path "~/.emacs.d/themes")
(load-theme 'dracula t)

(setq inhibit-splash-screen t)
(setq inhibit-startup-message t)
(setq initial-scratch-message "")

==> emacs -q -l ~/emacs_q.el hello_emacs

alper
  • 1,238
  • 11
  • 30
  • 1
    Emacs must always have at least one buffer and it will generate the `*scratch*` buffer if there is none to be found. Emacs will generate a `*scratch*` and a `*Messages*` buffer on `startup` without a user-init file. If you kill them both with code on startup, then Emacs will automatically recreate the `*scratch*` if no other buffer has been found. **What do you want to see *after* Emacs starts?** This will kill the `*scratch*` buffer on startup, but it may be visible for a split second: `(add-hook 'emacs-startup-hook (lambda () (when (get-buffer "*scratch*") (kill-buffer "*scratch*"))))` – lawlist Aug 12 '20 at 14:31
  • What do you want to see after Emacs starts? => I just want to see the buffer of the file I am opening right away and I don't want to see any other buffer like *scratch*, *Messages*, or any other. When I use a slow machine over ssh connection, when `*scratch*` buffer is open first, it may let me wait max for a second, so I just don't want that. – alper Aug 13 '20 at 01:21
  • If you are experiencing a split-window situation, where the `*scratch*` or `*Messages*` buffer is appearing along side your `hello-emacs` buffer, then the solution will be different. If your `hello-emacs` buffer is the only window open once Emacs has fully fired up, then the issue is just what you see while you wait. You are not likely to achieve any *appreciable* speed enhancement by killing either the `*scratch*` or the `*Messages*` buffer. If the `emacs-startup-hook` is too late for you, try the `after-init-hook` which runs a little earlier. See also `early-init.el` in Emacs 27. – lawlist Aug 13 '20 at 03:07
  • I tried `(add-hook 'emacs-startup-hook (lambda () (when (get-buffer "*scratch*") (kill-buffer "*scratch*"))))` but I still `scratch` buffer show up when emacs launches – alper Aug 15 '20 at 16:39

1 Answers1

1

This should do it:

;; Remove messages from the *Messages* buffer.
(setq-default message-log-max nil)

;; Kill both buffers on startup.
(kill-buffer "*Messages*")
(kill-buffer "*scratch*")

If your scratch buffer is not empty, you may want to throw this too:

;; Empty the *scratch* buffer.
(setq initial-scratch-message "")
nunop
  • 126
  • 2
  • Can we have something as follows too?: https://emacs.stackexchange.com/a/59695/18414 – alper Apr 21 '23 at 11:33
  • 1
    That seems to be a more robust solution indeed. Something like this in one's `early-init.el` file (either with `after-init-hook` or `emacs-startup-hook`, doesn't seem to make a difference here) works seemingly smoothly: `(add-hook 'after-init-hook (lambda () (when (get-buffer "*scratch*") (kill-buffer "*scratch*") (when (get-buffer "*Messages*") (kill-buffer "*Messages*")))))`. You still need to first remove all messages from your `*Messages*` buffer though. – nunop Apr 22 '23 at 08:15
  • This solutiion looks like did not work for when I write using `emacs -Q` – alper Apr 24 '23 at 11:30