unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#47124: 28.0.50; [PATCH] Init archive and add noconfirm to 'package-install-selected-packages'
@ 2021-03-13 17:15 Gabriel
  2021-03-13 19:01 ` Stefan Kangas
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel @ 2021-03-13 17:15 UTC (permalink / raw)
  To: 47124

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

This patch adds the following to 'package-install-selected-packages':
- a call to 'package--archives-initialize', to initialize the archive
contents, similar to how 'package-install' works;
- a new optional argument NOCONFIRM, to don't ask for confirmation when
installing new packages.

Thread on emacs-devel:
https://lists.gnu.org/archive/html/emacs-devel/2021-03/msg00662.html


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Init-archive-and-add-noconfirm-to-package-install-se.patch --]
[-- Type: text/x-diff, Size: 2510 bytes --]

From 9cc5189d1837a7cc403849e81a27b82f9c2e1160 Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <gabriel.nascimento@nubank.com.br>
Date: Sat, 13 Mar 2021 14:08:48 -0300
Subject: [PATCH] Init archive and add noconfirm to
 'package-install-selected-packages'

* lisp/emacs-lisp/package.el (package-install-selected-packages):
Add call to 'package--archives-initialize' and add optional argument
NOCONFIRM to skip user confirmation when installing packages.
---
 lisp/emacs-lisp/package.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 0973963af2..a78d05c80b 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2206,13 +2206,16 @@ package-install-file
     (package-install-from-buffer)))
 
 ;;;###autoload
-(defun package-install-selected-packages ()
+(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 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)
   ;; We don't need to populate `package-selected-packages' before
   ;; using here, because the outcome is the same either way (nothing
   ;; gets installed).
+  (package--archives-initialize)
   (if (not package-selected-packages)
       (message "`package-selected-packages' is empty, nothing to install")
     (let* ((not-installed (seq-remove #'package-installed-p package-selected-packages))
@@ -2220,10 +2223,11 @@ package-install-selected-packages
            (difference (- (length not-installed) (length available))))
       (cond
        (available
-        (when (y-or-n-p
-               (format "Packages to install: %d (%s), proceed? "
-                       (length available)
-                       (mapconcat #'symbol-name available " ")))
+        (when (or noconfirm
+                  (y-or-n-p
+                   (format "Packages to install: %d (%s), proceed? "
+                           (length available)
+                           (mapconcat #'symbol-name available " "))))
           (mapc (lambda (p) (package-install p 'dont-select)) available)))
        ((> difference 0)
         (message "Packages that are not available: %d (the rest is already installed), maybe you need to `M-x package-refresh-contents'"
-- 
2.27.0


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

* bug#47124: 28.0.50; [PATCH] Init archive and add noconfirm to 'package-install-selected-packages'
  2021-03-13 17:15 bug#47124: 28.0.50; [PATCH] Init archive and add noconfirm to 'package-install-selected-packages' Gabriel
@ 2021-03-13 19:01 ` Stefan Kangas
  2021-03-13 19:16   ` Gabriel
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Kangas @ 2021-03-13 19:01 UTC (permalink / raw)
  To: Gabriel; +Cc: 47124

Gabriel <gabriel376@hotmail.com> writes:

> This patch adds the following to 'package-install-selected-packages':
> - a call to 'package--archives-initialize', to initialize the archive
> contents, similar to how 'package-install' works;
> - a new optional argument NOCONFIRM, to don't ask for confirmation when
> installing new packages.

LGTM, with one minor nit:

>  ;;;###autoload
> -(defun package-install-selected-packages ()
> +(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 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)
>    ;; We don't need to populate `package-selected-packages' before
>    ;; using here, because the outcome is the same either way (nothing
>    ;; gets installed).
> +  (package--archives-initialize)

I would put this new line above the comment, as the comment relates to
this next line:

>    (if (not package-selected-packages)
>        (message "`package-selected-packages' is empty, nothing to install")
>      (let* ((not-installed (seq-remove #'package-installed-p package-selected-packages))
> @@ -2220,10 +2223,11 @@ package-install-selected-packages
>             (difference (- (length not-installed) (length available))))
>        (cond
>         (available
> -        (when (y-or-n-p
> -               (format "Packages to install: %d (%s), proceed? "
> -                       (length available)
> -                       (mapconcat #'symbol-name available " ")))
> +        (when (or noconfirm
> +                  (y-or-n-p
> +                   (format "Packages to install: %d (%s), proceed? "
> +                           (length available)
> +                           (mapconcat #'symbol-name available " "))))
>            (mapc (lambda (p) (package-install p 'dont-select)) available)))
>         ((> difference 0)
>          (message "Packages that are not available: %d (the rest is already installed), maybe you need to `M-x package-refresh-contents'"





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

* bug#47124: 28.0.50; [PATCH] Init archive and add noconfirm to 'package-install-selected-packages'
  2021-03-13 19:01 ` Stefan Kangas
@ 2021-03-13 19:16   ` Gabriel
  2021-03-15  2:29     ` Stefan Kangas
  0 siblings, 1 reply; 4+ messages in thread
From: Gabriel @ 2021-03-13 19:16 UTC (permalink / raw)
  To: 47124

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

>>  ;;;###autoload
>> -(defun package-install-selected-packages ()
>> +(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 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)
>>    ;; We don't need to populate `package-selected-packages' before
>>    ;; using here, because the outcome is the same either way (nothing
>>    ;; gets installed).
>> +  (package--archives-initialize)
>
> I would put this new line above the comment, as the comment relates to
> this next line:

Hi Stefan, good catch! Thank you for the suggestion. Here is an updated
patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Init-archive-and-add-noconfirm-to-package-install-se.patch --]
[-- Type: text/x-diff, Size: 2306 bytes --]

From 61f6bcdc3534c0d3a47d7f5e04e1f7c952539b6b Mon Sep 17 00:00:00 2001
From: Gabriel do Nascimento Ribeiro <gabriel.nascimento@nubank.com.br>
Date: Sat, 13 Mar 2021 16:12:47 -0300
Subject: [PATCH] Init archive and add noconfirm to
 'package-install-selected-packages'

* lisp/emacs-lisp/package.el (package-install-selected-packages):
Add call to 'package--archives-initialize' and add optional argument
NOCONFIRM to skip user confirmation when installing packages.
---
 lisp/emacs-lisp/package.el | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 0973963af2..2ecd92cee9 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2206,10 +2206,13 @@ package-install-file
     (package-install-from-buffer)))
 
 ;;;###autoload
-(defun package-install-selected-packages ()
+(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 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)
+  (package--archives-initialize)
   ;; We don't need to populate `package-selected-packages' before
   ;; using here, because the outcome is the same either way (nothing
   ;; gets installed).
@@ -2220,10 +2223,11 @@ package-install-selected-packages
            (difference (- (length not-installed) (length available))))
       (cond
        (available
-        (when (y-or-n-p
-               (format "Packages to install: %d (%s), proceed? "
-                       (length available)
-                       (mapconcat #'symbol-name available " ")))
+        (when (or noconfirm
+                  (y-or-n-p
+                   (format "Packages to install: %d (%s), proceed? "
+                           (length available)
+                           (mapconcat #'symbol-name available " "))))
           (mapc (lambda (p) (package-install p 'dont-select)) available)))
        ((> difference 0)
         (message "Packages that are not available: %d (the rest is already installed), maybe you need to `M-x package-refresh-contents'"
-- 
2.27.0


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

* bug#47124: 28.0.50; [PATCH] Init archive and add noconfirm to 'package-install-selected-packages'
  2021-03-13 19:16   ` Gabriel
@ 2021-03-15  2:29     ` Stefan Kangas
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Kangas @ 2021-03-15  2:29 UTC (permalink / raw)
  To: Gabriel; +Cc: 47124

tags 47124 fixed
close 47124 28.1
thanks

Gabriel <gabriel376@hotmail.com> writes:

> Hi Stefan, good catch! Thank you for the suggestion. Here is an updated
> patch.

Thanks!  Pushed to master as commit 2d12df3926.





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

end of thread, other threads:[~2021-03-15  2:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-13 17:15 bug#47124: 28.0.50; [PATCH] Init archive and add noconfirm to 'package-install-selected-packages' Gabriel
2021-03-13 19:01 ` Stefan Kangas
2021-03-13 19:16   ` Gabriel
2021-03-15  2:29     ` Stefan Kangas

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