* Install packages picked up from a list automatically.
@ 2020-12-24 13:37 Hongyi Zhao
2020-12-25 8:31 ` Tim Landscheidt
0 siblings, 1 reply; 2+ messages in thread
From: Hongyi Zhao @ 2020-12-24 13:37 UTC (permalink / raw)
To: help-gnu-emacs
I want to let emacs install needed packages stored in a list
automatically. For this purpose, I find the following methods which
can be used in ~/.emacs.d/init.el:
1. The method represented at
<https://realpython.com/emacs-the-best-python-editor/#initialization-file>:
;; If there are no archived package contents, refresh them
(when (not package-archive-contents)
(package-refresh-contents))
;; Installs packages
;;
;; myPackages contains a list of package names
(defvar myPackages
'(better-defaults ;; Set up some better Emacs defaults
material-theme ;; Theme
)
)
;; Scans the list in myPackages
;; If the package listed is not already installed, install it
(mapc #'(lambda (package)
(unless (package-installed-p package)
(package-install package)))
myPackages)
2. The method given by Bozhidar Batsov in his prelude project, see
<https://github.com/bbatsov/prelude/blob/aaedc8537c04e4af7a53690b8bbb8522d5a35b9d/core/prelude-packages.el#L56>
for more information.
(defvar prelude-packages
;; https://github.com/magnars/s.el#installation
'(s
flycheck)
"A list of packages to ensure are installed at launch.")
(defun prelude-packages-installed-p ()
"Check if all packages in `prelude-packages' are installed."
(cl-every #'package-installed-p prelude-packages))
(defun prelude-require-package (package)
"Install PACKAGE unless already installed."
(unless (memq package prelude-packages)
(add-to-list 'prelude-packages package))
(unless (package-installed-p package)
(package-install package)))
(defun prelude-require-packages (packages)
"Ensure PACKAGES are installed.
Missing packages are installed automatically."
(mapc #'prelude-require-package packages))
(defun prelude-install-packages ()
"Install all packages listed in `prelude-packages'."
(unless (prelude-packages-installed-p)
;; check for new packages (package versions)
(message "%s" "Emacs Prelude is now refreshing its package database...")
(package-refresh-contents)
(message "%s" " done.")
;; install the missing packages
(prelude-require-packages prelude-packages)))
;; run package installation
(prelude-install-packages)
I'm a thorough beginner as for emacs lisp. Could you please give me
some hints/notes/comments on the pros can cons of the above two
mentioned methods? Thanks in advance.
Regards,
HY
--
Assoc. Prof. Hongyi Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Polytechnic University of Science and Technology engineering
NO. 552 North Gangtie Road, Xingtai, China
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Install packages picked up from a list automatically.
2020-12-24 13:37 Install packages picked up from a list automatically Hongyi Zhao
@ 2020-12-25 8:31 ` Tim Landscheidt
0 siblings, 0 replies; 2+ messages in thread
From: Tim Landscheidt @ 2020-12-25 8:31 UTC (permalink / raw)
To: Hongyi Zhao; +Cc: help-gnu-emacs
Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
> […]
> I'm a thorough beginner as for emacs lisp. Could you please give me
> some hints/notes/comments on the pros can cons of the above two
> mentioned methods? Thanks in advance.
Unwanted advice: I would not (try to) install packages as
part of your initialization. These might fail or install
incompatible versions that you did not expect. Even if they
succeed they require network connectivity and slow down
Emacs's start-up.
I would separate two phases:
1. Install Emacs, distribution-provided Emacs packages, your
.emacs and other initialization files, and (M)ELPA-pro-
vided Emacs packages, the latter either by copying them
from your own "cache" (if they do not depend on the ma-
chine's architecture) or installing them on the command
line. You can use tools like Ansible to automate this
process so that you can just point Ansible at a host and
it will do everything necessary (you could, of course,
also write such a script in Emacs Lisp :-)).
2. Use Emacs everyday with as few external dependencies as
possible. If Emacs starts up, it should do so quickly
and never have to wait for some other machine.
Tim
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-12-25 8:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-24 13:37 Install packages picked up from a list automatically Hongyi Zhao
2020-12-25 8:31 ` Tim Landscheidt
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).