 
   ; Find all the enabled homectl packages and load them/add them to Emacs's
   ; paths.
+  (homectl-update-env "PATH" "bin")
+  (cond
+   ((string= system-type "darwin")
+    (homectl-update-env "DYLD_FRAMEWORK_PATH" "Frameworks")
+    (homectl-update-env "DYLD_LIBRARY_PATH" "lib"))
+   ((string= system-type "linux")
+    (homectl-update-env "LD_LIBRARY_PATH" "lib")
+    (homectl-update-env "LD_LIBRARY_PATH" "lib32")
+    (homectl-update-env "LD_LIBRARY_PATH" "lib64")))
+
+  ; Update emacs internal paths from environment variables
+  (setq exec-path (append (split-string (getenv "PATH") ":" t) exec-path))
+  (setq load-path (append (process-lines homectl-bin "path" "emacs")
+                          load-path))
+
+  ; Load all emacs packages from homectl
+  (dolist (pdir (process-lines homectl-bin "path" "emacs"))
+    (dolist (f (directory-files pdir nil "^[^.].*\.el"))
+      (let ((pkg (replace-regexp-in-string "\.el$" "" f)))
+        (message "[homectl] Loading %s" pkg)
+        (require (intern pkg)))))
+
+  ; Load old-style homectl hooks
+  (message "[homectl] Loading standard init files...")
   (homectl-foreach-enabled pkg
     (homectl-enable-pkg pkg)))
 

;;; Customization
;;;

(defvar homectl-dir (concat (getenv "HOME") "/.homectl")
  "The location of the homectl directory.  You should not change
  this unless you're a homectl developer and you change it in all
  the other places where it's hard-coded. :)")

(defgroup homectl nil "Homectl configuration options" :tag "Homectl")



(defmacro homectl-foreach-enabled (path-var &rest body)
  "Loop through each enabled homectl package, placing its path in /path-var/."
  `(dolist (,path-var (process-lines homectl-bin "list"))
     (when (null (string-match-p "^\\." (file-name-nondirectory ,path-var)))
       ,@body)))

