1 ;;; guix-emacs.el --- Emacs packages installed with Guix
3 ;; Copyright © 2014 Alex Kost <alezost@gmail.com>
5 ;; This file is part of GNU Guix.
7 ;; GNU Guix is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; GNU Guix is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
22 ;; This file provides auxiliary code for working with Emacs packages
23 ;; installed with Guix.
27 (require 'guix-profiles
)
30 (defcustom guix-emacs-activate-after-operation t
31 "Activate Emacs packages after installing.
32 If nil, do not load autoloads of the Emacs packages after
33 they are successfully installed."
37 (defvar guix-emacs-autoloads nil
38 "List of the last loaded Emacs autoloads.")
40 (defun guix-emacs-directory (&optional profile
)
41 "Return directory with Emacs packages installed in PROFILE.
42 If PROFILE is nil, use `guix-user-profile'."
43 (expand-file-name "share/emacs/site-lisp"
44 (or profile guix-user-profile
)))
46 (defun guix-emacs-find-autoloads-in-directory (directory)
47 "Return list of Emacs 'autoloads' files in DIRECTORY."
48 (directory-files directory
'full-name
"-autoloads\\.el\\'" 'no-sort
))
50 (defun guix-emacs-subdirs (directory)
51 "Return list of DIRECTORY subdirectories."
52 (cl-remove-if (lambda (file)
53 (or (string-match-p (rx "/." string-end
) file
)
54 (string-match-p (rx "/.." string-end
) file
)
55 (not (file-directory-p file
))))
56 (directory-files directory
'full-name nil
'no-sort
)))
58 (defun guix-emacs-find-autoloads (&optional profile
)
59 "Return list of autoloads of Emacs packages installed in PROFILE.
60 If PROFILE is nil, use `guix-user-profile'.
61 Return nil if there are no emacs packages installed in PROFILE."
62 (let ((elisp-root-dir (guix-emacs-directory profile
)))
63 (if (file-directory-p elisp-root-dir
)
64 (let ((elisp-pkgs-dir (expand-file-name "guix.d" elisp-root-dir
))
65 (root-autoloads (guix-emacs-find-autoloads-in-directory
67 (if (file-directory-p elisp-pkgs-dir
)
69 (cl-mapcan #'guix-emacs-find-autoloads-in-directory
70 (guix-emacs-subdirs elisp-pkgs-dir
))))
71 (append root-autoloads pkgs-autoloads
))
73 (message "Directory '%s' does not exist." elisp-root-dir
)
77 (defun guix-emacs-load-autoloads (&optional all
)
78 "Load autoloads for Emacs packages installed in a user profile.
79 Add autoloads directories to `load-path'.
80 If ALL is nil, activate only those packages that were installed
81 after the last activation, otherwise activate all Emacs packages
82 installed in `guix-user-profile'."
84 (let* ((autoloads (guix-emacs-find-autoloads))
87 (cl-nset-difference autoloads guix-emacs-autoloads
90 (cl-pushnew (file-name-directory file
) load-path
93 (setq guix-emacs-autoloads autoloads
)))
95 (defun guix-emacs-load-autoloads-maybe ()
96 "Load autoloads for Emacs packages if needed.
97 See `guix-emacs-activate-after-operation' for details."
98 (and guix-emacs-activate-after-operation
99 (guix-emacs-load-autoloads)))
101 (provide 'guix-emacs
)
103 ;;; guix-emacs.el ends here