gnu: youtube-dl: Update to 2014.12.15.
[jackhill/guix/guix.git] / emacs / guix.el
1 ;;; guix.el --- Interface for GNU Guix package manager
2
3 ;; Copyright © 2014 Alex Kost <alezost@gmail.com>
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
31 (require 'guix-base)
32 (require 'guix-list)
33 (require 'guix-info)
34 (require 'guix-utils)
35
36 (defgroup guix nil
37 "Interface for Guix package manager."
38 :prefix "guix-"
39 :group 'external)
40
41 (defcustom guix-list-single-package nil
42 "If non-nil, list a package even if it is the only matching result.
43 If nil, show a single package in the info buffer."
44 :type 'boolean
45 :group 'guix)
46
47 (defvar guix-search-params '(name synopsis description)
48 "Default list of package parameters for searching by regexp.")
49
50 (defvar guix-search-history nil
51 "A history of minibuffer prompts.")
52
53 (defun guix-get-show-packages (profile search-type &rest search-vals)
54 "Search for packages and show results.
55
56 If PROFILE is nil, use `guix-current-profile'.
57
58 See `guix-get-entries' for the meaning of SEARCH-TYPE and
59 SEARCH-VALS.
60
61 Results are displayed in the list buffer, unless a single package
62 is found and `guix-list-single-package' is nil."
63 (or profile (setq profile guix-current-profile))
64 (let ((packages (guix-get-entries profile guix-package-list-type
65 search-type search-vals
66 (guix-get-params-for-receiving
67 'list guix-package-list-type))))
68 (if (or guix-list-single-package
69 (cdr packages))
70 (guix-set-buffer profile packages 'list guix-package-list-type
71 search-type search-vals)
72 (let ((packages (guix-get-entries profile guix-package-info-type
73 search-type search-vals
74 (guix-get-params-for-receiving
75 'info guix-package-info-type))))
76 (guix-set-buffer profile packages 'info guix-package-info-type
77 search-type search-vals)))))
78
79 (defun guix-get-show-generations (profile search-type &rest search-vals)
80 "Search for generations and show results.
81
82 If PROFILE is nil, use `guix-current-profile'.
83
84 See `guix-get-entries' for the meaning of SEARCH-TYPE and
85 SEARCH-VALS."
86 (apply #'guix-get-show-entries
87 (or profile guix-current-profile)
88 'list 'generation search-type search-vals))
89
90 ;;;###autoload
91 (defun guix-search-by-name (name &optional profile)
92 "Search for Guix packages by NAME.
93 NAME is a string with name specification. It may optionally contain
94 a version number. Examples: \"guile\", \"guile-2.0.11\".
95
96 If PROFILE is nil, use `guix-current-profile'.
97 Interactively with prefix, prompt for PROFILE."
98 (interactive
99 (list (read-string "Package name: " nil 'guix-search-history)
100 (and current-prefix-arg
101 (guix-profile-prompt))))
102 (guix-get-show-packages profile 'name name))
103
104 ;;;###autoload
105 (defun guix-search-by-regexp (regexp &optional params profile)
106 "Search for Guix packages by REGEXP.
107 PARAMS are package parameters that should be searched.
108 If PARAMS are not specified, use `guix-search-params'.
109
110 If PROFILE is nil, use `guix-current-profile'.
111 Interactively with prefix, prompt for PROFILE."
112 (interactive
113 (list (read-regexp "Regexp: " nil 'guix-search-history)
114 nil
115 (and current-prefix-arg
116 (guix-profile-prompt))))
117 (guix-get-show-packages profile 'regexp regexp
118 (or params guix-search-params)))
119
120 ;;;###autoload
121 (defun guix-installed-packages (&optional profile)
122 "Display information about installed Guix packages.
123 If PROFILE is nil, use `guix-current-profile'.
124 Interactively with prefix, prompt for PROFILE."
125 (interactive
126 (list (and current-prefix-arg
127 (guix-profile-prompt))))
128 (guix-get-show-packages profile 'installed))
129
130 ;;;###autoload
131 (defun guix-obsolete-packages (&optional profile)
132 "Display information about obsolete Guix packages.
133 If PROFILE is nil, use `guix-current-profile'.
134 Interactively with prefix, prompt for PROFILE."
135 (interactive
136 (list (and current-prefix-arg
137 (guix-profile-prompt))))
138 (guix-get-show-packages profile 'obsolete))
139
140 ;;;###autoload
141 (defun guix-all-available-packages (&optional profile)
142 "Display information about all available Guix packages.
143 If PROFILE is nil, use `guix-current-profile'.
144 Interactively with prefix, prompt for PROFILE."
145 (interactive
146 (list (and current-prefix-arg
147 (guix-profile-prompt))))
148 (guix-get-show-packages profile 'all-available))
149
150 ;;;###autoload
151 (defun guix-newest-available-packages (&optional profile)
152 "Display information about the newest available Guix packages.
153 If PROFILE is nil, use `guix-current-profile'.
154 Interactively with prefix, prompt for PROFILE."
155 (interactive
156 (list (and current-prefix-arg
157 (guix-profile-prompt))))
158 (guix-get-show-packages profile 'newest-available))
159
160 ;;;###autoload
161 (defun guix-generations (&optional profile)
162 "Display information about all generations.
163 If PROFILE is nil, use `guix-current-profile'.
164 Interactively with prefix, prompt for PROFILE."
165 (interactive
166 (list (and current-prefix-arg
167 (guix-profile-prompt))))
168 (guix-get-show-generations profile 'all))
169
170 ;;;###autoload
171 (defun guix-last-generations (number &optional profile)
172 "Display information about last NUMBER generations.
173 If PROFILE is nil, use `guix-current-profile'.
174 Interactively with prefix, prompt for PROFILE."
175 (interactive
176 (list (read-number "The number of last generations: ")
177 (and current-prefix-arg
178 (guix-profile-prompt))))
179 (guix-get-show-generations profile 'last number))
180
181 ;;;###autoload
182 (defun guix-generations-by-time (from to &optional profile)
183 "Display information about generations created between FROM and TO.
184 FROM and TO should be time values.
185 If PROFILE is nil, use `guix-current-profile'.
186 Interactively with prefix, prompt for PROFILE."
187 (interactive
188 (list (guix-read-date "Find generations (from): ")
189 (guix-read-date "Find generations (to): ")
190 (and current-prefix-arg
191 (guix-profile-prompt))))
192 (guix-get-show-generations profile 'time
193 (float-time from)
194 (float-time to)))
195
196 (provide 'guix)
197
198 ;;; guix.el ends here