al-guix-autoload.el 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. ;;; al-guix-autoload.el --- Additional functionality to autoload Guix packages
  2. ;; Copyright © 2014-2016 Alex Kost
  3. ;; This program is free software; you can redistribute it and/or modify
  4. ;; it under the terms of the GNU General Public License as published by
  5. ;; the Free Software Foundation, either version 3 of the License, or
  6. ;; (at your option) any later version.
  7. ;;
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;;
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (require 'al-autoload)
  17. (require 'al-file)
  18. (defvar al/guix-emacs-autoloads nil
  19. "List of the last loaded Emacs autoloads.")
  20. (defun al/guix-emacs-directory (profile)
  21. "Return directory with Emacs packages installed in PROFILE."
  22. (expand-file-name "share/emacs/site-lisp" profile))
  23. (defun al/guix-emacs-directories (profile)
  24. "Return list of directories under PROFILE that contain Emacs packages.
  25. This includes both `share/emacs/site-lisp/guix.d/PACKAGE'
  26. sub-directories and `share/emacs/site-lisp' itself.
  27. Return nil, if Emacs packages are not installed in PROFILE."
  28. (let ((root-dir (al/guix-emacs-directory profile)))
  29. (when (file-directory-p root-dir)
  30. (let* ((pkgs-dir (expand-file-name "guix.d" root-dir))
  31. (pkgs-dirs (when (file-directory-p pkgs-dir)
  32. (al/subdirs pkgs-dir))))
  33. (cons root-dir pkgs-dirs)))))
  34. (defun al/guix-autoload-emacs-packages (&rest profiles)
  35. "Autoload Emacs packages installed in Guix PROFILES."
  36. (dolist (profile profiles)
  37. (let ((dirs (al/guix-emacs-directories profile)))
  38. (when dirs
  39. (let* ((autoloads (cl-mapcan #'al/find-autoloads dirs))
  40. (new-autoloads (cl-nset-difference autoloads
  41. al/guix-emacs-autoloads
  42. :test #'string=)))
  43. (dolist (dir dirs)
  44. (cl-pushnew (directory-file-name dir)
  45. load-path
  46. :test #'string=))
  47. (dolist (autoload new-autoloads)
  48. (load autoload 'noerror))
  49. (setq al/guix-emacs-autoloads
  50. (append new-autoloads al/guix-emacs-autoloads)))))))
  51. (provide 'al-guix-autoload)
  52. ;;; al-guix-autoload.el ends here