The Emacs manual often talk about init.el
and .emacs
interchangeably, generally referring to them as "the Init File" like so:
When you start Emacs, it normally attempts to load your init file. This is either a file named .emacs or .emacs.el in your home directory, or a file named init.el in a subdirectory named .emacs.d in your home directory.
I try to put all my customization code into init.el
because, according to this site, it is 'modern' and 'preferred':
On linux and Mac, by default, emacs look for init file at
~/.emacs ~/.emacs.el ~/.emacs.d/init.el (this is modern, preferred, since ~2010)
I also try not to manually edit .emacs
too often because there are custom-set-variables
sitting in the file and there is a warning that says:
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
Other advantages of using the init.el
over .emacs
can be found here.
But I recently realize that some of the code I put in init.el
have been left unevaluated when Emacs is restarted. So I have to call up the file and M-x eval-buffer
every time I restart.
Therefore, I'd like to ask:
What is the difference between
init.el
and.emacs
as far as customization is concerned? (question has been partly answered here.)What is the point of keeping two (or more) Init files when having one would do? Some people even talked about splitting
init.el
into different files, quoting lunaryorn on Reddit:
It makes version control easier, especially if you split your init.el into different files in ~/.emacs.d.
- What to do when (some) code in one of them are persistently left unevaluated?
Updates:
I've deleted .emacs
and moved all its contents into init.el
, but part of the code in init.el
,such as the one below, is still unevaluated everytime emacs restarts.
;;set Chinese table alignment font size
(set-face-attribute
'default nil
:font (font-spec :name "-*-Menlo-normal-normal-normal-*-*-*-*-*-m-0-iso10646-1"
:weight 'normal
:slant 'normal
:size 24))
(dolist (charset '(kana han symbol cjk-misc bopomofo))
(set-fontset-font
(frame-parameter nil 'font)
charset
(font-spec :name "-*-STFangsong-normal-normal-normal-*-*-*-*-*-p-0-iso10646-1"
:weight 'normal
:slant 'normal
:size 28)))
.emacs
is checked beforeinit.el
. Sinceinit.el
resides in a directory devoted to Emacs configuration, it makes sense to use it instead, since it makes things like version controlling your init file easier. – Jul 12 '19 at 18:11init.el
then you need to delete.emacs
(after copying its contents to the newer file), otherwise Emacs will continue to use.emacs
as your init file. In short, put all of your init code in one file, and delete all other would-be init files. – phils Jul 13 '19 at 00:37custom-set-variables
, does that have to go intoinit.el
as well? – Sati Jul 13 '19 at 00:59init.el
is better than.emacs
. It doesn't say much about what to do with.emacs
when you decide to useinit.el
instead. – Sati Jul 13 '19 at 01:14custom-set-variables
is being written to.emacs
only because that is your init file. If your init file wasinit.el
then Emacs would be writing it to that. So yes, you should move everything in.emacs
toinit.el
and delete.emacs
. If a~/.emacs
file even exists, then that is your init file. Emacs may update that "custom" config when you exit, so I suggest you (1) Exit emacs; (2) Runemacs -q ~/.emacs.d/init.el ~/.emacs
and copy/paste the .emacs contents to the init.el file, save that file, and exit; (3) Delete the .emacs file; (4) Start emacs normally. – phils Jul 13 '19 at 03:45custom-set-variables
section in another file (e.g.~/.emacs.d/custom.el
) if you find that tidier. SeeC-h v custom-file
. Note that your init file will need to both specify the file name and load it. – phils Jul 13 '19 at 03:46.emacs
. – Sati Jul 13 '19 at 03:52emacs --debug-init
show you any error / backtrace? – phils Jul 13 '19 at 05:12local variables list is not properly terminated
message every time I openinit.el
. – Sati Jul 13 '19 at 05:15C-x 5 2
reverts all custom settings back to the default. – Sati Jul 13 '19 at 05:24Local Variables:
list for starters. If you have no idea what that is or why you're getting that error, then you can insert a page break character at the end of the file withC-q C-l
(the character will look like^L
), as emacs only looks for a Local Variables list in the final page of the file. – phils Jul 13 '19 at 05:34C-x 5 2
will absolutely not revert "all custom settings" back to the default. Certain settings are frame-specific, however (e.g. frame parameters and terminal-local variables). That is a completely different question, though. – phils Jul 13 '19 at 05:43Local Variables:
list has been fixed by inserting anEnd:
after it. Still doesn't fix the evaluation problem, though. Seems to me that only some of the code ininit.el
gets evaluated - even when.emacs
is not around - but everything in.emacs
would be evaluated upon startup. – Sati Jul 13 '19 at 05:53