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.

Drew
  • 75,699
  • 9
  • 109
  • 225
Edman
  • 1,167
  • 7
  • 13

2 Answers2

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

(let ((default-directory my-packages-dir))
  (normal-top-level-add-subdirs-to-load-path))
Fran Burstall
  • 3,665
  • 10
  • 18
2
(defvar my-packages-directory "~/.emacs.d/packages")

(dolist (package-directory 
          (directory-files my-packages-directory :absolute))
  (add-to-list 'load-path package-directory))
Phil Hudson
  • 1,651
  • 10
  • 13
  • 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 '22 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. – Phil Hudson Apr 15 '22 at 16:08
  • @Fran Burstall's solution is better. – Phil Hudson Apr 15 '22 at 16:54