From 65c7dfda357469352bab7fb3a73e65927ac6eebd Mon Sep 17 00:00:00 2001 From: Sean Devlin Date: Mon, 21 Oct 2024 11:28:06 -0400 Subject: [PATCH] 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) (cherry picked from commit b4e2d9a3af3dbd0ac7fa944e9386f667feb1c124) --- etc/NEWS | 9 +++++++++ lisp/emacs-lisp/package.el | 21 +++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/etc/NEWS b/etc/NEWS index 19cbc360332..dc88b5f8617 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -635,6 +635,15 @@ cloning, or prompts for that, too. When the argument is non-nil, the function switches to a buffer visiting the directory into which the repository was cloned. +** Package + +--- +*** New optional argument to 'package-autoremove'. +An optional argument NOCONFIRM has been added to 'package-autoremove'. +If it is non-nil, or when invoked with a prefix argument, +'package-autoremove' will not prompt the user for confirmation before +removing packages. + * New Modes and Packages in Emacs 31.1 diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index bb334b94cbb..95db55bb9f7 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -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)) -- 2.39.2