~/.emacs.d/
does not work like /etc/profile.d/
or /etc/modules-load.d/
or similar directories, i.e. Emacs does not automatically load any Emacs Lisp file in this directory.
In fact, Emacs explicitly advises against placing Emacs Lisp libraries in ~/.emacs.d/
. The byte compiler emits a warning if you add ~/.emacs.d/
to the load-path
.
Instead, create a new sub-directory, e.g. ~/.emacs.d/lisp
. Add this directory to your load-path
explicitly, with the following code in init.el
:
(add-to-list 'load-path (locate-user-emacs-file "lisp"))
Then, place your Emacs Lisp files in this directory, e.g. ~/.emacs.d/lisp/foo.el
, and load them in your init.el
:
(load "foo" nil 'no-message)
The best approach to avoid the dreaded .emacs bankruptcy is to actually avoid large customizations! Most notably, try to avoid any custom functions and commands.
Instead, try to a find an ELPA package that comes closest to what you want, and either try to get used to it, or customize it to your needs. If you don't find any, first try to write your own and distribute it on Github, Marmalade or MELPA.
Don't be afraid of maintaining a package in the public. You'll have to maintain your customization anyway, whether in your init.el
or not, so you can just as well let other Emacs users help you with this job.
Adding code to your init.el
should be your very last resort!