Commit | Line | Data |
---|---|---|
12f2490a AK |
1 | ;;; guix-emacs.el --- Emacs packages installed with Guix |
2 | ||
3 | ;; Copyright © 2014 Alex Kost <alezost@gmail.com> | |
4 | ||
5 | ;; This file is part of GNU Guix. | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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/>. | |
19 | ||
20 | ;;; Commentary: | |
21 | ||
22 | ;; This file provides auxiliary code for working with Emacs packages | |
23 | ;; installed with Guix. | |
24 | ||
25 | ;;; Code: | |
26 | ||
27 | (require 'guix-profiles) | |
28 | ||
29 | (defcustom guix-emacs-activate-after-operation t | |
30 | "Activate Emacs packages after installing. | |
31 | If nil, do not load autoloads of the Emacs packages after | |
32 | they are successfully installed." | |
33 | :type 'boolean | |
34 | :group 'guix) | |
35 | ||
36 | (defvar guix-emacs-autoloads nil | |
37 | "List of the last loaded Emacs autoloads.") | |
38 | ||
39 | (defun guix-emacs-directory (&optional profile) | |
40 | "Return directory with Emacs packages installed in PROFILE. | |
41 | If PROFILE is nil, use `guix-user-profile'." | |
42 | (expand-file-name "share/emacs/site-lisp" | |
43 | (or profile guix-user-profile))) | |
44 | ||
45 | (defun guix-emacs-find-autoloads (&optional profile) | |
46 | "Return list of autoloads of Emacs packages installed in PROFILE. | |
47 | If PROFILE is nil, use `guix-user-profile'. | |
48 | Return nil if there are no emacs packages installed in PROFILE." | |
49 | (let ((dir (guix-emacs-directory profile))) | |
50 | (if (file-directory-p dir) | |
51 | (directory-files dir 'full-name "-autoloads\\.el\\'") | |
52 | (message "Directory '%s' does not exist." dir) | |
53 | nil))) | |
54 | ||
55 | ;;;###autoload | |
56 | (defun guix-emacs-load-autoloads (&optional all) | |
57 | "Load autoloads for Emacs packages installed in a user profile. | |
58 | If ALL is nil, activate only those packages that were installed | |
59 | after the last activation, otherwise activate all Emacs packages | |
60 | installed in `guix-user-profile'." | |
61 | (interactive "P") | |
62 | (let* ((autoloads (guix-emacs-find-autoloads)) | |
63 | (files (if all | |
64 | autoloads | |
65 | (cl-nset-difference autoloads guix-emacs-autoloads | |
66 | :test #'string=)))) | |
67 | (dolist (file files) | |
68 | (load file 'noerror)) | |
69 | (setq guix-emacs-autoloads autoloads))) | |
70 | ||
71 | (defun guix-emacs-load-autoloads-maybe () | |
72 | "Load autoloads for Emacs packages if needed. | |
73 | See `guix-emacs-activate-after-operation' for details." | |
74 | (and guix-emacs-activate-after-operation | |
75 | (guix-emacs-load-autoloads))) | |
76 | ||
77 | (provide 'guix-emacs) | |
78 | ||
79 | ;;; guix-emacs.el ends here |