]> git.eshelyaron.com Git - emacs.git/commitdiff
Add noconfirm to 'package-autoremove'
authorSean Devlin <spd@toadstyle.org>
Mon, 21 Oct 2024 15:28:06 +0000 (11:28 -0400)
committerEshel Yaron <me@eshelyaron.com>
Wed, 27 Nov 2024 19:50:41 +0000 (20:50 +0100)
* 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
lisp/emacs-lisp/package.el

index 19cbc360332abe8ce74cf903795ec8e780cd2e8a..dc88b5f86174026e0143bb41129b4241ec85e81b 100644 (file)
--- 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.
+
 \f
 * New Modes and Packages in Emacs 31.1
 
index bb334b94cbb2bd28df7a2d6a9ddd689423a8a193..95db55bb9f758c17d7506d16102c97ed6b44d87d 100644 (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))