Commit | Line | Data |
---|---|---|
457f60fa AK |
1 | ;;; guix.el --- Interface for GNU Guix package manager |
2 | ||
eb097f36 | 3 | ;; Copyright © 2014, 2015 Alex Kost <alezost@gmail.com> |
457f60fa AK |
4 | |
5 | ;; Package-Requires: ((geiser "0.3")) | |
6 | ;; Keywords: tools | |
7 | ||
8 | ;; This file is part of GNU Guix. | |
9 | ||
10 | ;; GNU Guix is free software; you can redistribute it and/or modify | |
11 | ;; it under the terms of the GNU General Public License as published by | |
12 | ;; the Free Software Foundation, either version 3 of the License, or | |
13 | ;; (at your option) any later version. | |
14 | ||
15 | ;; GNU Guix is distributed in the hope that it will be useful, | |
16 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | ;; GNU General Public License for more details. | |
19 | ||
20 | ;; You should have received a copy of the GNU General Public License | |
21 | ;; along with this program. If not, see <http://www.gnu.org/licenses/>. | |
22 | ||
23 | ;;; Commentary: | |
24 | ||
25 | ;; This package provides an interface for searching, listing and getting | |
26 | ;; information about Guix packages and generations; and for | |
27 | ;; installing/upgrading/removing packages. | |
28 | ||
29 | ;;; Code: | |
30 | ||
dfeb0239 | 31 | (require 'guix-base) |
457f60fa AK |
32 | (require 'guix-list) |
33 | (require 'guix-info) | |
189cea27 | 34 | (require 'guix-utils) |
eb097f36 | 35 | (require 'guix-read) |
457f60fa AK |
36 | |
37 | (defgroup guix nil | |
38 | "Interface for Guix package manager." | |
39 | :prefix "guix-" | |
40 | :group 'external) | |
41 | ||
46e17df6 AK |
42 | (defgroup guix-faces nil |
43 | "Guix faces." | |
44 | :group 'guix | |
45 | :group 'faces) | |
46 | ||
457f60fa AK |
47 | (defcustom guix-list-single-package nil |
48 | "If non-nil, list a package even if it is the only matching result. | |
49 | If nil, show a single package in the info buffer." | |
50 | :type 'boolean | |
51 | :group 'guix) | |
52 | ||
457f60fa AK |
53 | (defvar guix-search-params '(name synopsis description) |
54 | "Default list of package parameters for searching by regexp.") | |
55 | ||
56 | (defvar guix-search-history nil | |
57 | "A history of minibuffer prompts.") | |
58 | ||
23459fa5 | 59 | (defun guix-get-show-packages (profile search-type &rest search-vals) |
457f60fa AK |
60 | "Search for packages and show results. |
61 | ||
23459fa5 AK |
62 | If PROFILE is nil, use `guix-current-profile'. |
63 | ||
457f60fa AK |
64 | See `guix-get-entries' for the meaning of SEARCH-TYPE and |
65 | SEARCH-VALS. | |
66 | ||
67 | Results are displayed in the list buffer, unless a single package | |
68 | is found and `guix-list-single-package' is nil." | |
23459fa5 AK |
69 | (or profile (setq profile guix-current-profile)) |
70 | (let ((packages (guix-get-entries profile guix-package-list-type | |
3472bb20 AK |
71 | search-type search-vals |
72 | (guix-get-params-for-receiving | |
73 | 'list guix-package-list-type)))) | |
457f60fa AK |
74 | (if (or guix-list-single-package |
75 | (cdr packages)) | |
23459fa5 | 76 | (guix-set-buffer profile packages 'list guix-package-list-type |
dfeb0239 | 77 | search-type search-vals) |
23459fa5 | 78 | (let ((packages (guix-get-entries profile guix-package-info-type |
3472bb20 AK |
79 | search-type search-vals |
80 | (guix-get-params-for-receiving | |
81 | 'info guix-package-info-type)))) | |
23459fa5 | 82 | (guix-set-buffer profile packages 'info guix-package-info-type |
dfeb0239 | 83 | search-type search-vals))))) |
457f60fa | 84 | |
23459fa5 AK |
85 | (defun guix-get-show-generations (profile search-type &rest search-vals) |
86 | "Search for generations and show results. | |
87 | ||
88 | If PROFILE is nil, use `guix-current-profile'. | |
89 | ||
90 | See `guix-get-entries' for the meaning of SEARCH-TYPE and | |
91 | SEARCH-VALS." | |
dfeb0239 | 92 | (apply #'guix-get-show-entries |
23459fa5 | 93 | (or profile guix-current-profile) |
dfeb0239 | 94 | 'list 'generation search-type search-vals)) |
457f60fa AK |
95 | |
96 | ;;;###autoload | |
23459fa5 | 97 | (defun guix-search-by-name (name &optional profile) |
457f60fa AK |
98 | "Search for Guix packages by NAME. |
99 | NAME is a string with name specification. It may optionally contain | |
23459fa5 AK |
100 | a version number. Examples: \"guile\", \"guile-2.0.11\". |
101 | ||
102 | If PROFILE is nil, use `guix-current-profile'. | |
103 | Interactively with prefix, prompt for PROFILE." | |
457f60fa | 104 | (interactive |
23459fa5 AK |
105 | (list (read-string "Package name: " nil 'guix-search-history) |
106 | (and current-prefix-arg | |
107 | (guix-profile-prompt)))) | |
108 | (guix-get-show-packages profile 'name name)) | |
457f60fa AK |
109 | |
110 | ;;;###autoload | |
23459fa5 | 111 | (defun guix-search-by-regexp (regexp &optional params profile) |
457f60fa AK |
112 | "Search for Guix packages by REGEXP. |
113 | PARAMS are package parameters that should be searched. | |
23459fa5 AK |
114 | If PARAMS are not specified, use `guix-search-params'. |
115 | ||
116 | If PROFILE is nil, use `guix-current-profile'. | |
117 | Interactively with prefix, prompt for PROFILE." | |
118 | (interactive | |
119 | (list (read-regexp "Regexp: " nil 'guix-search-history) | |
120 | nil | |
121 | (and current-prefix-arg | |
122 | (guix-profile-prompt)))) | |
123 | (guix-get-show-packages profile 'regexp regexp | |
124 | (or params guix-search-params))) | |
125 | ||
126 | ;;;###autoload | |
127 | (defun guix-installed-packages (&optional profile) | |
128 | "Display information about installed Guix packages. | |
129 | If PROFILE is nil, use `guix-current-profile'. | |
130 | Interactively with prefix, prompt for PROFILE." | |
457f60fa | 131 | (interactive |
23459fa5 AK |
132 | (list (and current-prefix-arg |
133 | (guix-profile-prompt)))) | |
134 | (guix-get-show-packages profile 'installed)) | |
457f60fa AK |
135 | |
136 | ;;;###autoload | |
23459fa5 AK |
137 | (defun guix-obsolete-packages (&optional profile) |
138 | "Display information about obsolete Guix packages. | |
139 | If PROFILE is nil, use `guix-current-profile'. | |
140 | Interactively with prefix, prompt for PROFILE." | |
141 | (interactive | |
142 | (list (and current-prefix-arg | |
143 | (guix-profile-prompt)))) | |
144 | (guix-get-show-packages profile 'obsolete)) | |
457f60fa AK |
145 | |
146 | ;;;###autoload | |
23459fa5 AK |
147 | (defun guix-all-available-packages (&optional profile) |
148 | "Display information about all available Guix packages. | |
149 | If PROFILE is nil, use `guix-current-profile'. | |
150 | Interactively with prefix, prompt for PROFILE." | |
151 | (interactive | |
152 | (list (and current-prefix-arg | |
153 | (guix-profile-prompt)))) | |
154 | (guix-get-show-packages profile 'all-available)) | |
457f60fa AK |
155 | |
156 | ;;;###autoload | |
23459fa5 AK |
157 | (defun guix-newest-available-packages (&optional profile) |
158 | "Display information about the newest available Guix packages. | |
159 | If PROFILE is nil, use `guix-current-profile'. | |
160 | Interactively with prefix, prompt for PROFILE." | |
161 | (interactive | |
162 | (list (and current-prefix-arg | |
163 | (guix-profile-prompt)))) | |
164 | (guix-get-show-packages profile 'newest-available)) | |
457f60fa AK |
165 | |
166 | ;;;###autoload | |
23459fa5 AK |
167 | (defun guix-generations (&optional profile) |
168 | "Display information about all generations. | |
169 | If PROFILE is nil, use `guix-current-profile'. | |
170 | Interactively with prefix, prompt for PROFILE." | |
171 | (interactive | |
172 | (list (and current-prefix-arg | |
173 | (guix-profile-prompt)))) | |
174 | (guix-get-show-generations profile 'all)) | |
457f60fa AK |
175 | |
176 | ;;;###autoload | |
23459fa5 | 177 | (defun guix-last-generations (number &optional profile) |
457f60fa | 178 | "Display information about last NUMBER generations. |
23459fa5 AK |
179 | If PROFILE is nil, use `guix-current-profile'. |
180 | Interactively with prefix, prompt for PROFILE." | |
181 | (interactive | |
182 | (list (read-number "The number of last generations: ") | |
183 | (and current-prefix-arg | |
184 | (guix-profile-prompt)))) | |
185 | (guix-get-show-generations profile 'last number)) | |
457f60fa | 186 | |
189cea27 | 187 | ;;;###autoload |
23459fa5 | 188 | (defun guix-generations-by-time (from to &optional profile) |
189cea27 | 189 | "Display information about generations created between FROM and TO. |
23459fa5 AK |
190 | FROM and TO should be time values. |
191 | If PROFILE is nil, use `guix-current-profile'. | |
192 | Interactively with prefix, prompt for PROFILE." | |
189cea27 AK |
193 | (interactive |
194 | (list (guix-read-date "Find generations (from): ") | |
23459fa5 AK |
195 | (guix-read-date "Find generations (to): ") |
196 | (and current-prefix-arg | |
197 | (guix-profile-prompt)))) | |
198 | (guix-get-show-generations profile 'time | |
189cea27 AK |
199 | (float-time from) |
200 | (float-time to))) | |
201 | ||
eb097f36 AK |
202 | ;;;###autoload |
203 | (defun guix-edit (id-or-name) | |
204 | "Edit (go to location of) package with ID-OR-NAME." | |
205 | (interactive (list (guix-read-package-name))) | |
206 | (let ((loc (guix-package-location id-or-name))) | |
207 | (if loc | |
208 | (guix-find-location loc) | |
209 | (message "Couldn't find package location.")))) | |
210 | ||
457f60fa AK |
211 | (provide 'guix) |
212 | ||
213 | ;;; guix.el ends here |