I have a list of packages that I need to install in a custom variable (in the early-init.el
) like so.
(defcustom timu-package-list
'(0x0
...
yasnippet
ytel)
"List of packages to be installed for the Emacs config to work as configured.
The packages will be installed with `timu-func-install-packages'."
:type '(repeat symbol)
:group 'timu)
The following function checks if a package is installed.
(defun timu-func-packages-installed-p ()
"Check if all packages in `timu-package-list' are installed."
(cl-every #'package-installed-p timu-package-list))
This functions installs a package if it is not installed.
(defun timu-func-require-package (package)
"Install PACKAGE unless already installed."
(unless (memq package timu-package-list)
(add-to-list 'timu-package-list package))
(unless (package-installed-p package)
(package-install package)))
Install ALL the packages in case they are not installes
(defun timu-func-require-packages (packages)
"Ensure PACKAGES are installed.
Missing packages are installed automatically."
(mapc #'timu-func-require-package packages))
This is the command I the use in my init.el
file to install the packages on demand.
This would be the "one command".
Note that this only installs missing packages. The above functions are helper functions.
(defun timu-func-install-packages ()
"Install all packages listed in `timu-package-list' unless already installed."
(interactive)
(unless (timu-func-packages-installed-p)
;; check for new packages (package versions)
(message "%s" "Reloading packages DB...")
(package-refresh-contents)
(message "%s" " done.")
;; install the missing packages
(timu-func-require-packages timu-package-list)))
I got most of the code from this repo and adjusted it for case:
https://github.com/bbatsov/prelude