1 ;;; guix-ui-package.el --- Interface for displaying packages -*- lexical-binding: t -*-
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 an interface for displaying packages and outputs
23 ;; in 'list' and 'info' buffers, and commands for working with them.
28 (require 'guix-buffer
)
33 (require 'guix-backend
)
38 (require 'guix-hydra-build
)
40 (require 'guix-license
)
41 (require 'guix-profiles
)
43 (guix-ui-define-entry-type package
)
44 (guix-ui-define-entry-type output
)
46 (defcustom guix-package-list-type
'output
47 "Define how to display packages in 'list' buffer.
48 Should be a symbol `package' or `output' (if `output', display each
49 output on a separate line; if `package', display each package on
51 :type
'(choice (const :tag
"List of packages" package
)
52 (const :tag
"List of outputs" output
))
55 (defcustom guix-package-info-type
'package
56 "Define how to display packages in 'info' buffer.
57 Should be a symbol `package' or `output' (if `output', display
58 each output separately; if `package', display outputs inside
60 :type
'(choice (const :tag
"Display packages" package
)
61 (const :tag
"Display outputs" output
))
64 (defun guix-package-get-display (profile search-type
&rest search-values
)
65 "Search for packages/outputs and show results.
67 If PROFILE is nil, use `guix-current-profile'.
69 See `guix-ui-get-entries' for the meaning of SEARCH-TYPE and
72 Results are displayed in the list buffer, unless a single package
73 is found and `guix-package-list-single' is nil."
74 (let* ((args (cl-list* (or profile guix-current-profile
)
75 search-type search-values
))
76 (entries (guix-buffer-get-entries
77 'list guix-package-list-type args
)))
78 (if (or guix-package-list-single
81 (guix-buffer-display-entries
82 entries
'list guix-package-list-type args
'add
)
83 (guix-buffer-get-display-entries
84 'info guix-package-info-type args
'add
))))
86 (defun guix-package-entry->name-specification
(entry &optional output
)
87 "Return name specification of the package ENTRY and OUTPUT."
88 (guix-package-name-specification
89 (guix-entry-value entry
'name
)
90 (guix-entry-value entry
'version
)
91 (or output
(guix-entry-value entry
'output
))))
93 (defun guix-package-entries->name-specifications
(entries)
94 "Return name specifications by the package or output ENTRIES."
95 (cl-remove-duplicates (mapcar #'guix-package-entry-
>name-specification
99 (defun guix-package-installed-outputs (entry)
100 "Return a list of installed outputs for the package ENTRY."
101 (mapcar (lambda (installed-entry)
102 (guix-entry-value installed-entry
'output
))
103 (guix-entry-value entry
'installed
)))
105 (defun guix-package-id-and-output-by-output-id (output-id)
106 "Return a list (PACKAGE-ID OUTPUT) by OUTPUT-ID."
107 (cl-multiple-value-bind (package-id-str output
)
108 (split-string output-id
":")
109 (let ((package-id (string-to-number package-id-str
)))
110 (list (if (= 0 package-id
) package-id-str package-id
)
114 ;;; Processing package actions
116 (defun guix-process-package-actions (profile actions
117 &optional operation-buffer
)
118 "Process package ACTIONS on PROFILE.
119 Each action is a list of the form:
121 (ACTION-TYPE PACKAGE-SPEC ...)
123 ACTION-TYPE is one of the following symbols: `install',
124 `upgrade', `remove'/`delete'.
125 PACKAGE-SPEC should have the following form: (ID [OUTPUT] ...)."
126 (let (install upgrade remove
)
127 (mapc (lambda (action)
128 (let ((action-type (car action
))
129 (specs (cdr action
)))
131 (install (setq install
(append install specs
)))
132 (upgrade (setq upgrade
(append upgrade specs
)))
133 ((remove delete
) (setq remove
(append remove specs
))))))
135 (when (guix-continue-package-operation-p
137 :install install
:upgrade upgrade
:remove remove
)
139 (guix-make-guile-expression
140 'process-package-actions profile
141 :install install
:upgrade upgrade
:remove remove
142 :use-substitutes?
(or guix-use-substitutes
'f
)
143 :dry-run?
(or guix-dry-run
'f
))
144 (and (not guix-dry-run
) operation-buffer
)))))
146 (cl-defun guix-continue-package-operation-p (profile
147 &key install upgrade remove
)
148 "Return non-nil if a package operation should be continued.
149 Ask a user if needed (see `guix-operation-confirm').
150 INSTALL, UPGRADE, REMOVE are 'package action specifications'.
151 See `guix-process-package-actions' for details."
152 (or (null guix-operation-confirm
)
153 (let* ((entries (guix-ui-get-entries
155 (append (mapcar #'car install
)
156 (mapcar #'car upgrade
)
157 (mapcar #'car remove
))
158 '(id name version location
)))
159 (install-strings (guix-get-package-strings install entries
))
160 (upgrade-strings (guix-get-package-strings upgrade entries
))
161 (remove-strings (guix-get-package-strings remove entries
)))
162 (if (or install-strings upgrade-strings remove-strings
)
163 (let ((buf (get-buffer-create guix-temp-buffer-name
)))
164 (with-current-buffer buf
165 (setq-local cursor-type nil
)
166 (setq buffer-read-only nil
)
168 (insert "Profile: " profile
"\n\n")
169 (guix-insert-package-strings install-strings
"install")
170 (guix-insert-package-strings upgrade-strings
"upgrade")
171 (guix-insert-package-strings remove-strings
"remove")
172 (let ((win (temp-buffer-window-show
174 '((display-buffer-reuse-window
175 display-buffer-at-bottom
)
176 (window-height . fit-window-to-buffer
)))))
177 (prog1 (guix-operation-prompt)
178 (quit-window nil win
)))))
179 (message "Nothing to be done.
180 If Guix REPL was restarted, the data is not up-to-date.")
183 (defun guix-get-package-strings (specs entries
)
184 "Return short package descriptions for performing package actions.
185 See `guix-process-package-actions' for the meaning of SPECS.
186 ENTRIES is a list of package entries to get info about packages."
190 (let* ((id (car spec
))
192 (entry (guix-entry-by-id id entries
)))
194 (let ((location (guix-entry-value entry
'location
)))
195 (concat (guix-package-entry->name-specification entry
)
198 (guix-concat-strings outputs
",")))
200 (concat "\t(" location
")")))))))
203 (defun guix-insert-package-strings (strings action
)
204 "Insert information STRINGS at point for performing package ACTION."
206 (insert "Package(s) to " (propertize action
'face
'bold
) ":\n")
208 (insert " " str
"\n"))
215 (guix-ui-info-define-interface package
216 :buffer-name
"*Guix Package Info*"
217 :format
'(guix-package-info-insert-heading
219 (synopsis ignore
(simple guix-package-info-synopsis
))
221 (description ignore
(simple guix-package-info-description
))
223 (outputs simple guix-package-info-insert-outputs
)
224 (source simple guix-package-info-insert-source
)
225 (location format
(format guix-package-location
))
226 (home-url format
(format guix-url
))
227 (license format
(format guix-package-license
))
228 (systems format guix-package-info-insert-systems
)
229 (inputs format
(format guix-package-input
))
230 (native-inputs format
(format guix-package-native-input
))
231 (propagated-inputs format
232 (format guix-package-propagated-input
)))
233 :titles
'((home-url .
"Home page")
234 (systems .
"Supported systems"))
235 :required
'(id name version installed non-unique
))
237 (guix-info-define-interface installed-output
238 :format
'((path simple
(indent guix-file
))
239 (dependencies simple
(indent guix-file
)))
240 :titles
'((path .
"Store directory"))
243 (defface guix-package-info-heading
244 '((t :inherit guix-info-heading
))
245 "Face for package name and version headings."
246 :group
'guix-package-info-faces
)
248 (defface guix-package-info-name
249 '((t :inherit font-lock-keyword-face
))
250 "Face used for a name of a package."
251 :group
'guix-package-info-faces
)
253 (defface guix-package-info-name-button
254 '((t :inherit button
))
255 "Face used for a full name that can be used to describe a package."
256 :group
'guix-package-info-faces
)
258 (defface guix-package-info-version
259 '((t :inherit font-lock-builtin-face
))
260 "Face used for a version of a package."
261 :group
'guix-package-info-faces
)
263 (defface guix-package-info-synopsis
264 '((((type tty pc
) (class color
)) :weight bold
)
265 (t :height
1.1 :weight bold
:inherit variable-pitch
))
266 "Face used for a synopsis of a package."
267 :group
'guix-package-info-faces
)
269 (defface guix-package-info-description
271 "Face used for a description of a package."
272 :group
'guix-package-info-faces
)
274 (defface guix-package-info-license
275 '((t :inherit font-lock-string-face
))
276 "Face used for a license of a package."
277 :group
'guix-package-info-faces
)
279 (defface guix-package-info-location
281 "Face used for a location of a package."
282 :group
'guix-package-info-faces
)
284 (defface guix-package-info-source
285 '((t :inherit link
:underline nil
))
286 "Face used for a source URL of a package."
287 :group
'guix-package-info-faces
)
289 (defface guix-package-info-installed-outputs
290 '((default :weight bold
)
291 (((class color
) (min-colors 88) (background light
))
292 :foreground
"ForestGreen")
293 (((class color
) (min-colors 88) (background dark
))
294 :foreground
"PaleGreen")
295 (((class color
) (min-colors 8))
298 "Face used for installed outputs of a package."
299 :group
'guix-package-info-faces
)
301 (defface guix-package-info-uninstalled-outputs
303 "Face used for uninstalled outputs of a package."
304 :group
'guix-package-info-faces
)
306 (defface guix-package-info-obsolete
307 '((t :inherit error
))
308 "Face used if a package is obsolete."
309 :group
'guix-package-info-faces
)
311 (defcustom guix-package-info-auto-find-source nil
312 "If non-nil, find a source file after pressing a \"Show\" button.
313 If nil, just display the source file path without finding."
315 :group
'guix-package-info
)
317 (defcustom guix-package-info-auto-download-source t
318 "If nil, do not automatically download a source file if it doesn't exist.
319 After pressing a \"Show\" button, a derivation of the package
320 source is calculated and a store file path is displayed. If this
321 variable is non-nil and the source file does not exist in the
322 store, it will be automatically downloaded (with a possible
323 prompt depending on `guix-operation-confirm' variable)."
325 :group
'guix-package-info
)
327 (defvar guix-package-info-download-buffer nil
328 "Buffer from which a current download operation was performed.")
330 (defvar guix-package-info-output-format
"%-10s"
331 "String used to format output names of the packages.
332 It should be a '%s'-sequence. After inserting an output name
333 formatted with this string, an action button is inserted.")
335 (defvar guix-package-info-obsolete-string
"(This package is obsolete)"
336 "String used if a package is obsolete.")
338 (define-button-type 'guix-package-location
340 'face
'guix-package-info-location
341 'help-echo
"Find location of this package"
342 'action
(lambda (btn)
343 (guix-find-location (button-label btn
))))
345 (define-button-type 'guix-package-license
347 'face
'guix-package-info-license
348 'help-echo
"Browse license URL"
349 'action
(lambda (btn)
350 (guix-browse-license-url (button-label btn
))))
352 (define-button-type 'guix-package-name
354 'face
'guix-package-info-name-button
355 'help-echo
"Describe this package"
356 'action
(lambda (btn)
357 (guix-buffer-get-display-entries-current
358 'info guix-package-info-type
359 (list (guix-ui-current-profile)
360 'name
(button-label btn
))
363 (define-button-type 'guix-package-heading
364 :supertype
'guix-package-name
365 'face
'guix-package-info-heading
)
367 (define-button-type 'guix-package-source
369 'face
'guix-package-info-source
372 ;; As a source may not be a real URL (e.g., "mirror://..."),
373 ;; no action is bound to a source button.
374 (message "Yes, this is the source URL. What did you expect?")))
376 (defun guix-package-info-insert-heading (entry)
377 "Insert package ENTRY heading (name specification) at point."
379 (guix-package-entry->name-specification entry
)
380 'guix-package-heading
))
382 (defun guix-package-info-insert-systems (systems entry
)
383 "Insert supported package SYSTEMS at point."
384 (guix-info-insert-value-format
385 systems
'guix-hydra-build-system
386 'action
(lambda (btn)
387 (let ((args (guix-hydra-build-latest-prompt-args
388 :job
(button-get btn
'job-name
)
389 :system
(button-label btn
))))
390 (apply #'guix-hydra-build-get-display
392 'job-name
(guix-hydra-job-name-specification
393 (guix-entry-value entry
'name
)
394 (guix-entry-value entry
'version
))))
396 (defmacro guix-package-info-define-insert-inputs
(&optional type
)
397 "Define a face and a function for inserting package inputs.
398 TYPE is a type of inputs.
399 Function name is `guix-package-info-insert-TYPE-inputs'.
400 Face name is `guix-package-info-TYPE-inputs'."
401 (let* ((type-str (symbol-name type
))
402 (type-name (and type
(concat type-str
"-")))
403 (type-desc (and type
(concat type-str
" ")))
404 (face (intern (concat "guix-package-info-" type-name
"inputs")))
405 (btn (intern (concat "guix-package-" type-name
"input"))))
408 '((t :inherit guix-package-info-name-button
))
409 ,(concat "Face used for " type-desc
"inputs of a package.")
410 :group
'guix-package-info-faces
)
412 (define-button-type ',btn
413 :supertype
'guix-package-name
416 (guix-package-info-define-insert-inputs)
417 (guix-package-info-define-insert-inputs native
)
418 (guix-package-info-define-insert-inputs propagated
)
420 (defun guix-package-info-insert-outputs (outputs entry
)
421 "Insert OUTPUTS from package ENTRY at point."
422 (and (guix-entry-value entry
'obsolete
)
423 (guix-package-info-insert-obsolete-text))
424 (and (guix-entry-value entry
'non-unique
)
425 (guix-entry-value entry
'installed
)
426 (guix-package-info-insert-non-unique-text
427 (guix-package-entry->name-specification entry
)))
429 (dolist (output outputs
)
430 (guix-package-info-insert-output output entry
)))
432 (defun guix-package-info-insert-obsolete-text ()
433 "Insert a message about obsolete package at point."
434 (guix-info-insert-indent)
435 (guix-format-insert guix-package-info-obsolete-string
436 'guix-package-info-obsolete
))
438 (defun guix-package-info-insert-non-unique-text (full-name)
439 "Insert a message about non-unique package with FULL-NAME at point."
441 (guix-info-insert-indent)
442 (insert "Installed outputs are displayed for a non-unique ")
443 (guix-insert-button full-name
'guix-package-name
)
444 (insert " package."))
446 (defun guix-package-info-insert-output (output entry
)
447 "Insert OUTPUT at point.
448 Make some fancy text with buttons and additional stuff if the
449 current OUTPUT is installed (if there is such output in
450 `installed' parameter of a package ENTRY)."
451 (let* ((installed (guix-entry-value entry
'installed
))
452 (obsolete (guix-entry-value entry
'obsolete
))
453 (installed-entry (cl-find-if
455 (string= (guix-entry-value entry
'output
)
458 (action-type (if installed-entry
'delete
'install
))
459 (profile (guix-ui-current-profile)))
460 (guix-info-insert-indent)
461 (guix-format-insert output
463 'guix-package-info-installed-outputs
464 'guix-package-info-uninstalled-outputs
)
465 guix-package-info-output-format
)
466 ;; Do not allow a user to install/delete anything to/from a system
467 ;; profile, so add action buttons only for non-system profiles.
469 (not (guix-system-profile? profile
)))
470 (guix-package-info-insert-action-button action-type entry output
)
472 (guix-info-insert-indent)
473 (guix-package-info-insert-action-button 'upgrade entry output
)))
475 (when installed-entry
476 (guix-info-insert-entry installed-entry
'installed-output
2))))
478 (defun guix-package-info-insert-action-button (type entry output
)
479 "Insert button to process an action on a package OUTPUT at point.
480 TYPE is one of the following symbols: `install', `delete', `upgrade'.
481 ENTRY is an alist with package info."
482 (let ((type-str (capitalize (symbol-name type
)))
483 (full-name (guix-package-entry->name-specification entry output
)))
484 (guix-info-insert-action-button
487 (guix-process-package-actions
488 (guix-ui-current-profile)
489 `((,(button-get btn
'action-type
) (,(button-get btn
'id
)
490 ,(button-get btn
'output
))))
492 (concat type-str
" '" full-name
"'")
494 'id
(or (guix-entry-value entry
'package-id
)
495 (guix-entry-id entry
))
498 (defun guix-package-info-show-source (entry-id package-id
)
499 "Show file name of a package source in the current info buffer.
500 Find the file if needed (see `guix-package-info-auto-find-source').
501 ENTRY-ID is an ID of the current entry (package or output).
502 PACKAGE-ID is an ID of the package which source to show."
503 (let* ((entries (guix-buffer-current-entries))
504 (entry (guix-entry-by-id entry-id entries
))
505 (file (guix-package-source-path package-id
)))
507 (error "Couldn't define file name of the package source"))
508 (let* ((new-entry (cons (cons 'source-file file
)
510 (new-entries (guix-replace-entry entry-id new-entry entries
)))
511 (setf (guix-buffer-item-entries guix-buffer-item
)
513 (guix-buffer-redisplay-goto-button)
514 (if (file-exists-p file
)
515 (if guix-package-info-auto-find-source
516 (guix-find-file file
)
517 (message "The source store path is displayed."))
518 (if guix-package-info-auto-download-source
519 (guix-package-info-download-source package-id
)
520 (message "The source does not exist in the store."))))))
522 (defun guix-package-info-download-source (package-id)
523 "Download a source of the package PACKAGE-ID."
524 (setq guix-package-info-download-buffer
(current-buffer))
525 (guix-package-source-build-derivation
527 "The source does not exist in the store. Download it?"))
529 (defun guix-package-info-insert-source (source entry
)
530 "Insert SOURCE from package ENTRY at point.
531 SOURCE is a list of URLs."
533 (guix-format-insert nil
)
534 (let* ((source-file (guix-entry-value entry
'source-file
))
535 (entry-id (guix-entry-id entry
))
536 (package-id (or (guix-entry-value entry
'package-id
)
538 (if (null source-file
)
539 (guix-info-insert-action-button
542 (guix-package-info-show-source (button-get btn
'entry-id
)
543 (button-get btn
'package-id
)))
544 "Show the source store directory of the current package"
546 'package-id package-id
)
547 (unless (file-exists-p source-file
)
548 (guix-info-insert-action-button
551 (guix-package-info-download-source
552 (button-get btn
'package-id
)))
553 "Download the source into the store"
554 'package-id package-id
))
555 (guix-info-insert-value-indent source-file
'guix-file
))
556 (guix-info-insert-value-indent source
'guix-package-source
))))
558 (defun guix-package-info-redisplay-after-download ()
559 "Redisplay an 'info' buffer after downloading the package source.
560 This function is used to hide a \"Download\" button if needed."
561 (when (buffer-live-p guix-package-info-download-buffer
)
562 (with-current-buffer guix-package-info-download-buffer
563 (guix-buffer-redisplay-goto-button))
564 (setq guix-package-info-download-buffer nil
)))
566 (add-hook 'guix-after-source-download-hook
567 'guix-package-info-redisplay-after-download
)
572 (guix-ui-list-define-interface package
573 :buffer-name
"*Guix Package List*"
574 :format
'((name guix-package-list-get-name
20 t
)
577 (installed guix-package-list-get-installed-outputs
13 t
)
578 (synopsis guix-list-get-one-line
30 nil
))
580 :marks
'((install . ?I
)
584 (let ((map guix-package-list-mode-map
))
585 (define-key map
(kbd "B") 'guix-package-list-latest-builds
)
586 (define-key map
(kbd "e") 'guix-package-list-edit
)
587 (define-key map
(kbd "x") 'guix-package-list-execute
)
588 (define-key map
(kbd "i") 'guix-package-list-mark-install
)
589 (define-key map
(kbd "d") 'guix-package-list-mark-delete
)
590 (define-key map
(kbd "U") 'guix-package-list-mark-upgrade
)
591 (define-key map
(kbd "^") 'guix-package-list-mark-upgrades
))
593 (defface guix-package-list-installed
594 '((t :inherit guix-package-info-installed-outputs
))
595 "Face used if there are installed outputs for the current package."
596 :group
'guix-package-list-faces
)
598 (defface guix-package-list-obsolete
599 '((t :inherit guix-package-info-obsolete
))
600 "Face used if a package is obsolete."
601 :group
'guix-package-list-faces
)
603 (defcustom guix-package-list-generation-marking-enabled nil
604 "If non-nil, allow putting marks in a list with 'generation packages'.
606 By default this is disabled, because it may be confusing. For
607 example, a package is installed in some generation, so a user can
608 mark it for deletion in the list of packages from this
609 generation, but the package may not be installed in the latest
610 generation, so actually it cannot be deleted.
612 If you managed to understand the explanation above or if you
613 really know what you do or if you just don't care, you can set
614 this variable to t. It should not do much harm anyway (most
617 :group
'guix-package-list
)
619 (defun guix-package-list-get-name (name entry
)
620 "Return NAME of the package ENTRY.
621 Colorize it with `guix-package-list-installed' or
622 `guix-package-list-obsolete' if needed."
623 (guix-get-string name
624 (cond ((guix-entry-value entry
'obsolete
)
625 'guix-package-list-obsolete
)
626 ((guix-entry-value entry
'installed
)
627 'guix-package-list-installed
))))
629 (defun guix-package-list-get-installed-outputs (installed &optional _
)
630 "Return string with outputs from INSTALLED entries."
632 (mapcar (lambda (entry)
633 (guix-entry-value entry
'output
))
636 (defun guix-package-list-marking-check ()
637 "Signal an error if marking is disabled for the current buffer."
638 (when (and (not guix-package-list-generation-marking-enabled
)
639 (or (derived-mode-p 'guix-package-list-mode
)
640 (derived-mode-p 'guix-output-list-mode
))
641 (eq (guix-ui-current-search-type) 'generation
))
642 (error "Action marks are disabled for lists of 'generation packages'")))
644 (defun guix-package-list-mark-outputs (mark default
645 &optional prompt available
)
646 "Mark the current package with MARK and move to the next line.
647 If PROMPT is non-nil, use it to ask a user for outputs from
648 AVAILABLE list, otherwise mark all DEFAULT outputs."
649 (let ((outputs (if prompt
650 (guix-completing-read-multiple
651 prompt available nil t
)
653 (apply #'guix-list--mark mark t outputs
)))
655 (defun guix-package-list-mark-install (&optional arg
)
656 "Mark the current package for installation and move to the next line.
657 With ARG, prompt for the outputs to install (several outputs may
658 be separated with \",\")."
660 (guix-package-list-marking-check)
661 (let* ((entry (guix-list-current-entry))
662 (all (guix-entry-value entry
'outputs
))
663 (installed (guix-package-installed-outputs entry
))
664 (available (cl-set-difference all installed
:test
#'string
=)))
666 (user-error "This package is already installed"))
667 (guix-package-list-mark-outputs
669 (and arg
"Output(s) to install: ")
672 (defun guix-package-list-mark-delete (&optional arg
)
673 "Mark the current package for deletion and move to the next line.
674 With ARG, prompt for the outputs to delete (several outputs may
675 be separated with \",\")."
677 (guix-package-list-marking-check)
678 (let* ((entry (guix-list-current-entry))
679 (installed (guix-package-installed-outputs entry
)))
681 (user-error "This package is not installed"))
682 (guix-package-list-mark-outputs
684 (and arg
"Output(s) to delete: ")
687 (defun guix-package-list-mark-upgrade (&optional arg
)
688 "Mark the current package for upgrading and move to the next line.
689 With ARG, prompt for the outputs to upgrade (several outputs may
690 be separated with \",\")."
692 (guix-package-list-marking-check)
693 (let* ((entry (guix-list-current-entry))
694 (installed (guix-package-installed-outputs entry
)))
696 (user-error "This package is not installed"))
697 (when (or (guix-entry-value entry
'obsolete
)
698 (y-or-n-p "This package is not obsolete. Try to upgrade it anyway? "))
699 (guix-package-list-mark-outputs
701 (and arg
"Output(s) to upgrade: ")
704 (defun guix-package-mark-upgrades (fun)
705 "Mark all obsolete packages for upgrading.
706 Use FUN to perform marking of the current line. FUN should
707 take an entry as argument."
708 (guix-package-list-marking-check)
709 (let ((obsolete (cl-remove-if-not
711 (guix-entry-value entry
'obsolete
))
712 (guix-buffer-current-entries))))
713 (guix-list-for-each-line
715 (let* ((id (guix-list-current-id))
718 (equal id
(guix-entry-id entry
)))
721 (funcall fun entry
)))))))
723 (defun guix-package-list-mark-upgrades ()
724 "Mark all obsolete packages for upgrading."
726 (guix-package-mark-upgrades
728 (apply #'guix-list--mark
730 (guix-package-installed-outputs entry
)))))
732 (defun guix-package-assert-non-system-profile ()
733 "Verify that the current profile is not a system one.
734 The current profile is the one used by the current buffer."
735 (let ((profile (guix-ui-current-profile)))
737 (guix-system-profile? profile
)
738 (user-error "Packages cannot be installed or removed to/from \
740 Use 'guix system reconfigure' shell command to modify a system profile."
743 (defun guix-package-execute-actions (fun)
744 "Perform actions on the marked packages.
745 Use FUN to define actions suitable for `guix-process-package-actions'.
746 FUN should take action-type as argument."
747 (guix-package-assert-non-system-profile)
748 (let ((actions (delq nil
749 (mapcar fun
'(install delete upgrade
)))))
751 (guix-process-package-actions (guix-ui-current-profile)
752 actions
(current-buffer))
753 (user-error "No operations specified"))))
755 (defun guix-package-list-execute ()
756 "Perform actions on the marked packages."
758 (guix-package-execute-actions #'guix-package-list-make-action
))
760 (defun guix-package-list-make-action (action-type)
761 "Return action specification for the packages marked with ACTION-TYPE.
762 Return nil, if there are no packages marked with ACTION-TYPE.
763 The specification is suitable for `guix-process-package-actions'."
764 (let ((specs (guix-list-get-marked-args action-type
)))
765 (and specs
(cons action-type specs
))))
767 (defun guix-package-list-edit (&optional directory
)
768 "Go to the location of the current package.
769 See `guix-find-location' for the meaning of DIRECTORY."
770 (interactive (list (guix-read-directory)))
771 (guix-edit (guix-list-current-id) directory
))
773 (defun guix-package-list-latest-builds (number &rest args
)
774 "Display latest NUMBER of Hydra builds of the current package.
775 Interactively, prompt for NUMBER. With prefix argument, prompt
778 (let ((entry (guix-list-current-entry)))
779 (guix-hydra-build-latest-prompt-args
780 :job
(guix-hydra-job-name-specification
781 (guix-entry-value entry
'name
)
782 (guix-entry-value entry
'version
)))))
783 (apply #'guix-hydra-latest-builds number args
))
788 (guix-ui-info-define-interface output
789 :buffer-name
"*Guix Package Info*"
790 :format
'((name format
(format guix-package-info-name
))
791 (version format guix-output-info-insert-version
)
792 (output format guix-output-info-insert-output
)
793 (synopsis simple
(indent guix-package-info-synopsis
))
794 (source simple guix-package-info-insert-source
)
795 (path simple
(indent guix-file
))
796 (dependencies simple
(indent guix-file
))
797 (location format
(format guix-package-location
))
798 (home-url format
(format guix-url
))
799 (license format
(format guix-package-license
))
800 (systems format guix-package-info-insert-systems
)
801 (inputs format
(format guix-package-input
))
802 (native-inputs format
(format guix-package-native-input
))
803 (propagated-inputs format
804 (format guix-package-propagated-input
))
805 (description simple
(indent guix-package-info-description
)))
806 :titles guix-package-info-titles
807 :required
'(id package-id installed non-unique
))
809 (defun guix-output-info-insert-version (version entry
)
810 "Insert output VERSION and obsolete text if needed at point."
811 (guix-info-insert-value-format version
812 'guix-package-info-version
)
813 (and (guix-entry-value entry
'obsolete
)
814 (guix-package-info-insert-obsolete-text)))
816 (defun guix-output-info-insert-output (output entry
)
817 "Insert OUTPUT and action buttons at point."
818 (let* ((installed (guix-entry-value entry
'installed
))
819 (obsolete (guix-entry-value entry
'obsolete
))
820 (action-type (if installed
'delete
'install
)))
821 (guix-info-insert-value-format
824 'guix-package-info-installed-outputs
825 'guix-package-info-uninstalled-outputs
))
826 (guix-info-insert-indent)
827 (guix-package-info-insert-action-button action-type entry output
)
829 (guix-info-insert-indent)
830 (guix-package-info-insert-action-button 'upgrade entry output
))))
835 (guix-ui-list-define-interface output
836 :buffer-name
"*Guix Package List*"
837 :describe-function
'guix-output-list-describe
838 :format
'((name guix-package-list-get-name
20 t
)
842 (synopsis guix-list-get-one-line
30 nil
))
843 :required
'(id package-id
)
845 :marks
'((install . ?I
)
849 (let ((map guix-output-list-mode-map
))
850 (define-key map
(kbd "B") 'guix-package-list-latest-builds
)
851 (define-key map
(kbd "e") 'guix-output-list-edit
)
852 (define-key map
(kbd "x") 'guix-output-list-execute
)
853 (define-key map
(kbd "i") 'guix-output-list-mark-install
)
854 (define-key map
(kbd "d") 'guix-output-list-mark-delete
)
855 (define-key map
(kbd "U") 'guix-output-list-mark-upgrade
)
856 (define-key map
(kbd "^") 'guix-output-list-mark-upgrades
))
858 (defun guix-output-list-mark-install ()
859 "Mark the current output for installation and move to the next line."
861 (guix-package-list-marking-check)
862 (let* ((entry (guix-list-current-entry))
863 (installed (guix-entry-value entry
'installed
)))
865 (user-error "This output is already installed")
866 (guix-list--mark 'install t
))))
868 (defun guix-output-list-mark-delete ()
869 "Mark the current output for deletion and move to the next line."
871 (guix-package-list-marking-check)
872 (let* ((entry (guix-list-current-entry))
873 (installed (guix-entry-value entry
'installed
)))
875 (guix-list--mark 'delete t
)
876 (user-error "This output is not installed"))))
878 (defun guix-output-list-mark-upgrade ()
879 "Mark the current output for upgrading and move to the next line."
881 (guix-package-list-marking-check)
882 (let* ((entry (guix-list-current-entry))
883 (installed (guix-entry-value entry
'installed
)))
885 (user-error "This output is not installed"))
886 (when (or (guix-entry-value entry
'obsolete
)
887 (y-or-n-p "This output is not obsolete. Try to upgrade it anyway? "))
888 (guix-list--mark 'upgrade t
))))
890 (defun guix-output-list-mark-upgrades ()
891 "Mark all obsolete package outputs for upgrading."
893 (guix-package-mark-upgrades
894 (lambda (_) (guix-list--mark 'upgrade
))))
896 (defun guix-output-list-execute ()
897 "Perform actions on the marked outputs."
899 (guix-package-execute-actions #'guix-output-list-make-action
))
901 (defun guix-output-list-make-action (action-type)
902 "Return action specification for the outputs marked with ACTION-TYPE.
903 Return nil, if there are no outputs marked with ACTION-TYPE.
904 The specification is suitable for `guix-process-output-actions'."
905 (let ((ids (guix-list-get-marked-id-list action-type
)))
906 (and ids
(cons action-type
907 (mapcar #'guix-package-id-and-output-by-output-id
910 (defun guix-output-list-describe (ids)
911 "Describe outputs with IDS (list of output identifiers).
912 See `guix-package-info-type'."
913 (if (eq guix-package-info-type
'output
)
914 (guix-buffer-get-display-entries
916 (cl-list* (guix-ui-current-profile) 'id ids
)
918 (let ((pids (mapcar (lambda (oid)
919 (car (guix-package-id-and-output-by-output-id
922 (guix-buffer-get-display-entries
924 (cl-list* (guix-ui-current-profile)
925 'id
(cl-remove-duplicates pids
))
928 (defun guix-output-list-edit (&optional directory
)
929 "Go to the location of the current package.
930 See `guix-find-location' for the meaning of DIRECTORY."
931 (interactive (list (guix-read-directory)))
932 (guix-edit (guix-entry-value (guix-list-current-entry)
937 ;;; Interactive commands
939 (defvar guix-package-search-params
'(name synopsis description
)
940 "Default list of package parameters for searching by regexp.")
942 (defvar guix-package-search-history nil
943 "A history of minibuffer prompts.")
946 (defun guix-packages-by-name (name &optional profile
)
947 "Display Guix packages with NAME.
948 NAME is a string with name specification. It may optionally contain
949 a version number. Examples: \"guile\", \"guile-2.0.11\".
951 If PROFILE is nil, use `guix-current-profile'.
952 Interactively with prefix, prompt for PROFILE."
954 (list (guix-read-package-name)
955 (guix-ui-read-profile)))
956 (guix-package-get-display profile
'name name
))
959 (defun guix-packages-by-license (license &optional profile
)
960 "Display Guix packages with LICENSE.
961 LICENSE is a license name string.
962 If PROFILE is nil, use `guix-current-profile'.
963 Interactively with prefix, prompt for PROFILE."
965 (list (guix-read-license-name)
966 (guix-ui-read-profile)))
967 (guix-package-get-display profile
'license license
))
970 (defun guix-search-by-regexp (regexp &optional params profile
)
971 "Search for Guix packages by REGEXP.
972 PARAMS are package parameters that should be searched.
973 If PARAMS are not specified, use `guix-package-search-params'.
975 If PROFILE is nil, use `guix-current-profile'.
976 Interactively with prefix, prompt for PROFILE."
978 (list (read-regexp "Regexp: " nil
'guix-package-search-history
)
979 nil
(guix-ui-read-profile)))
980 (guix-package-get-display profile
'regexp regexp
981 (or params guix-package-search-params
)))
984 (defun guix-search-by-name (regexp &optional profile
)
985 "Search for Guix packages matching REGEXP in a package name.
986 If PROFILE is nil, use `guix-current-profile'.
987 Interactively with prefix, prompt for PROFILE."
989 (list (read-string "Package name by regexp: "
990 nil
'guix-package-search-history
)
991 (guix-ui-read-profile)))
992 (guix-search-by-regexp regexp
'(name) profile
))
995 (defun guix-installed-packages (&optional profile
)
996 "Display information about installed Guix packages.
997 If PROFILE is nil, use `guix-current-profile'.
998 Interactively with prefix, prompt for PROFILE."
999 (interactive (list (guix-ui-read-profile)))
1000 (guix-package-get-display profile
'installed
))
1003 (defun guix-installed-user-packages ()
1004 "Display information about Guix packages installed in a user profile."
1006 (guix-installed-packages guix-user-profile
))
1009 (defun guix-installed-system-packages ()
1010 "Display information about Guix packages installed in a system profile."
1012 (guix-installed-packages
1013 (guix-packages-profile guix-system-profile nil t
)))
1016 (defun guix-obsolete-packages (&optional profile
)
1017 "Display information about obsolete Guix packages.
1018 If PROFILE is nil, use `guix-current-profile'.
1019 Interactively with prefix, prompt for PROFILE."
1020 (interactive (list (guix-ui-read-profile)))
1021 (guix-package-get-display profile
'obsolete
))
1024 (defun guix-all-available-packages (&optional profile
)
1025 "Display information about all available Guix packages.
1026 If PROFILE is nil, use `guix-current-profile'.
1027 Interactively with prefix, prompt for PROFILE."
1028 (interactive (list (guix-ui-read-profile)))
1029 (guix-package-get-display profile
'all-available
))
1032 (defun guix-newest-available-packages (&optional profile
)
1033 "Display information about the newest available Guix packages.
1034 If PROFILE is nil, use `guix-current-profile'.
1035 Interactively with prefix, prompt for PROFILE."
1036 (interactive (list (guix-ui-read-profile)))
1037 (guix-package-get-display profile
'newest-available
))
1039 (provide 'guix-ui-package
)
1041 ;;; guix-ui-package.el ends here