0

I want to kill some buffers created by default, such as the GNU Emacs, but putting:

(kill-buffer "*GNU Emacs*")

On the .emacs doesn't work. I guess this code is called before the initial buffers are created. There should be some kind of hook, but I want it to be run only at the start up, to clean all the initial buffers I don't need.

Edit:

Tried after-init-hook and emacs-startup-hook without success.

Edit 2:

Put some code on .emacs to see what's happening:

(defun buffer-hook-function ()
  (append-to-file (format "%s" (buffer-list)) nil  "log.txt")
  (append-to-file "\n" nil  "log.txt")
  )

(append-to-file "Executou .emacs\n" nil  "log.txt")

(add-hook 'emacs-startup-hook (lambda () (append-to-file "emacs-startup-hook\n" nil  "log.txt")))
(add-hook 'after-init-hook (lambda () (append-to-file "after-init-hook\n" nil  "log.txt")))
(add-hook 'before-init-hook (lambda () (append-to-file "before-init-hook\n" nil  "log.txt")))
(add-hook 'window-setup-hook (lambda () (append-to-file "window-setup-hook\n" nil  "log.txt")))
(add-hook 'emacs-startup-hook (lambda () (append-to-file "window-setup-hook\n" nil  "log.txt")))
(add-hook 'buffer-list-update-hook 'buffer-hook-function)

After starting emacs, the output on log.txt is:

Ran .emacs
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*)
after-init-hook
window-setup-hook
emacs-startup-hook
window-setup-hook
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*  *temp*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1* *GNU Emacs*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1* *GNU Emacs*  *temp*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1* *GNU Emacs*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1* *GNU Emacs*  *temp*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1* *GNU Emacs*)
(*scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1* *GNU Emacs*)
(*GNU Emacs* *scratch*  *Minibuf-0* *Messages*  *code-conversion-work*  *Echo Area 0*  *Echo Area 1*)

I'm not finding a hook for being executed after all those initial buffers are created... Maybe I'll need to do some shenanigan to capture this event.

2 Answers 2

3

To prevent Emacs creating the *GNU Emacs* buffer, you can set inhibit-startup-screen to t, or you can also change the user option initial-buffer-choice to tell Emacs to display a buffer that you want.

To kill *scratch*, put (kill-buffer "*scratch*") anywhere in your init file. For *Messages*, you can't avoid it since it's a special buffer which is used by Emacs itself.

1
0

Easy: find and kill buffer *scratch*:

(when (get-buffer "*scratch*")
   (kill-buffer "*scratch*"))

Normal: find and kill buffer *scratch* after starting EMACS session (also with emacsclient):

(defun kill-scratch-after-init ()
  "Kill *scratch* buffer."
  (when (get-buffer "*scratch*")
    (kill-buffer "*scratch*"))

(add-hook 'after-init-hook #'kill-scratch-after-init)

or with lambda:

(add-hook 'after-init-hook (lanmda ()(
  (when (get-buffer "*scratch*")
    (kill-buffer "*scratch*")))))

Difficult: find and kill buffers from defined list after starting EMACS session:

(defun kill-initial-buffers-after-init ()
  "Kill listed EMACS buffers after initialization."
  (setq buff-list '(
                    "*scratch*"
                    "another"
                    "buffer"
                    "names"))
  (dolist (buf buff-list)
    (when (get-buffer buf)
      (kill-buffer buf)))))

(add-hook 'after-init-hook #'kill-initial-buffers-after-init)

NOTE: Buffer *Message* will be recreated automatically after first call message function.

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.