1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-22 21:50:45 -08:00

Add noconfirm to 'package-autoremove'

* lisp/emacs-lisp/package.el (package-autoremove):
Add optional argument NOCONFIRM to skip user confirmation when removing
packages.
* etc/NEWS: Announce the new argument.  (Bug#73932)
This commit is contained in:
Sean Devlin 2024-10-21 11:28:06 -04:00 committed by Philip Kaludercic
parent 7cb77385d3
commit b4e2d9a3af
No known key found for this signature in database
2 changed files with 22 additions and 8 deletions

View file

@ -2616,26 +2616,31 @@ are invalid due to changed byte-code, macros or the like."
(package-recompile pkg-desc))))
;;;###autoload
(defun package-autoremove ()
(defun package-autoremove (&optional noconfirm)
"Remove packages that are no longer needed.
Packages that are no more needed by other packages in
`package-selected-packages' and their dependencies
will be deleted."
(interactive)
will be deleted.
If optional argument NOCONFIRM is non-nil, or when invoked with a prefix
argument, don't ask for confirmation to install packages."
(interactive "P")
;; If `package-selected-packages' is nil, it would make no sense to
;; try to populate it here, because then `package-autoremove' will
;; do absolutely nothing.
(when (or package-selected-packages
(when (or noconfirm
package-selected-packages
(yes-or-no-p
(format-message
"`package-selected-packages' is empty! Really remove ALL packages? ")))
(let ((removable (package--removable-packages)))
(if removable
(when (y-or-n-p
(format "Packages to delete: %d (%s), proceed? "
(length removable)
(mapconcat #'symbol-name removable " ")))
(when (or noconfirm
(y-or-n-p
(format "Packages to delete: %d (%s), proceed? "
(length removable)
(mapconcat #'symbol-name removable " "))))
(mapc (lambda (p)
(package-delete (cadr (assq p package-alist)) t))
removable))