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