If I have a folder structure set up like this:
~/Projects
emacs
package1
package1-helpers
package2
package2-helpers
package2-more-helpers
package3
package3-helpers
How do I add these folders:
...to the load-path
from my .emacs file?
I basically need a short automated version of this code:
(add-to-list 'load-path "~/Projects/emacs")
(add-to-list 'load-path "~/Projects/emacs/package1")
(add-to-list 'load-path "~/Projects/emacs/package2")
(add-to-list 'load-path "~/Projects/emacs/package3")
To load an Emacs Lisp file, type M-x load-file . This command reads a file name using the minibuffer, and executes the contents of that file as Emacs Lisp code. It is not necessary to visit the file first; this command reads the file directly from disk, not from an existing Emacs buffer.
You can change this with M-x cd and type in whatever directory you would like to be the default instead (and by default I mean the one that will show up when you do C-x C-f ). If you start emacs without opening a file, you will end up with the *scratch* buffer open.
In Emacs, type M-x dired. You will be prompted for the directory to open. Type in the directory to display, or press Return to open the default directory.
(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)))))
Here's something I use in my .emacs:
(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))
If you look at the description for normal-top-level-add-subdirs-to-load-path, it's somewhat smart about picking which directories to exclude.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With