unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
@ 2024-10-21 15:58 Sean Devlin
  2024-10-21 16:35 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Devlin @ 2024-10-21 15:58 UTC (permalink / raw)
  To: 73932

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

Hi folks,

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!


[-- Attachment #2: 0001-Add-noconfirm-to-package-autoremove.patch --]
[-- Type: application/octet-stream, Size: 2300 bytes --]

From 952d8facc6be876f6aa71f742491b58287b0e7a2 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.
---
 lisp/emacs-lisp/package.el | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 7cae8d68bc0..d2de264743a 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)


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
  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
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2024-10-21 16:35 UTC (permalink / raw)
  To: Sean Devlin; +Cc: 73932

> 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.

Also, would it make sense to turn NOCONFIRM on if the command is
invoked with a prefix argument?





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
  2024-10-21 16:35 ` Eli Zaretskii
@ 2024-10-21 18:04   ` Sean Devlin
  2024-10-26  7:31     ` Philip Kaludercic
  0 siblings, 1 reply; 6+ messages in thread
From: Sean Devlin @ 2024-10-21 18:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 73932

[-- 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.

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
  2024-10-21 18:04   ` Sean Devlin
@ 2024-10-26  7:31     ` Philip Kaludercic
  2024-10-27  9:53       ` Stefan Kangas
  0 siblings, 1 reply; 6+ messages in thread
From: Philip Kaludercic @ 2024-10-26  7:31 UTC (permalink / raw)
  To: Sean Devlin; +Cc: Eli Zaretskii, 73932

Sean Devlin <spd@toadstyle.org> writes:

> 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:

The change looks pretty uncontroversial to me.  Is the variation
interesting, where NOCONFIRM is a predicate so that we can selectively
remove packages?

> 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.

We can do that in a subsequent patch.

-- 
	Philip Kaludercic on siskin





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
  2024-10-26  7:31     ` Philip Kaludercic
@ 2024-10-27  9:53       ` Stefan Kangas
  2024-10-28 14:48         ` Sean Devlin
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Kangas @ 2024-10-27  9:53 UTC (permalink / raw)
  To: Philip Kaludercic, Sean Devlin; +Cc: Eli Zaretskii, 73932

Philip Kaludercic <philipk@posteo.net> writes:

> The change looks pretty uncontroversial to me.

Agreed.

> Is the variation interesting, where NOCONFIRM is a predicate so that
> we can selectively remove packages?

Do you have a use case in mind?

>> 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.
>
> We can do that in a subsequent patch.

Feel free to post such a patch, indeed.  Thanks in advance.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* bug#73932: [PATCH] Add noconfirm to 'package-autoremove'
  2024-10-27  9:53       ` Stefan Kangas
@ 2024-10-28 14:48         ` Sean Devlin
  0 siblings, 0 replies; 6+ messages in thread
From: Sean Devlin @ 2024-10-28 14:48 UTC (permalink / raw)
  To: Stefan Kangas, Philip Kaludercic; +Cc: Eli Zaretskii, 73932

[-- Attachment #1: Type: text/plain, Size: 606 bytes --]

Hi folks,

> On Oct 27, 2024, at 5:53 AM, Stefan Kangas <stefankangas@gmail.com> wrote:
> 
> Philip Kaludercic <philipk@posteo.net> writes:
> 
>> Is the variation interesting, where NOCONFIRM is a predicate so that
>> we can selectively remove packages?
> 
> Do you have a use case in mind?
> 
>>> 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.
>> 
>> We can do that in a subsequent patch.
> 
> Feel free to post such a patch, indeed.  Thanks in advance.

Here’s two patches:


[-- Attachment #2: 0001-Add-noconfirm-to-package-autoremove.patch --]
[-- Type: application/octet-stream, Size: 3114 bytes --]

From 5ad7a54aae80704fe2827b8e2b924b30adabcf2c Mon Sep 17 00:00:00 2001
From: Sean Devlin <spd@toadstyle.org>
Date: Mon, 21 Oct 2024 11:28:06 -0400
Subject: [PATCH 1/2] 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                   |  9 +++++++++
 lisp/emacs-lisp/package.el | 21 +++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index cfc5a8e1785..aad81d56ed4 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -587,6 +587,15 @@ 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, 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
 
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 90d6150ed0b..b3e561f762e 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.5 (Apple Git-154)


[-- Attachment #3: 0002-Use-prefix-argument-in-package-install-selected-pack.patch --]
[-- Type: application/octet-stream, Size: 2017 bytes --]

From 8fcc764ab0ae260f751f25013f400a4368b05d07 Mon Sep 17 00:00:00 2001
From: Sean Devlin <spd@toadstyle.org>
Date: Mon, 28 Oct 2024 10:34:48 -0400
Subject: [PATCH 2/2] Use prefix argument in
 'package-install-selected-packages'

* lisp/emacs-lisp/package.el (package-install-selected-packages):
When invoked with a prefix argument, skip user confirmation when
installing packages.
* etc/NEWS: Announce the prefix argument usage.
---
 etc/NEWS                   | 5 +++++
 lisp/emacs-lisp/package.el | 7 ++++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index aad81d56ed4..32f0233ce09 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -596,6 +596,11 @@ 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 prefix argument for 'package-install-selected-packages'.
+When invoked with a prefix argument, 'package-install-selected-packages'
+will not prompt the user for confirmation before installing 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 b3e561f762e..16e53871780 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2438,9 +2438,10 @@ directory."
 (defun package-install-selected-packages (&optional noconfirm)
   "Ensure packages in `package-selected-packages' are installed.
 If some packages are not installed, propose to install them.
-If optional argument NOCONFIRM is non-nil, don't ask for
-confirmation to install packages."
-  (interactive)
+
+If optional argument NOCONFIRM is non-nil, or when invoked with a prefix
+argument, don't ask for confirmation to install packages."
+  (interactive "P")
   (package--archives-initialize)
   ;; We don't need to populate `package-selected-packages' before
   ;; using here, because the outcome is the same either way (nothing
-- 
2.39.5 (Apple Git-154)


[-- Attachment #4: Type: text/plain, Size: 411 bytes --]



The first is the same as before, but it adds the prefix argument usage Eli suggested.

The second patch adds a matching prefix argument to package-install-selected-packages (if this is desired).

I didn’t implement a predicate option for NOCONFIRM yet, since I couldn’t think of a use case, and the intended semantics are not quite clear to me.

Please let me know what else is needed, and thanks!

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-10-28 14:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2024-10-26  7:31     ` Philip Kaludercic
2024-10-27  9:53       ` Stefan Kangas
2024-10-28 14:48         ` Sean Devlin

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).