tags:

views:

390

answers:

2

The question is similar to one.

However, it differs in putting all subdirectories achievable in the folder too.

Jouni's code which puts first level folders achievable

(let ((base "~/Projects/emacs"))
  (add-to-list 'load-path base)
  (dolist (f (directory-files base))
    (let ((name (concat base "/" f)))
      (when (and (file-directory-p name) 
                 (not (equal f ".."))
                 (not (equal f ".")))
        (add-to-list 'load-path name)))))

How can you put a directory and all its subdirectories to load-path in Emacs?

+7  A: 

My answer in the other question does handle multiple levels of subdirectories.

The code for reference

(let* ((my-lisp-dir "~/.elisp/")
       (default-directory my-lisp-dir)
       (orig-load-path load-path))
  (setq load-path (cons my-lisp-dir nil))
  (normal-top-level-add-subdirs-to-load-path)
  (nconc load-path orig-load-path))
Nicholas Riley
@Nicholas: Thank you for pointing that out!
Masi
I am rather new in Lisp. What does let* mean in your code?
Masi
@Nicholas: Why do you use the star?
Masi
@Nicholas: Which line does exclude PATHs in your command?
Masi
let* is shorthand for many nested lets, each of which binds a single variable; regular old let binds all the variables at once. So, with let instead of let*, I could not refer to my-lisp-dir in the binding for default-directory because it would not be available until the body of the let.
Nicholas Riley
To see what directories are excluded, run C-h f normal-top-level-add-subdirs-to-load-path.
Nicholas Riley
@Nicholas: How can you see what is inside the functions such as the one in you last comment?
Masi
If you click on "startup.el" in the help window, you'll go to the function's definition (assuming it's written in elisp, not C.)
Nicholas Riley
@Nicholas: Thank you!
Masi
+1  A: 
Robert P. Goldman