1

By default Emacs load the file .emacs on my system. I know if I want to start Emacs with the init file .emacs2, I should run the Emacs with the argument like emacs -q -l ~/.emacs2. Is it possible to load the init file .emacs2 in the current Emacs which is previously loaded with .emacs?

4

It's possible. Just M-: (eval-expression) with:

(load-file "~/.emacs2")

Or yank the above into *scratch*, position the cursor after it and press C-j.

  • 3
    Or just M-x load-file ~/.emacs2 instead of eval-expression – erikstokes Jan 3 '15 at 15:57
  • Let us continue this discussion in chat. – Name Jan 3 '15 at 18:52
  • 2
    My unsolicited advice: don't bother. It is unlikely that your init files are idempotent. You will save yourself trouble by not expecting that loading an init file more than once, or loading multiple init files, will have the effect of loading an init file in a virgin Emacs session. (Just one opinion.) – Drew Jan 3 '15 at 18:53
2

From the Emacs info page on Initialization, the -q option prevents the load of the ~/.emacs or ~/.emacs.d/init.el in later versions of Emacs.

The filename is compiled in. There is no way to modify the expected init file without recompiling the application that I am aware of.

You can suppress the initialization file with the -q , but then load a file with the -l option. So something like you described gets you everything you would expect loaded from the site files:

emacs -q -l ~/.emacs2

If you are looking for some kind of dependent load from the ~/.emacs.d/init.el or ~/.emacs, then you might find some way to load a file based upon the environment. The init file then becomes your decision tree. I do this for identifying where my customization is held to use the same emacs init file for multiple workstations. Here is the code for that as an example:

(cond ((< emacs-major-version 24)
   (setq custom-file "~/.emacs.d/.emacs-23-custom.el"))
  (t (setq custom-file "~/.emacs.d/.emacs-24-custom.el")))

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.