(defun guix-package-desc-name (pkg-desc) "Return the name of the package. PKG-DESC is the unprocessed list read from the package-description file." (nth 1 pkg-desc)) (defun guix-package-description-file (dir) "Return the name of the description file of the package in DIR. (From Emacs 'package--description-file' in 'startup.el')." (concat (let ((subdir (file-name-nondirectory (directory-file-name dir)))) (if (string-match "\\([^.].*?\\)-\\([0-9]+\\(?:[.][0-9]+\\|\\(?:pre\\|beta\\|alpha\\)[0-9]+\\)*\\)" subdir) (match-string 1 subdir) subdir)) "-pkg.el")) (defun guix-package-load-descriptor (pkg-dir) "Return the uninterpreted content of the description file in directory PKG-DIR. (Adapted from Emacs 'package-load-descriptor' in 'package.el'.)" (let ((pkg-file (expand-file-name (guix-package-description-file pkg-dir) pkg-dir))) (when (file-exists-p pkg-file) (with-temp-buffer (insert-file-contents pkg-file) (goto-char (point-min)) (read (current-buffer)))))) (defun guix-package-load-all (dir) "Activate all packages below DIR. (Adapted from Emacs 'package-activate-1' in 'package.el'.)" (when (file-directory-p dir) (dolist (subdir (directory-files dir)) (let ((pkg-dir (expand-file-name subdir dir))) (when (file-directory-p pkg-dir) (let* ((pkg-desc (guix-package-load-descriptor pkg-dir)) (name (guix-package-desc-name pkg-desc)) (pkg-file (expand-file-name (format "%s-autoloads.el" name) pkg-dir))) (when (file-exists-p pkg-file) ;; For some packages to be properly loaded (e.g., ;; AUCTeX), they must be on the load-path. However, ;; some packages add themselves to the load-path. Hence ;; the check to avoid duplications. (push pkg-dir load-path) (let ((old-lp load-path)) (with-demoted-errors (load pkg-file nil t)) (unless (eq old-lp load-path) (setq load-path old-lp)))))))))) (let* ((dir (concat (getenv "HOME") ".guix-profile/share/emacs/site-lisp/guix.d"))) (when (file-exists-p dir) (guix-package-load-all dir)))