Adding Subdirectories to Load Path
Asked Answered
J

2

19

Rather than individually specifing each subdirectory in my plugins directory I want to be able to automatically load them, to that end I included the following to my .emacs file:

(let ((base  "~/.emacs.d/plugins/"))
      (normal-top-level-add-subdirs-to-load-path))

require 'rinari
require 'yasnippet

Unfortunately the above results in: File error: Cannot open load file, rinari

Anyone know what's wrong and how to fix it?

Jose answered 6/9, 2011 at 15:20 Comment(0)
F
21

You're so close...

(let ((default-directory "~/.emacs.d/plugins/"))
  (normal-top-level-add-subdirs-to-load-path))

normal-top-level-add-subdirs-to-load-path works off the current directory, which you can set via the variable default-directory - not base like you tried.

Fretted answered 6/9, 2011 at 16:1 Comment(1)
Thanks, I didn't know default-directory was a special variable.Jose
R
4

You might investigate the role of the subdirs.el files during startup. It is a good way get subdirectories into your load-path.

For example, much of the default load-path arises as a consequence of the files discovered by this command:
find /usr -name subdirs.el

Rayerayfield answered 12/11, 2014 at 12:55 Comment(1)
Ah, nice! Yes, see C-h i g (elisp) Startup Summary and C-h f normal-top-level-add-subdirs-to-load-path and and C-h f normal-top-level-add-to-load-path, and look at the usage of those in existing subdirs.el files.Damage

© 2022 - 2024 — McMap. All rights reserved.