2018-06-11 23:18:15 +02:00
|
|
|
;;; core/core-packages.el -*- lexical-binding: t; -*-
|
2017-02-19 06:59:55 -05:00
|
|
|
|
2018-05-24 21:17:23 +02:00
|
|
|
;; Emacs package management is opinionated, and so am I. I've bound together
|
|
|
|
;; `use-package', `quelpa' and package.el to create my own, rolling-release,
|
|
|
|
;; lazily-loaded package management system for Emacs.
|
2017-02-11 06:00:08 -05:00
|
|
|
;;
|
2017-07-14 15:23:12 +02:00
|
|
|
;; The three key commands are:
|
|
|
|
;;
|
2018-06-17 21:35:58 +02:00
|
|
|
;; + `bin/doom install`: Installs packages that are wanted, but not installed.
|
|
|
|
;; + `bin/doom update`: Updates packages that are out-of-date.
|
|
|
|
;; + `bin/doom autoremove`: Uninstalls packages that are no longer needed.
|
2017-07-14 15:23:12 +02:00
|
|
|
;;
|
|
|
|
;; This system reads packages.el files located in each activated module (and one
|
2017-11-13 18:03:36 +01:00
|
|
|
;; in `doom-core-dir'). These contain `package!' blocks that tell DOOM what
|
2017-07-14 15:23:12 +02:00
|
|
|
;; plugins to install and where from.
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2017-01-28 02:02:16 -05:00
|
|
|
;; Why all the trouble? Because:
|
2017-05-19 02:57:39 +02:00
|
|
|
;; 1. Scriptability: I live in the command line. I want a programmable
|
|
|
|
;; alternative to `list-packages' for updating and installing packages.
|
2017-05-19 22:29:47 +02:00
|
|
|
;; 2. Flexibility: I want packages from sources other than ELPA. Primarily
|
|
|
|
;; github, because certain plugins are out-of-date through official channels,
|
2017-07-02 16:47:02 +02:00
|
|
|
;; have changed hands, have a superior fork, or simply aren't in any ELPA
|
|
|
|
;; repo.
|
2017-05-19 02:57:39 +02:00
|
|
|
;; 3. Stability: I used Cask before this. It would error out with cyrptic errors
|
|
|
|
;; depending on the version of Emacs I used and the alignment of the planets.
|
|
|
|
;; No more.
|
|
|
|
;; 4. Performance: A minor point, but this system is lazy-loaded (more so if you
|
|
|
|
;; byte-compile). Not having to initialize package.el (or check that your
|
|
|
|
;; packages are installed) every time you start up Emacs affords us precious
|
|
|
|
;; seconds.
|
2017-06-05 16:45:19 +02:00
|
|
|
;; 5. Simplicity: No Cask, no external dependencies (unless you count make),
|
|
|
|
;; just Emacs. Arguably, my config is still over-complicated, but shhh, it's
|
|
|
|
;; fine. Everything is fine.
|
2017-02-06 00:13:24 -05:00
|
|
|
;;
|
2018-03-14 18:25:22 -04:00
|
|
|
;; You should be able to use package.el commands without any conflicts.
|
2017-02-06 00:13:24 -05:00
|
|
|
;;
|
|
|
|
;; See core/autoload/packages.el for more functions.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-06-05 14:21:52 +02:00
|
|
|
(defvar doom-packages ()
|
2017-02-11 06:00:08 -05:00
|
|
|
"A list of enabled packages. Each element is a sublist, whose CAR is the
|
|
|
|
package's name as a symbol, and whose CDR is the plist supplied to its
|
2017-02-23 00:06:12 -05:00
|
|
|
`package!' declaration. Set by `doom-initialize-packages'.")
|
2017-02-11 06:00:08 -05:00
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
(defvar doom-core-packages '(persistent-soft use-package quelpa async)
|
2017-02-11 06:00:08 -05:00
|
|
|
"A list of packages that must be installed (and will be auto-installed if
|
|
|
|
missing) and shouldn't be deleted.")
|
|
|
|
|
2017-06-05 16:45:42 +02:00
|
|
|
(defvar doom-disabled-packages ()
|
|
|
|
"A list of packages that should be ignored by `def-package!'.")
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
(setq package--init-file-ensured t
|
2017-01-16 23:15:48 -05:00
|
|
|
package-user-dir (expand-file-name "elpa" doom-packages-dir)
|
2018-06-20 12:45:51 +02:00
|
|
|
package-gnupghome-dir (expand-file-name "gpg" doom-packages-dir)
|
2017-01-16 23:15:48 -05:00
|
|
|
package-enable-at-startup nil
|
|
|
|
package-archives
|
2018-05-14 15:57:54 +02:00
|
|
|
'(("gnu" . "https://elpa.gnu.org/packages/")
|
|
|
|
("melpa" . "https://melpa.org/packages/")
|
|
|
|
("org" . "https://orgmode.org/elpa/"))
|
2017-02-11 00:46:42 -05:00
|
|
|
;; I omit Marmalade because its packages are manually submitted rather
|
|
|
|
;; than pulled, so packages are often out of date with upstream.
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-06-05 16:45:19 +02:00
|
|
|
;; Don't track MELPA, we'll use package.el for that
|
2017-01-16 23:15:48 -05:00
|
|
|
quelpa-checkout-melpa-p nil
|
|
|
|
quelpa-update-melpa-p nil
|
2017-02-19 06:59:55 -05:00
|
|
|
quelpa-melpa-recipe-stores nil
|
|
|
|
quelpa-self-upgrade-p nil
|
2017-05-21 13:42:06 +02:00
|
|
|
quelpa-verbose doom-debug-mode
|
2018-06-11 23:18:15 +02:00
|
|
|
quelpa-dir (expand-file-name "quelpa" doom-packages-dir))
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2018-05-14 15:57:54 +02:00
|
|
|
;; accommodate INSECURE setting
|
|
|
|
(unless gnutls-verify-error
|
|
|
|
(dolist (archive package-archives)
|
|
|
|
(setcdr archive (replace-regexp-in-string "^https://" "http://" (cdr archive) t nil))))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
2018-06-11 23:18:15 +02:00
|
|
|
;; Bootstrapper
|
2018-05-14 15:57:54 +02:00
|
|
|
;;
|
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defun doom-initialize-packages (&optional force-p)
|
2018-05-20 00:01:07 +02:00
|
|
|
"Ensures that Doom's package management system, package.el and quelpa are
|
|
|
|
initialized, and `doom-packages', `packages-alist' and `quelpa-cache' are
|
|
|
|
populated, if they aren't already.
|
2018-03-02 17:45:15 -05:00
|
|
|
|
2018-05-20 00:01:07 +02:00
|
|
|
If FORCE-P is non-nil, do it anyway.
|
|
|
|
If FORCE-P is 'internal, only (re)populate `doom-packages'.
|
2018-03-02 17:45:15 -05:00
|
|
|
|
|
|
|
Use this before any of package.el, quelpa or Doom's package management's API to
|
|
|
|
ensure all the necessary package metadata is initialized and available for
|
|
|
|
them."
|
2017-11-05 01:23:36 +01:00
|
|
|
(with-temp-buffer ; prevent buffer-local settings from propagating
|
2018-05-25 01:17:01 +02:00
|
|
|
(let ((load-prefer-newer t)) ; reduce stale code issues
|
2018-03-02 17:45:15 -05:00
|
|
|
;; package.el and quelpa handle themselves if their state changes during
|
|
|
|
;; the current session, but if you change an packages.el file in a module,
|
|
|
|
;; there's no non-trivial way to detect that, so we give you a way to
|
2018-05-14 18:40:35 +02:00
|
|
|
;; reload only doom-packages (by passing 'internal as FORCE-P).
|
2018-05-24 21:17:35 +02:00
|
|
|
(unless (eq force-p 'internal)
|
|
|
|
;; `package-alist'
|
|
|
|
(when (or force-p (not (bound-and-true-p package-alist)))
|
2018-06-12 12:18:21 +02:00
|
|
|
(setq load-path (cons doom-core-dir doom-site-load-path))
|
2018-06-09 20:13:20 +02:00
|
|
|
(doom-ensure-packages-initialized 'force))
|
2018-05-24 21:17:35 +02:00
|
|
|
;; `quelpa-cache'
|
|
|
|
(when (or force-p (not (bound-and-true-p quelpa-cache)))
|
2018-06-04 21:19:46 +02:00
|
|
|
;; ensure un-byte-compiled version of quelpa is loaded
|
|
|
|
(unless (featurep 'quelpa)
|
|
|
|
(load (locate-library "quelpa.el") nil t t))
|
2018-05-24 21:17:35 +02:00
|
|
|
(setq quelpa-initialized-p nil)
|
|
|
|
(or (quelpa-setup-p)
|
|
|
|
(error "Could not initialize quelpa"))))
|
2018-06-20 02:07:12 +02:00
|
|
|
;; `doom-packages'
|
2018-05-24 21:17:35 +02:00
|
|
|
(when (or force-p (not doom-packages))
|
2018-06-20 02:07:12 +02:00
|
|
|
(cl-flet
|
|
|
|
((_load
|
|
|
|
(lambda (file &optional noerror)
|
|
|
|
(condition-case e
|
|
|
|
(load file noerror t t)
|
|
|
|
((debug error)
|
|
|
|
(signal 'doom-package-error
|
|
|
|
(list (or (doom-module-from-path file)
|
|
|
|
'(:private . packages))
|
|
|
|
e)))))))
|
|
|
|
(let ((doom-modules (doom-modules))
|
|
|
|
(doom--stage 'packages)
|
|
|
|
(noninteractive t))
|
|
|
|
(setq doom-packages nil)
|
|
|
|
(_load (expand-file-name "packages.el" doom-core-dir))
|
|
|
|
;; We load the private packages file twice to ensure disabled
|
|
|
|
;; packages are seen ASAP, and a second time to ensure privately
|
|
|
|
;; overridden packages are properly overwritten.
|
|
|
|
(let ((private-packages (expand-file-name "packages.el" doom-private-dir)))
|
|
|
|
(_load private-packages t)
|
|
|
|
(cl-loop for key being the hash-keys of doom-modules
|
|
|
|
for path = (doom-module-path (car key) (cdr key) "packages.el")
|
|
|
|
do (let ((doom--current-module key)) (_load path t)))
|
|
|
|
(_load private-packages t))))))))
|
2018-03-02 17:45:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2018-06-11 23:18:15 +02:00
|
|
|
;; Package API
|
2018-03-02 17:45:15 -05:00
|
|
|
;;
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
(defun doom-ensure-packages-initialized (&optional force-p)
|
|
|
|
"Make sure package.el is initialized."
|
|
|
|
(when (or force-p (not (bound-and-true-p package--initialized)))
|
|
|
|
(require 'package)
|
|
|
|
(setq package-activated-list nil
|
|
|
|
package--initialized nil)
|
|
|
|
(let (byte-compile-warnings)
|
|
|
|
(condition-case _
|
|
|
|
(quiet! (package-initialize))
|
|
|
|
('error (package-refresh-contents)
|
|
|
|
(setq doom--refreshed-p t)
|
|
|
|
(package-initialize))))))
|
2018-05-18 01:21:09 +02:00
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
(defun doom-ensure-core-packages ()
|
|
|
|
"Make sure `doom-core-packages' are installed."
|
|
|
|
(when-let* ((core-packages (cl-remove-if #'package-installed-p doom-core-packages)))
|
|
|
|
(message "Installing core packages")
|
|
|
|
(unless doom--refreshed-p
|
|
|
|
(package-refresh-contents))
|
|
|
|
(dolist (package core-packages)
|
|
|
|
(let ((inhibit-message t))
|
|
|
|
(package-install package))
|
|
|
|
(if (package-installed-p package)
|
|
|
|
(message "✓ Installed %s" package)
|
|
|
|
(error "✕ Couldn't install %s" package)))
|
|
|
|
(message "Installing core packages...done")))
|
2017-02-11 06:52:38 -05:00
|
|
|
|
2017-02-06 00:13:24 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
2018-03-02 17:45:15 -05:00
|
|
|
;; Module package macros
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro package! (name &rest plist)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Declares a package and how to install it (if applicable).
|
|
|
|
|
|
|
|
This macro is declarative and does not load nor install packages. It is used to
|
|
|
|
populate `doom-packages' with metadata about the packages Doom needs to keep
|
|
|
|
track of.
|
|
|
|
|
2018-04-03 15:00:52 -04:00
|
|
|
Only use this macro in a module's packages.el file.
|
2017-02-04 21:07:54 -05:00
|
|
|
|
2017-02-11 00:46:42 -05:00
|
|
|
Accepts the following properties:
|
2017-02-03 20:10:40 -05:00
|
|
|
|
2018-03-26 16:44:24 -04:00
|
|
|
:recipe RECIPE
|
|
|
|
Takes a MELPA-style recipe (see `quelpa-recipe' in `quelpa' for an example);
|
|
|
|
for packages to be installed from external sources.
|
|
|
|
:pin ARCHIVE-NAME
|
|
|
|
Instructs ELPA to only look for this package in ARCHIVE-NAME. e.g. \"org\".
|
|
|
|
Ignored if RECIPE is present.
|
|
|
|
:disable BOOL
|
|
|
|
Do not install or update this package AND disable all of its `def-package!'
|
|
|
|
blocks.
|
|
|
|
:ignore FORM
|
2018-03-26 18:15:03 -04:00
|
|
|
Do not install this package.
|
2018-03-26 16:44:24 -04:00
|
|
|
:freeze FORM
|
2018-05-15 23:11:48 +02:00
|
|
|
Do not update this package if FORM is non-nil.
|
|
|
|
|
|
|
|
Returns t if package is successfully registered, and nil if it was disabled
|
|
|
|
elsewhere."
|
2017-01-16 23:15:48 -05:00
|
|
|
(declare (indent defun))
|
2018-05-14 18:40:35 +02:00
|
|
|
(doom--assert-stage-p 'packages #'package!)
|
2018-06-20 02:07:12 +02:00
|
|
|
(let* ((old-plist (cdr (assq name doom-packages)))
|
|
|
|
(pkg-recipe (or (plist-get plist :recipe)
|
|
|
|
(and old-plist (plist-get old-plist :recipe))))
|
|
|
|
(pkg-pin (or (plist-get plist :pin)
|
|
|
|
(and old-plist (plist-get old-plist :pin))))
|
|
|
|
(pkg-disable (or (plist-get plist :disable)
|
|
|
|
(and old-plist (plist-get old-plist :disable)))))
|
|
|
|
(when pkg-disable
|
|
|
|
(add-to-list 'doom-disabled-packages name nil #'eq))
|
|
|
|
(when pkg-recipe
|
|
|
|
(when (= 0 (% (length pkg-recipe) 2))
|
|
|
|
(setq plist (plist-put plist :recipe (cons name pkg-recipe))))
|
|
|
|
(when pkg-pin
|
|
|
|
(setq plist (plist-put plist :pin nil))))
|
|
|
|
(dolist (prop '(:ignore :freeze))
|
|
|
|
(when-let* ((val (plist-get plist prop)))
|
|
|
|
(setq plist (plist-put plist prop (eval val)))))
|
|
|
|
(when (file-in-directory-p (or (bound-and-true-p byte-compile-current-file)
|
|
|
|
load-file-name)
|
|
|
|
doom-private-dir)
|
|
|
|
(setq plist (plist-put plist :private t)))
|
|
|
|
`(progn
|
2018-06-23 16:48:58 +02:00
|
|
|
,(if pkg-pin `(setf (alist-get ',name package-pinned-packages) ,pkg-pin))
|
|
|
|
(setf (alist-get ',name doom-packages) ',plist)
|
2018-06-20 02:07:12 +02:00
|
|
|
(not (memq ',name doom-disabled-packages)))))
|
2017-01-28 02:02:16 -05:00
|
|
|
|
2018-03-26 02:58:22 -04:00
|
|
|
(defmacro packages! (&rest packages)
|
|
|
|
"A convenience macro like `package!', but allows you to declare multiple
|
2018-04-03 15:00:52 -04:00
|
|
|
packages at once.
|
|
|
|
|
|
|
|
Only use this macro in a module's packages.el file."
|
2018-05-14 18:40:35 +02:00
|
|
|
(doom--assert-stage-p 'packages #'packages!)
|
2018-05-15 23:13:06 +02:00
|
|
|
`(progn ,@(cl-loop for desc in packages collect `(package! ,@(doom-enlist desc)))))
|
2018-03-26 02:58:22 -04:00
|
|
|
|
|
|
|
(defmacro disable-packages! (&rest packages)
|
|
|
|
"A convenience macro like `package!', but allows you to disable multiple
|
2018-04-03 15:00:52 -04:00
|
|
|
packages at once.
|
|
|
|
|
|
|
|
Only use this macro in a module's packages.el file."
|
2018-05-14 18:40:35 +02:00
|
|
|
(doom--assert-stage-p 'packages #'disable-packages!)
|
2018-03-26 02:58:22 -04:00
|
|
|
`(setq doom-disabled-packages (append ',packages doom-disabled-packages)))
|
|
|
|
|
2018-03-02 17:45:15 -05:00
|
|
|
(defmacro depends-on! (module submodule &optional flags)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Declares that this module depends on another.
|
|
|
|
|
|
|
|
Only use this macro in a module's packages.el file.
|
|
|
|
|
|
|
|
MODULE is a keyword, and SUBMODULE is a symbol. Under the hood, this simply
|
|
|
|
loads MODULE SUBMODULE's packages.el file."
|
2018-05-14 18:40:35 +02:00
|
|
|
(doom--assert-stage-p 'packages #'depends-on!)
|
2018-03-02 17:45:15 -05:00
|
|
|
`(let ((doom-modules ,doom-modules)
|
|
|
|
(flags ,flags))
|
|
|
|
(when flags
|
|
|
|
(doom-module-put ,module ',submodule :flags flags))
|
2018-05-27 12:44:22 +02:00
|
|
|
(load! "packages" ,(doom-module-locate-path module submodule) t)))
|
2018-05-16 00:09:44 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(provide 'core-packages)
|
|
|
|
;;; core-packages.el ends here
|