The Goal

Place everything related to emacs in ~/.config/.emacs.d

What I Have Done

  • Created /usr/share/emacs/site-lisp/site-start.el which contain the following code:
(setq user-init-file "~/.config/.emacs.d/init.el")
(setq user-emacs-directory "~/.config/.emacs.d")
(load user-init-file)


The Outcome

  • emacs still creates ~/.emacs.d which contains the auto-save-list directory.

  • Changing the value of variables through M-x customize creates the ~/.emacs file.

  • Examining the value of variables modified within site-start.el I get the following result:

user-init-file is a variable defined in ‘C source code’.
Its value is "~/.emacs"

user-emacs-directory is a variable defined in ‘subr.el’.
Its value is "~/.config/.emacs.d"

Is it possible to achieve what I want? This is part of my effort to organize my HOME directory. I have read the following documentation.

1 Answer 1


You can't do that. Emacs doesn't care if you've (unexpectedly) set user-init-file -- it looks for your init file in the places it's hard-coded to look for it, and it then sets user-init-file to the path of the init file it located.

However if you wait for Emacs 27 (or try a pretest release; currently 27.0.90 at time of writing), it essentially provides what you're looking for.

See the NEWS for details:

Emacs can now use the XDG convention for init files. The 'XDG_CONFIG_HOME' environment variable (which defaults to "~/.config") specifies the XDG configuration parent directory. Emacs checks for "init.el" and other configuration files inside the "emacs" subdirectory of 'XDG_CONFIG_HOME', i.e. "$XDG_CONFIG_HOME/emacs/init.el"

However, Emacs will still initially look for init files in their traditional locations if "~/.emacs.d" or "~/.emacs" exist, even if "$XDG_CONFIG_HOME/emacs" also exists. This means that you must delete or rename any existing "~/.emacs.d" and "~/.emacs" to enable use of the XDG directory.

If "~/.emacs.d" does not exist, and Emacs has decided to use it (i.e. "$XDG_CONFIG_HOME/emacs" does not exist), Emacs will create it. Emacs will never create "$XDG_CONFIG_HOME/emacs".

Whichever directory Emacs decides to use, it will set 'user-emacs-directory' to point to it.

Your Answer

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

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