0

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:

  1. What is the difference between init.el and .emacs as far as customization is concerned? (question has been partly answered here.)

  2. 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.

  1. 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)))

  • 1
    The difference between these files is precedence. IIRC, .emacs is checked before init.el. Since init.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. – DoMiNeLa10 Jul 12 at 18:11
  • 1
    If you've decided to use init.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 at 0:37
  • 1
    @DoMiNeLa10♦, This is not exactly a duplicate. The question you highlighted just talks about why using init.el is better than .emacs. It doesn't say much about what to do with .emacs when you decide to use init.el instead. – Sati Jul 13 at 1:14
  • 1
    @Sati You can put that custom-set-variables section in another file (e.g. ~/.emacs.d/custom.el) if you find that tidier. See C-h v custom-file. Note that your init file will need to both specify the file name and load it. – phils Jul 13 at 3:46
  • 1
    Well fix your Local 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 with C-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 at 5:34

Your Answer

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

Browse other questions tagged or ask your own question.