1 ;;; guix-messages.el --- Minibuffer messages
3 ;; Copyright © 2014, 2015 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 `guix-result-message' function used to show a
23 ;; minibuffer message after displaying packages/generations in a
34 ,(lambda (_ entries ids
)
35 (guix-message-packages-by-id entries
'package ids
)))
37 ,(lambda (_ entries names
)
38 (guix-message-packages-by-name entries
'package names
)))
40 ,(lambda (_ entries licenses
)
41 (apply #'guix-message-packages-by-license
42 entries
'package licenses
)))
44 ,(lambda (_ entries locations
)
45 (apply #'guix-message-packages-by-location
46 entries
'package locations
)))
48 (0 "No package in file '%s'." val
)
49 (1 "Package from file '%s'." val
))
51 (0 "No packages matching '%s'." val
)
52 (1 "A single package matching '%s'." val
)
53 (many "%d packages matching '%s'." count val
))
55 (0 "No packages are available for some reason.")
56 (1 "A single available package (that's strange).")
57 (many "%d available packages." count
))
59 (0 "No packages are available for some reason.")
60 (1 "A single newest available package (that's strange).")
61 (many "%d newest available packages." count
))
63 (0 "No packages installed in profile '%s'." profile
)
64 (1 "A single package installed in profile '%s'." profile
)
65 (many "%d packages installed in profile '%s'." count profile
))
67 (0 "No obsolete packages in profile '%s'." profile
)
68 (1 "A single obsolete package in profile '%s'." profile
)
69 (many "%d obsolete packages in profile '%s'." count profile
)))
73 ,(lambda (_ entries ids
)
74 (guix-message-packages-by-id entries
'output ids
)))
76 ,(lambda (_ entries names
)
77 (guix-message-packages-by-name entries
'output names
)))
79 ,(lambda (_ entries licenses
)
80 (apply #'guix-message-packages-by-license
81 entries
'output licenses
)))
83 ,(lambda (_ entries locations
)
84 (apply #'guix-message-packages-by-location
85 entries
'output locations
)))
87 (0 "No package in file '%s'." val
)
88 (1 "Package from file '%s'." val
)
89 (many "Package outputs from file '%s'." val
))
91 (0 "No package outputs matching '%s'." val
)
92 (1 "A single package output matching '%s'." val
)
93 (many "%d package outputs matching '%s'." count val
))
95 (0 "No package outputs are available for some reason.")
96 (1 "A single available package output (that's strange).")
97 (many "%d available package outputs." count
))
99 (0 "No package outputs are available for some reason.")
100 (1 "A single newest available package output (that's strange).")
101 (many "%d newest available package outputs." count
))
103 (0 "No package outputs installed in profile '%s'." profile
)
104 (1 "A single package output installed in profile '%s'." profile
)
105 (many "%d package outputs installed in profile '%s'." count profile
))
107 (0 "No obsolete package outputs in profile '%s'." profile
)
108 (1 "A single obsolete package output in profile '%s'." profile
)
109 (many "%d obsolete package outputs in profile '%s'." count profile
))
111 guix-message-outputs-by-diff
))
115 (0 "Generations not found.")
117 (many "%d generations." count
))
119 (0 "No generations in profile '%s'." profile
)
120 (1 "The last generation of profile '%s'." profile
)
121 (many "%d last generations of profile '%s'." count profile
))
123 (0 "No generations in profile '%s'." profile
)
124 (1 "A single generation available in profile '%s'." profile
)
125 (many "%d generations available in profile '%s'." count profile
))
127 guix-message-generations-by-time
))))
129 (defun guix-message-string-name (name)
130 "Return a quoted name string."
131 (concat "'" name
"'"))
133 (defun guix-message-string-entry-type (entry-type &optional plural
)
134 "Return a string denoting an ENTRY-TYPE."
137 (if plural
"packages" "package"))
139 (if plural
"package outputs" "package output"))
141 (if plural
"generations" "generation"))))
143 (defun guix-message-string-entries (count entry-type
)
144 "Return a string denoting the COUNT of ENTRY-TYPE entries."
147 (guix-message-string-entry-type
148 entry-type
'plural
)))
149 (1 (concat "A single "
150 (guix-message-string-entry-type
154 (guix-message-string-entry-type
155 entry-type
'plural
)))))
157 (defun guix-message-packages-by-id (entries entry-type ids
)
158 "Display a message for packages or outputs searched by IDS."
159 (let* ((count (length entries
))
160 (str-beg (guix-message-string-entries count entry-type
))
161 (str-end (if (> count
1)
162 (concat "with the following IDs: "
163 (mapconcat #'guix-get-string ids
", "))
164 (concat "with ID " (guix-get-string (car ids
))))))
167 Most likely, Guix REPL was restarted, so IDs are not actual
168 anymore, because they live only during the REPL process.
169 Try \"M-x guix-search-by-name\"."
171 (message "%s %s." str-beg str-end
))))
173 (defun guix-message-packages-by-name (entries entry-type names
)
174 "Display a message for packages or outputs searched by NAMES."
175 (let* ((count (length entries
))
176 (str-beg (guix-message-string-entries count entry-type
))
177 (str-end (if (cdr names
)
178 (concat "matching the following names: "
179 (mapconcat #'guix-message-string-name
182 (guix-message-string-name (car names
))))))
183 (message "%s %s." str-beg str-end
)))
185 (defun guix-message-packages-by-license (entries entry-type license
)
186 "Display a message for packages or outputs searched by LICENSE."
187 (let* ((count (length entries
))
188 (str-beg (guix-message-string-entries count entry-type
))
189 (str-end (format "with license '%s'" license
)))
190 (message "%s %s." str-beg str-end
)))
192 (defun guix-message-packages-by-location (entries entry-type location
)
193 "Display a message for packages or outputs searched by LOCATION."
194 (let* ((count (length entries
))
195 (str-beg (guix-message-string-entries count entry-type
))
196 (str-end (format "placed in '%s'" location
)))
197 (message "%s %s." str-beg str-end
)))
199 (defun guix-message-generations-by-time (profile entries times
)
200 "Display a message for generations searched by TIMES."
201 (let* ((count (length entries
))
202 (str-beg (guix-message-string-entries count
'generation
))
203 (time-beg (guix-get-time-string (car times
)))
204 (time-end (guix-get-time-string (cadr times
))))
205 (message (concat "%s of profile '%s'\n"
206 "matching time period '%s' - '%s'.")
207 str-beg profile time-beg time-end
)))
209 (defun guix-message-outputs-by-diff (_ entries profiles
)
210 "Display a message for outputs searched by PROFILES difference."
211 (let* ((count (length entries
))
212 (str-beg (guix-message-string-entries count
'output
))
213 (profile1 (car profiles
))
214 (profile2 (cadr profiles
)))
215 (cl-multiple-value-bind (new old str-action
)
216 (if (string-lessp profile2 profile1
)
217 (list profile1 profile2
"added to")
218 (list profile2 profile1
"removed from"))
219 (message "%s %s profile '%s' comparing with profile '%s'."
220 str-beg str-action new old
))))
222 (defun guix-result-message (profile entries entry-type
223 search-type search-vals
)
224 "Display an appropriate message after displaying ENTRIES."
225 (let* ((type-spec (guix-assq-value guix-messages
226 (if (eq entry-type
'system-generation
)
230 (fun-or-count-spec (car type-spec
)))
231 (if (functionp fun-or-count-spec
)
232 (funcall fun-or-count-spec profile entries search-vals
)
233 (let* ((count (length entries
))
234 (count-key (if (> count
1) 'many count
))
235 (msg-spec (guix-assq-value type-spec count-key
))
237 (args (cdr msg-spec
)))
238 (mapc (lambda (subst)
239 (setq args
(cl-substitute (cdr subst
) (car subst
) args
)))
241 (val .
,(car search-vals
))
242 (profile .
,profile
)))
243 (apply #'message msg args
)))))
245 (provide 'guix-messages
)
247 ;;; guix-messages.el ends here