Factor out a new function `ensure-package-selection'

* Ensure installation of ob-company
* Ensure selection of ob-fennel
This commit is contained in:
Gerard Vermeulen 2022-10-04 06:44:06 +02:00
parent 03a07a16fd
commit 13d76a8534

View File

@ -321,15 +321,19 @@ the contents of packages and allows to update packages to the latest version.
;; Install the selected packages.
(package-install-selected-packages)))
(defun ensure-package-selection (package)
"Ensure selection of PACKAGE."
(when (and (package-installed-p package)
(bound-and-true-p package-selected-packages))
(cl-pushnew package package-selected-packages)))
(defun ensure-package-installation (&rest packages)
"Ensure installation of all packages in PACKAGES."
(let ((ok t))
(dolist (package packages)
(unless (package-installed-p package)
(package-install package))
(if (package-installed-p package)
(when (bound-and-true-p package-selected-packages)
(cl-pushnew package package-selected-packages))
(unless (ensure-package-selection package)
(setq ok nil)))
ok))
#+end_src
@ -3772,7 +3776,8 @@ support.
(when (and (executable-find "fennel")
(ensure-package-installation 'fennel-mode 'quelpa))
(unless (package-installed-p 'ob-fennel)
(quelpa '(ob-fennel :repo "andreyorst/ob-fennel" :fetcher gitlab))))
(quelpa '(ob-fennel :repo "andreyorst/ob-fennel" :fetcher gitlab)))
(ensure-package-selection 'ob-fennel))
#+end_src
#+caption[Fennel example]:
@ -3792,7 +3797,7 @@ support.
#+name: lst:install-lua-mode
#+begin_src emacs-lisp
(when (and (executable-find "lua")
(ensure-package-installation 'lua-mode)))
(ensure-package-installation 'company-lua 'lua-mode)))
#+end_src
#+caption[Lua example]: