Federico Beffa (2015-06-18 21:32 +0300) wrote:

> On Wed, Jun 17, 2015 at 8:21 PM, Alex Kost <alez...@gmail.com> wrote:
>> The code for loading "…-autoloads.el" files is placed in
>> "guix-emacs.el", so perhaps it would be enough to adjust:
>>
>> - 'guix-emacs-find-autoloads' to make it look at subdirs;
>>
>> - 'guix-emacs-load-autoloads' to add the subdir to 'load-path' before
>>   loading "…-autoloads.el".
>
> If you feel like wanting to adapt it yourself, please go on. I have no
> experience with elisp apart from trivial things in my ./emacs. file.
>
> Otherwise, I will look into it.

Thanks, I would like to adapt it myself.  I think the attached patch
should be enough to make the packages installed in
"~/.guix-profile/share/emacs/site-lisp/guix.d" be properly autoloaded.
I'll push this commit into "wip-emacs" when it appears, if you don't
mind.

>From 7110d5d4a795f91259af37b48a2909ad9451a42d Mon Sep 17 00:00:00 2001
From: Alex Kost <alez...@gmail.com>
Date: Fri, 19 Jun 2015 12:31:59 +0300
Subject: [PATCH] emacs: Find autoloads in "guix.d" subdirectories.

Co-authored-by: Federico Beffa <be...@fbengineering.ch>.

* emacs/guix-emacs.el (guix-emacs-find-autoloads-in-directory,
  guix-emacs-subdirs): New functions.
  (guix-emacs-find-autoloads): Search for autoloads in "guix.d"
  subdirectories.
  (guix-emacs-load-autoloads): Add subdirectories to 'load-path'.
---
 emacs/guix-emacs.el | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/emacs/guix-emacs.el b/emacs/guix-emacs.el
index 512a2e2..8be2f36 100644
--- a/emacs/guix-emacs.el
+++ b/emacs/guix-emacs.el
@@ -42,13 +42,33 @@ If PROFILE is nil, use `guix-user-profile'."
   (expand-file-name "share/emacs/site-lisp"
                     (or profile guix-user-profile)))
 
+(defun guix-emacs-find-autoloads-in-directory (directory)
+  "Return list of Emacs 'autoloads' files in DIRECTORY."
+  (directory-files directory 'full-name "-autoloads\\.el\\'" 'no-sort))
+
+(defun guix-emacs-subdirs (directory)
+  "Return list of DIRECTORY subdirectories."
+  (cl-remove-if (lambda (file)
+                  (or (string-match-p (rx "/." string-end) file)
+                      (string-match-p (rx "/.." string-end) file)
+                      (not (file-directory-p file))))
+                (directory-files directory 'full-name nil 'no-sort)))
+
 (defun guix-emacs-find-autoloads (&optional profile)
   "Return list of autoloads of Emacs packages installed in PROFILE.
 If PROFILE is nil, use `guix-user-profile'.
 Return nil if there are no emacs packages installed in PROFILE."
-  (let ((dir (guix-emacs-directory profile)))
-    (if (file-directory-p dir)
-        (directory-files dir 'full-name "-autoloads\\.el\\'")
+  (let ((elisp-root-dir (guix-emacs-directory profile)))
+    (if (file-directory-p elisp-root-dir)
+        (let ((elisp-pkgs-dir (expand-file-name "guix.d" elisp-root-dir))
+              (root-autoloads (guix-emacs-find-autoloads-in-directory
+                               elisp-root-dir)))
+          (if (file-directory-p elisp-pkgs-dir)
+              (let ((pkgs-autoloads
+                     (cl-mapcan #'guix-emacs-find-autoloads-in-directory
+                                (guix-emacs-subdirs elisp-pkgs-dir))))
+                (append root-autoloads pkgs-autoloads))
+            root-autoloads))
       (message "Directory '%s' does not exist." dir)
       nil)))
 
@@ -63,7 +83,10 @@ installed in `guix-user-profile'."
          (files (if all
                     autoloads
                   (cl-nset-difference autoloads guix-emacs-autoloads
-                                      :test #'string=))))
+                                      :test #'string=)))
+         (dirs (mapcar #'file-name-directory files))
+         (dirs (cl-remove-duplicates dirs :test #'string=)))
+    (setq load-path (append dirs load-path))
     (dolist (file files)
       (load file 'noerror))
     (setq guix-emacs-autoloads autoloads)))
-- 
2.4.2

Reply via email to