When loading things like themes from custom directories, is it possible to specify a path relative to the init.el file, rather than an absolute path?

I ask because I want to be able to use the same config file across my OSX and Windows machines, where an absolute path like ~/.emacs.d/themes means something different on each machine (I'm not even sure how Windows handles ~)

  • 1
    MS Windows handles ~/ the same way: as your home directory, the value of environment variable HOME.
    – Drew
    Dec 19, 2015 at 22:02
  • @Drew I just tried to cd ~/ in cmd but the path could not be found, despite having the HOME variable correctly set...
    – Simon
    Dec 19, 2015 at 22:45
  • Normally, cd is enough for going to your home directory. Also, you're better use powershell, cmd is definitely out-dated.
    – Nsukami _
    Dec 19, 2015 at 23:07
  • Did you start with emacs -Q? Did you define environment variable HOME? Did you do M-x cd RET ~/ RET? Works for me.
    – Drew
    Dec 19, 2015 at 23:16
  • 1
    The Windows cmd.exe shell does not understand ~, but Emacs on Windows will handle it. @Nsukami_: cd (at a cmd prompt) will print the current directory, not change to your home dir.
    – glucas
    Dec 20, 2015 at 1:29

2 Answers 2


You can use ~/ in your init file and it will work fine on Windows. I always define a HOME environment variable and put my .emacs.d there, but there are other approaches. See the FAQ for the details of how Emacs decides what to use for home.

You can also build paths with the user-emacs-directory variable, if you prefer:

 (expand-file-name "foo.el" user-emacs-directory)

which in my case would be interchangeable with just "~/.emacs.d/foo.el".


  • If memory serves, you can also use MS Windows environment variables in file name (they will be expanded), however you'd need to use UNIX syntax (i.e. $PROGRAMFILES instead of %PROGRAMFILES%, but I cannot check it at the moment).
    – wvxvw
    Dec 20, 2015 at 19:10
  • 1
    You can also use locate-user-init-file instead.
    – user227
    Dec 20, 2015 at 22:37

load-relative was written to do something like this. Its purpose those was to do relative linking within a package, but I believe it can be used here as well.

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.