Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the path from which init.el was loaded?

Tags:

emacs

I am looking to create a custom config for emacs to use for Erlang work and I want to refer to my custom EDTS repo as being under the directory from which init.el was loaded. Right now I have this:

(add-to-list 'load-path "~/.emacs-edts/edts/")

But I would rather not hardcode it and refer to it by variable.

Suggestions?

like image 749
Robert Simmons Jr. Avatar asked Nov 26 '25 13:11

Robert Simmons Jr.


2 Answers

Strictly speaking the answer is (file-name-directory user-init-file), but instead see C-hv user-emacs-directory

like image 169
phils Avatar answered Nov 28 '25 15:11

phils


I have the following snippet in my init.el:

(setq my-init-dir
    (file-name-directory
        (or load-file-name (buffer-file-name))))

This has the advantage of working whether init.el is in your emacs.d directory or not.

like image 30
Stuart Hickinbottom Avatar answered Nov 28 '25 17:11

Stuart Hickinbottom