3

I run all my Emacs packages manually without any package manager. My setup is a simple init.el file with this kind of direction:

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

(add-to-list 'load-path "~/.emacs.d/packages/dired+")
    
(require 'ace-window)
(require 'dired+)

Is there a way simply to specify the ~/.emacs.d/packages/ directory without having to spell out all the folders in separate lines as above. I.e. simply point Emacs to treat all subfolders as packages.

2
  • 1
    Any reason why you're not just putting all of the elisp into one directory?
    – phils
    Apr 15, 2022 at 6:20
  • That's a good idea. I suppose it is because I have simply been cloning the packages from git.
    – Edman
    Apr 15, 2022 at 6:22

2 Answers 2

7
(defvar my-packages-dir "~/.emacs.d/packages")

(let ((default-directory my-packages-dir))
  (normal-top-level-add-subdirs-to-load-path))
2
(defvar my-packages-directory "~/.emacs.d/packages")

(dolist (package-directory 
          (directory-files my-packages-directory :absolute))
  (add-to-list 'load-path package-directory))
3
  • 1
    This generated an error from Emacs: Warning (initialization): Your ‘load-path’ seems to contain your ‘.emacs.d’ directory: c:/red/.emacs.d/packages/.. This is likely to cause problems... Consider using a subdirectory instead, e.g.: c:/red/.emacs.d/lisp. The error persisted after I made a lips directory in .emacs.d, but went once I made a lisp directory off my home folder.
    – Edman
    Apr 15, 2022 at 12:29
  • 1
    Do you have a subdirectory called "packages" into which you clone your various git-based packages? That is essential for this code to work. Apr 15, 2022 at 16:08
  • @Fran Burstall's solution is better. Apr 15, 2022 at 16:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.