6

When I start up emacs, I see

Warning (initialization): Your `load-path' seems to contain
your `.emacs.d' directory: ~/.emacs.d/
This is likely to cause problems...
Consider using a subdirectory instead, e.g.: /home/faheem/.emacs.d/lisp

I think I started seeing this message relatively recently, but in any case, here are the relevant lines in my .emacs.

(add-to-list 'load-path "~/.emacs.d/")
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/")
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/contrib")

Here is what my emacs.d directory looks like:

faheem@orwell:~/.emacs.d$ ls
abbrev_defs     edit-server.el  session.10dbde7765000140938718700000055430258  session.10dbde7765000142073356500000315430010
auto-save-list  elpa            session.10dbde7765000141759448100000009970011  tramp

What am I doing wrong, if anything?

Faheem Mitha
  • 406
  • 4
  • 16
  • You are not doing anything wrong *per se*. This is a warning that this set up is not considered a good idea. At the moment having a set up like this will work fine. – verdammelt Mar 07 '15 at 15:35
  • Maybe you must recently upgraded emacs? I got this error when I upgraded from one version to another a while ago. 24.2 to 24.3 I think. – Jordon Biondo Mar 09 '15 at 19:18
  • 1
    answered on [SO](http://stackoverflow.com/q/24779041/850781). – sds Jul 21 '15 at 14:48

1 Answers1

13

So when you read this warning message:

Warning (initialization): Your `load-path' seems to contain
your `.emacs.d' directory: ~/.emacs.d/
This is likely to cause problems...

and note that you have the following in your init file:

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

hopefully you can recognise that this is exactly what the warning was referring to?

You need to follow the recommendation:

Consider using a subdirectory instead, e.g.: /home/faheem/.emacs.d/lisp

by changing that line in your init file to this:

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

and then create that sub-directory: mkdir ~/.emacs.d/lisp

and finally take any elisp libraries (excluding your init file) that you yourself placed directly in ~/.emacs.d/, and move them into the new lisp sub-directory (in this case it looks like edit-server.el is the only file you need to move).

(and of course in future, you would add custom elisp libraries into that lisp directory, instead of putting them in ~/.emacs.d).

phils
  • 48,657
  • 3
  • 76
  • 115
  • I still don't understand why the earlier setup is wrong, and why I need to make this change. What about all the other directories in `.emacs.d`, e.g. `elpa`? Why don't they need to be moved? And will they still get loaded if I used `.emacs.d/lisp` instead? – Faheem Mitha Mar 07 '15 at 11:48
  • 15
    There's a difference between `~/.emacs.d/` and its subdirectories. It's fine to add subdirectories of `~/.emacs.d` to your `load-path`, but you should not add `~/.emacs.d/` to it. The reason is that Emacs libraries create data files in `~/.emacs.d/`, which might accidentally shadow real libraries if you add `~/.emacs.d/` to your `load-path`. –  Mar 07 '15 at 11:58
  • 1
    @lunaryorn thanks, that's a very helpful comment. Consider expanding it into a full answer. In particular, do you have a reference for "Emacs libraries create data files in ~/.emacs.d/, which might accidentally shadow real libraries"? An example woould be even better. Shadowing means loading your personal file of the same name because in the path before the real thing, right? I don't see why this would happen in this case. – Faheem Mitha Mar 08 '15 at 05:12
  • 3
    `calc.el` is an example. That is both the name of an Emacs library, and also the name of a configuration file which it writes to your `~/.emacs.d/` directory. If that directory is in your load-path ahead of the standard library paths, then once calc has written its config file, you would be unable to load the `calc` library. – phils Mar 08 '15 at 05:22
  • 1
    But in short, your load path shouldn't include directories to which Emacs (or other applications for that matter) are liable to write arbitrary files, and `~/.emacs.d` is such a directory. – phils Mar 08 '15 at 05:28
  • If anyone's still here: so, if I'd like to have a bunch of `(load "sz/...")` calls to load from `~/.emacs.d/sz` (instead of using "undecorated" `(load "...")` paths with `sz` added to `load-path`), as a gentle reminder to myself in 5 years that those are my own scripts, can I still do that without creating an artificial extra subdir _above_ `sz` just for the scoping to work? – Sz. Aug 17 '23 at 15:12
  • No; that would require putting `~/.emacs.d` in your load path. Your gentle reminder can instead be to name-space the elisp file names: `(load "sz-foo")` and you can then put the `sz` directory in your `load-path` (and the `sz-*` files in that directory). – phils Aug 17 '23 at 15:14
  • But if you don't want to name-space the file names themselves, then you also don't want their parent directory in your load path (as less distinct file names may be prone to conflicts, whether now or in future), so you'd want to go with the artificial extra subdir for your initial approach (and put that dir in load-path). – phils Aug 17 '23 at 15:18
  • _(Thanks for the instant replies despite the party having ended ~8 years ago. :) )_ Just to confirm my understanding: that "name-spacing" simply means prefixing the file names (not anything specific to elisp, which I'm not familiar with), right? – Sz. Aug 17 '23 at 15:36
  • Correct; simply a file naming convention of your own to reliably differentiate your file names from those of any other elisp files you might have installed at any point, so that you can't accidentally create a conflict. – phils Aug 17 '23 at 15:41