From: Sean Devlin <spd@toadstyle.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 73932@debbugs.gnu.org
Subject: bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
Date: Mon, 21 Oct 2024 14:04:14 -0400 [thread overview]
Message-ID: <487C14D0-1114-49BC-996E-E3C74D17950F@toadstyle.org> (raw)
In-Reply-To: <864j55h0rl.fsf@gnu.org>
[-- Attachment #1: Type: text/plain, Size: 1309 bytes --]
Hello,
> On Oct 21, 2024, at 12:35 PM, Eli Zaretskii <eliz@gnu.org> wrote:
>
>> From: Sean Devlin <spd@toadstyle.org>
>> Date: Mon, 21 Oct 2024 11:58:34 -0400
>>
>> Attached is a patch adding an optional NOCONFIRM argument to package-autoremove to skip user confirmation before removing packages.
>>
>> I want to call package-autoremove in my init file to ensure there are no packages installed except those I configured explicitly via package-selected-packages.
>>
>> For example, in one session I might install package XYZ interactively via the package menu to try it out. If I decide I like it, I’ll add it to package-selected-packages in my init file to keep it around. Otherwise, I want to make sure it gets blown away the next time I start Emacs.
>>
>> This workflow is cumbersome in the current implementation of package-autoremove, which prompts the user before removing any packages. This patch adds an optional NOCONFIRM argument similar to what is implemented in package-install-selected-packages.
>>
>> Please let me know if any changes are needed.
>
> Thanks. I'll let our package.el experts review and comment, but if
> this is accepted, please add a NEWS entry for the new optional
> behavior.
Sounds good. Here is a patch with an attempt at a NEWS entry:
[-- Attachment #2: 0001-Add-noconfirm-to-package-autoremove.patch --]
[-- Type: application/octet-stream, Size: 3003 bytes --]
From a7574170716feb153016685a99f2537a27979627 Mon Sep 17 00:00:00 2001
From: Sean Devlin <spd@toadstyle.org>
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.
---
etc/NEWS | 8 ++++++++
lisp/emacs-lisp/package.el | 19 ++++++++++++-------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index cfc5a8e1785..a709a9ee6db 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -587,6 +587,14 @@ When non-nil, MPC will crossfade between songs for the specified number
of seconds. Crossfading can be toggled using the command
'mpc-toggle-crossfade' or from the MPC menu.
+** Package
+
+---
+*** New optional argument to 'package-autoremove'.
+An optional argument NOCONFIRM has been added to 'package-autoremove'.
+If it is non-nil, 'package-autoremove' will not prompt the user for
+confirmation before removing packages.
+
\f
* New Modes and Packages in Emacs 31.1
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 90d6150ed0b..6c23dcd68ff 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."
+will be deleted.
+
+If optional argument NOCONFIRM is non-nil, don't ask for
+confirmation to install packages."
(interactive)
;; 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.5 (Apple Git-154)
[-- Attachment #3: Type: text/plain, Size: 314 bytes --]
Please let me know if any changes are needed.
>
> Also, would it make sense to turn NOCONFIRM on if the command is
> invoked with a prefix argument?
Sure, that might make sense. If we do that, should we do the same in package-install-selected-packages? It uses its NOCONFIRM argument in a similar way.
next prev parent reply other threads:[~2024-10-21 18:04 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-21 15:58 bug#73932: [PATCH] Add noconfirm to 'package-autoremove' Sean Devlin
2024-10-21 16:35 ` Eli Zaretskii
2024-10-21 18:04 ` Sean Devlin [this message]
2024-10-26 7:31 ` Philip Kaludercic
2024-10-27 9:53 ` Stefan Kangas
2024-10-28 14:48 ` Sean Devlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=487C14D0-1114-49BC-996E-E3C74D17950F@toadstyle.org \
--to=spd@toadstyle.org \
--cc=73932@debbugs.gnu.org \
--cc=eliz@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.