1

Question of curiosity...

Let's assume I have the following files...~/.emacs, ~/.emacs.d/init.el and ~/.emacs.el.

Now, assume that each of these contain separate pieces of code, for example :

~/.emacs
(global-set-key (kbd "<f8>") 'execute-extended-command)

~/.emacs.d/init.el
(global-set-key (kbd "<apps>") 'execute-extended-command)

~/.emacs.el
(global-set-key (kbd "<menu>") 'execute-extended-command)

Notice that all files make separate changes to the execute-extended-command. When emacs is opened, which of these files will be executed? All of them, one of them, or none of them? Is there a special order for which ones are executed first? And, additionally, is it a bad idea to have multiple init files?

Any answer touching these subjects, and any additional information is adequate, I simply want to know what happens in such a scenario.

buydadip
  • 8,890
  • 22
  • 79
  • 154
  • 2
    Why not just try it? Put different (message "File X was loaded") commands in each of the files, and look in the `*Messages*` buffer after starting Emacs. – asjo Jan 10 '15 at 20:21
  • not sure why this is considered a duplicate... The questions are quite different, I would know since I asked both of them :P – buydadip Jan 11 '15 at 16:59
  • @Drew could you please explain why you flagged it? – buydadip Jan 11 '15 at 22:27
  • The questions might appear to be slightly different, but they are essentially the same. And the answer is exactly the same: **where Emacs looks for an init file - which places and in which order** (and how to ask Emacs for this info). – Drew Jan 11 '15 at 23:28
  • 1
    The questions are quite different, so users could benefit from two ways of finding the same answer... Why not add and accept an answer explaining that the answer is the same as (linked question). – Benjamin Mar 04 '15 at 01:13

1 Answers1

4

From the manual:

49.4.4 How Emacs Finds Your Init File

Normally Emacs uses the environment variable HOME (see HOME) to find .emacs; that's what ‘~’ means in a file name. If .emacs is not found inside ~/ (nor .emacs.el), Emacs looks for ~/.emacs.d/init.el (which, like ~/.emacs.el, can be byte-compiled).

So ~/.emacs.d/init.el is only consulted if the other two cannot be found. A quick test shows that, when both are available, ~/.emacs.el is preferred over ~/.emacs.

You should pick one of these locations and use it consistently.

I personally like ~/.emacs.d/init.el because Emacs puts other things in that directory (e.g. custom.el, elpa/) and many Emacs packages load their own configuration files from that directory.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257