unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Let `package-install-selected-packages' install packages without asking for confirmation.
@ 2021-07-16 14:01 Hongyi Zhao
  2021-07-16 14:22 ` Arthur Miller
  0 siblings, 1 reply; 4+ messages in thread
From: Hongyi Zhao @ 2021-07-16 14:01 UTC (permalink / raw)
  To: help-gnu-emacs

I use the following init file:

```
;https://emacs.stackexchange.com/questions/34180/how-can-i-script-emacs-to-install-packages-from-list
;https://stackoverflow.com/questions/10092322/how-to-automatically-install-emacs-packages-by-specifying-a-list-of-package-name
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

(setq package-selected-packages
      '(company
        async))
(package-install-selected-packages)


(unless package-archive-contents
  (package-refresh-contents))
(package-install-selected-packages t)
```

But when I start Emacs, it still asks me to confirm the installation
of the packages. See the following info shown in minibuffer:

Packages to install: 2 (company async), proceed? (y or n)

As you can see, I've set the `(package-install-selected-packages t)'
option. So, how to let `package-install-selected-packages' install
packages without asking for confirmation.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



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

* Re: Let `package-install-selected-packages' install packages without asking for confirmation.
  2021-07-16 14:01 Let `package-install-selected-packages' install packages without asking for confirmation Hongyi Zhao
@ 2021-07-16 14:22 ` Arthur Miller
  2021-07-16 14:41   ` Hongyi Zhao
  2021-07-26  0:08   ` Rudolf Adamkovič
  0 siblings, 2 replies; 4+ messages in thread
From: Arthur Miller @ 2021-07-16 14:22 UTC (permalink / raw)
  To: Hongyi Zhao; +Cc: help-gnu-emacs

Hongyi Zhao <hongyi.zhao@gmail.com> writes:

> I use the following init file:
>
> ```
> ;https://emacs.stackexchange.com/questions/34180/how-can-i-script-emacs-to-install-packages-from-list
> ;https://stackoverflow.com/questions/10092322/how-to-automatically-install-emacs-packages-by-specifying-a-list-of-package-name
> (require 'package)
> (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
> (package-initialize)
>
> (setq package-selected-packages
>       '(company
>         async))
> (package-install-selected-packages)
>
>
> (unless package-archive-contents
>   (package-refresh-contents))
> (package-install-selected-packages t)
> ```
>
> But when I start Emacs, it still asks me to confirm the installation
> of the packages. See the following info shown in minibuffer:
>
> Packages to install: 2 (company async), proceed? (y or n)
>
> As you can see, I've set the `(package-install-selected-packages t)'
> option.

As I see, docs says that variable holds already installed packages, not
the packages you would like to install:

Documentation
Store here packages installed explicitly by user.

I am not sure either how is it ment to be used on another machine, with
noconfirm flag, anyway, you just use dolist and install your packages in
a loop:

(dolist (p '(company async))
  (unless (package-installed-p p)
    (package-install p)))

If you really have to save packages in a named list:

(setq packages-to-install '(company asynb))

(dolist (p packages-to-install)
  (unless (package-installed-p p)
    (package-install p)))

Hope it works for you.



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

* Re: Let `package-install-selected-packages' install packages without asking for confirmation.
  2021-07-16 14:22 ` Arthur Miller
@ 2021-07-16 14:41   ` Hongyi Zhao
  2021-07-26  0:08   ` Rudolf Adamkovič
  1 sibling, 0 replies; 4+ messages in thread
From: Hongyi Zhao @ 2021-07-16 14:41 UTC (permalink / raw)
  To: Arthur Miller; +Cc: help-gnu-emacs

On Fri, Jul 16, 2021 at 10:22 PM Arthur Miller <arthur.miller@live.com> wrote:
>
> Hongyi Zhao <hongyi.zhao@gmail.com> writes:
>
> > I use the following init file:
> >
> > ```
> > ;https://emacs.stackexchange.com/questions/34180/how-can-i-script-emacs-to-install-packages-from-list
> > ;https://stackoverflow.com/questions/10092322/how-to-automatically-install-emacs-packages-by-specifying-a-list-of-package-name
> > (require 'package)
> > (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
> > (package-initialize)
> >
> > (setq package-selected-packages
> >       '(company
> >         async))
> > (package-install-selected-packages)

The above line is redundant. If I delete it, all will work just as I want.

> >
> >
> > (unless package-archive-contents
> >   (package-refresh-contents))
> > (package-install-selected-packages t)
> > ```
> >
> > But when I start Emacs, it still asks me to confirm the installation
> > of the packages. See the following info shown in minibuffer:
> >
> > Packages to install: 2 (company async), proceed? (y or n)
> >
> > As you can see, I've set the `(package-install-selected-packages t)'
> > option.
>
> As I see, docs says that variable holds already installed packages, not
> the packages you would like to install:
>
> Documentation
> Store here packages installed explicitly by user.
>
> I am not sure either how is it ment to be used on another machine, with
> noconfirm flag, anyway, you just use dolist and install your packages in
> a loop:
>
> (dolist (p '(company async))
>   (unless (package-installed-p p)
>     (package-install p)))
>
> If you really have to save packages in a named list:
>
> (setq packages-to-install '(company asynb))
>
> (dolist (p packages-to-install)
>   (unless (package-installed-p p)
>     (package-install p)))
>
> Hope it works for you.

Thank you very much for your suggestions. But as I've told, the method
posted here really works perfectly after my later revision, as
mentioned above.

Regards
-- 
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



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

* Re: Let `package-install-selected-packages' install packages without asking for confirmation.
  2021-07-16 14:22 ` Arthur Miller
  2021-07-16 14:41   ` Hongyi Zhao
@ 2021-07-26  0:08   ` Rudolf Adamkovič
  1 sibling, 0 replies; 4+ messages in thread
From: Rudolf Adamkovič @ 2021-07-26  0:08 UTC (permalink / raw)
  To: Arthur Miller, Hongyi Zhao; +Cc: help-gnu-emacs

On a related note, I use “(package-install 'X)” in my Emacs 
configuration files which spits out “‘X’ is already installed” for 
every package on launch. It is no big deal, but it would be great 
if Emacs included “package-install-if-needed” or perhaps some 
argument on “package-install” to stay quiet if no work is 
necessary. Clearly, “(unless (package-installed-p X) 
(package-install X))” is a common pattern.

R+

Arthur Miller <arthur.miller@live.com> writes:

> [snip]
>
> (dolist (p packages-to-install) 
>   (unless (package-installed-p p) 
>     (package-install p))) 

-- 
"Contrariwise," continued Tweedledee, "if it was so, it might be; 
and if it were so, it would be; but as it isn't, it ain't. That's 
logic." -- Lewis Carroll, Through the Looking Glass  Rudolf 
Adamkovič <salutis@me.com> Studenohorská 25 84103 Bratislava 
Slovakia  [he/him]



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

end of thread, other threads:[~2021-07-26  0:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-16 14:01 Let `package-install-selected-packages' install packages without asking for confirmation Hongyi Zhao
2021-07-16 14:22 ` Arthur Miller
2021-07-16 14:41   ` Hongyi Zhao
2021-07-26  0:08   ` Rudolf Adamkovič

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