I used to have in my emacs .init.el file the following two lines used to inhibit the splash screen and to switch to an anonymous buffer

(setq inhibit-splash-screen t) (switch-to-buffer "**")

Recently I started using emacs --daemon and emacsclient and my initial buffer is set to *scratch*. I don't want Lisp interaction and the annoying scratch message so I wrote the following line in my init.el

(setq initial-buffer-choice "**")

The problem is that the new initial buffer is different from the traditional ** buffer. In fact, when closing emacs, I am prompted to save a file called **, while I don't want this kind of behavior, I just want my traditional ** anonymous buffer.

I know that I can manually set initial-major-mode and initial-scratch-message and continue to use *scratch* but I really would like to use ** instead.

How can I solve this problem?


From the initial-buffer-choice documentation:

If the value is nil and ‘inhibit-startup-screen’ is nil, show the startup screen. If the value is a string, switch to a buffer visiting the file or directory that the string specifies. If the value is a function, call it with no arguments and switch to the buffer that it returns. If t, open the ‘scratch’ buffer.

You have set the value as a string, so it switches a buffer visiting the file that the string specifies.

You can instead set the value as a function returning the buffer you want selected:

(setq initial-buffer-choice (lambda () (get-buffer-create "**")))

Note that I've used get-buffer-create, because if the buffer doesn't exist then the function passed will return nil, which can cause problems wwhen creating new frames.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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