I'm new to emacs and looking to change my default init file as the current is set to be ~/.emacs and I want it to be ~/.emacs.d/init.el
I can clearly C-h v user-init-file to see but but M-x set-variable user-init-file just gives [No Match].
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityWhy "No match"
The function set-variable
will only accept setting user options. But user-init-file
is not a user option (i.e. it was not designed to be customized). Relevant excerpt from the docstring of set-variable
:
VARIABLE should be a user option variable name
Why user-init-file
is not a user option
This variable is meant to be read, not modified. The reason is that at the moment you can write code to modify this variable (i.e. while emacs is starting, or after it has started), it is already too late : the init file is already loaded (or is being loaded).
How to change the init file
There are various ways to tell emacs what to load at startup. Details can be found at (info "(emacs) Init File")
. I think the easiest is : prevent emacs from loading any init file then load another one instead (i.e. use -q -l somefile.el
when invoking emacs).
user-init-file
? In the init file? That's too late. You should think of it as a read-only variable that's compiled into emacs. To change it, you'd have to recompile emacs. But current versions look for either file, so you can just rename your .emacs to ~/.emacs.d/init.el and you should be OK. – NickD Sep 17 '17 at 18:19(message "Hello world")
in ~/emacs.d/init.el and start up emacs. Do you see the message in the minibuffer? – NickD Sep 17 '17 at 18:34