2

I've had just one single .emacs since the 1980s (not kidding). I feel like it's finally time to modernize, literatize, and put it in a modern place.

I see that emacs now prefers ~/.config/emacs/init.el and ~/.emacs.d/init.el. I'd like to go with ~/.config/emacs at least on Linux, to be XDG-compatible and make it simple to source-control all my emacs files.

Emacs creates a lot of temporary/cache/history-type files in ~/.emacs.d; is it possible for me to put my config files (and only those) in ~/.config/emacs and let emacs use ~/.emacs.d for all its other stuff, to not clutter my config's .gitignore? (straight repos, history, eln-cache, org-roam.db, etc.) If I try putting my init in ~/.config/emacs/init.el but leave my ~/.emacs.d existing (with no init file), I get vanilla emacs. So I assume the mere existence of the .emacs.d directory causes it to stop looking for ~/.config/emacs/init.el?

I use emacs on Linux, Windows and Mac, various versions and flavors, so I'd like to be able to keep my config as portable and simple (haha) as possible.

If it's not possible to separate my config from emacs's auto-generated stuff, I can certainly work with that; it'll just be a bigger .gitignore file I guess. But it would be nice to keep it separate.

1

1 Answer 1

0

According to the manual, Emacs will always look for your init file at three preferred locations, in order:

  1. ~/.emacs.el
  2. ~/.emacs
  3. ~/.emacs.d/init.el

before looking in the XDG-preferred location you'd like to use,

  1. ~/.config/emacs/init.el

It isn't the existence of ~/.emacs.d/ that causes Emacs to stop looking for ~/.config/emacs/init.el, but the existence of the specific files 1-3. When you tried #4 before and got vanilla Emacs, it's likely that you still had a ~/.emacs file remaining from the initial installation that blocked Emacs from finding #4, even though you didn't have #3.

As long as you don't have those files, then you're perfectly safe to have both ~/.config/emacs/init.el for configuration and ~/.emacs.d/ for temp files. In fact, that will happen automatically once #1-3 are gone and #4 exists.

1
  • 1
    That's not what happens: if emacs decides to use XDG-style, then user-emacs-directory is set to `~/.config/emacs"
    – rpluim
    Nov 16, 2022 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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