0

I would like to run a custom function whenever a new *Scratch* buffer is created because the last uninteresting buffer was killed. I looked at both the C source code and window.el and it appears that Lisp has nothing to do with the *Scratch* buffer being displayed in a particular window, but I'm not 100% certain. It appears as though tem = Fother_buffer (buffer, Qnil, Qnil) within kill-buffer is what leads to the creation of a new *Scratch* buffer.

Is there anything other than the buffer-list-update-hook that I could use to trigger my custom function when a new *Scratch* gets spawned? I don't think that replace-buffer-in-windows is any help in this context.

[I don't really want to advise get-buffer-create.]

2 Answers 2

1

The function assigned to the variable initial-major-mode is only called when *Scratch* is created by Emacs (e.g., startup.el, or when certain criteria is met when killing a buffer). It can be a custom function -- e.g., set the major-mode and do anything else under the sun.

(setq initial-major-mode (lambda () (lisp-interaction-mode) (message "*scratch*")))
0

The *scratch* buffer isn't special; it's just a regular buffer with a fixed name. There are no special hooks just for it, so buffer-list-update-hook is the way to go.

0

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.