set-buffer-major-mode

set-buffer-major-mode is a built-in function in `C source code'.

(set-buffer-major-mode BUFFER)

Set an appropriate major mode for BUFFER.
For the *scratch* buffer, use `initial-major-mode', otherwise choose a mode
according to the default value of `major-mode'.
Use this function before selecting the buffer, since it may need to inspect
the current buffer's major mode.