New command 'package-update-all'

* lisp/emacs-lisp/package.el (package-update-all): New function
(bug#19146).
(package--updateable-packages): Factored out...
(package-update): ... from here.
This commit is contained in:
Lars Ingebrigtsen 2022-05-12 03:59:16 +02:00
parent 2dc996a95d
commit 42001f843b
3 changed files with 45 additions and 21 deletions

View file

@ -329,12 +329,14 @@ version of the package, a newer version is also installed.
@findex package-install @findex package-install
@findex package-update @findex package-update
@findex package-update-all
Packages are most conveniently installed using the package menu Packages are most conveniently installed using the package menu
(@pxref{Package Menu}), but you can also use the command @kbd{M-x (@pxref{Package Menu}), but you can also use the command @kbd{M-x
package-install}. This prompts for the name of a package with the package-install}. This prompts for the name of a package with the
@samp{available} status, then downloads and installs it. Similarly, @samp{available} status, then downloads and installs it. Similarly,
if you want to update a package, you can use the @kbd{M-x if you want to update a package, you can use the @kbd{M-x
package-update} command. package-update} command, and if you just want to update all the
packages, you can use the @kbd{M-x package-update-all} command.
@cindex package requirements @cindex package requirements
A package may @dfn{require} certain other packages to be installed, A package may @dfn{require} certain other packages to be installed,

View file

@ -829,6 +829,10 @@ this includes "binary" buffers like 'archive-mode' and 'image-mode'.
** Package ** Package
+++
*** New command 'package-update-all'.
This command allows updating all packages without any queries.
+++ +++
*** New command 'package-update'. *** New command 'package-update'.
This command allows you to upgrade packages without using 'M-x This command allows you to upgrade packages without using 'M-x

View file

@ -2140,26 +2140,44 @@ to install it but still mark it as selected."
(defun package-update (name) (defun package-update (name)
"Update package NAME if a newer version exists." "Update package NAME if a newer version exists."
(interactive (interactive
(progn (list (completing-read
;; Initialize the package system to get the list of package "Update package: " (package--updateable-packages) nil t)))
;; symbols for completion. (let ((package (if (symbolp name)
(package--archives-initialize) name
(list (completing-read (intern name))))
"Update package: " (package-delete (cadr (assq package package-alist)) 'force)
(mapcar (package-install package 'dont-select)))
#'car
(seq-filter (defun package--updateable-packages ()
(lambda (elt) ;; Initialize the package system to get the list of package
(let ((available ;; symbols for completion.
(assq (car elt) package-archive-contents))) (package--archives-initialize)
(and available (mapcar
(version-list-< #'car
(package-desc-priority-version (cadr elt)) (seq-filter
(package-desc-priority-version (cadr available)))))) (lambda (elt)
package-alist)) (let ((available
nil t)))) (assq (car elt) package-archive-contents)))
(package-delete (cadr (assq (intern name) package-alist)) 'force) (and available
(package-install (intern name) 'dont-select)) (version-list-<
(package-desc-priority-version (cadr elt))
(package-desc-priority-version (cadr available))))))
package-alist)))
(defun package-update-all (&optional inhibit-queries)
"Upgrade all packages."
(interactive "P")
(let ((updateable (package--updateable-packages)))
(if (not updateable)
(message "No packages to update")
(when (and (not inhibit-queries)
(not (yes-or-no-p
(if (length= updateable 1)
"One package to update. Do it? "
(format "%s packages to update. Do it?"
(length updateable))))))
(user-error "Updating aborted"))
(mapc #'package-update updateable))))
(defun package-strip-rcs-id (str) (defun package-strip-rcs-id (str)
"Strip RCS version ID from the version string STR. "Strip RCS version ID from the version string STR.