2017-06-08 11:47:56 +02:00
|
|
|
;;; core-packages.el --- package management system -*- 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-05-24 21:17:23 +02:00
|
|
|
;; + `bin/doom install` or `doom//packages-install': Installs packages that are
|
2017-07-14 15:23:12 +02:00
|
|
|
;; wanted, but not installed.
|
2018-05-24 21:17:23 +02:00
|
|
|
;; + `bin/doom update` or `doom//packages-update': Updates packages that are
|
2017-07-14 15:23:12 +02:00
|
|
|
;; out-of-date.
|
2018-05-24 21:17:23 +02:00
|
|
|
;; + `bin/doom autoremove` or `doom//packages-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-02-03 07:58:16 -05:00
|
|
|
(defvar doom-init-p nil
|
2018-05-24 19:00:41 +02:00
|
|
|
"Non-nil if `doom-initialize' has run.")
|
|
|
|
|
|
|
|
(defvar doom-init-modules-p nil
|
|
|
|
"Non-nil if `doom-initialize-modules' has run.")
|
2017-06-12 00:20:30 +02:00
|
|
|
|
2017-06-05 14:21:52 +02:00
|
|
|
(defvar doom-init-time nil
|
|
|
|
"The time it took, in seconds, for DOOM Emacs to initialize.")
|
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
(defvar doom-modules ()
|
2017-02-20 09:47:27 -05:00
|
|
|
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
|
2017-01-31 04:31:14 -05:00
|
|
|
|
2018-04-03 03:07:26 -04:00
|
|
|
(defvar doom-modules-dirs
|
2018-04-03 15:57:51 -04:00
|
|
|
(list (expand-file-name "modules/" doom-private-dir) doom-modules-dir)
|
2018-03-27 19:11:11 -04:00
|
|
|
"A list of module root directories. Order determines priority.")
|
|
|
|
|
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-02-16 02:02:58 -05:00
|
|
|
(defvar doom-site-load-path load-path
|
|
|
|
"The starting load-path, before it is altered by `doom-initialize'.")
|
2017-03-05 13:32:12 -05:00
|
|
|
|
2018-02-27 22:24:36 -05:00
|
|
|
(defvar doom-autoload-file (concat doom-local-dir "autoloads.el")
|
2018-05-24 19:00:41 +02:00
|
|
|
"Where `doom//reload-doom-autoloads' will generate its core autoloads file.")
|
2018-02-27 22:24:36 -05:00
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
(defvar doom-package-autoload-file (concat doom-local-dir "autoloads.pkg.el")
|
|
|
|
"Where `doom//reload-package-autoloads' will generate its package.el autoloads
|
|
|
|
file.")
|
2017-03-05 13:32:12 -05:00
|
|
|
|
2018-05-19 23:58:14 +02:00
|
|
|
(defvar doom-reload-hook nil
|
|
|
|
"A list of hooks to run when `doom//reload-load-path' is called.")
|
|
|
|
|
2018-06-05 11:18:36 +02:00
|
|
|
(defvar doom-emacs-changed-p nil
|
|
|
|
"If non-nil, the running version of Emacs is different from the first time
|
|
|
|
Doom was setup, which can cause problems.")
|
|
|
|
|
2018-02-16 02:02:58 -05:00
|
|
|
(defvar doom--current-module nil)
|
2018-03-28 02:56:21 -04:00
|
|
|
(defvar doom--refreshed-p nil)
|
2018-05-15 11:23:44 +02:00
|
|
|
(defvar doom--stage 'init)
|
2017-06-06 12:01:10 +02:00
|
|
|
|
2018-05-14 15:57:54 +02:00
|
|
|
;;
|
2018-03-02 17:45:15 -05:00
|
|
|
(setq autoload-compute-prefixes nil
|
|
|
|
package--init-file-ensured t
|
2017-01-16 23:15:48 -05:00
|
|
|
package-user-dir (expand-file-name "elpa" doom-packages-dir)
|
|
|
|
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-05-19 22:28:01 +02:00
|
|
|
;; security settings
|
2017-05-26 20:17:51 +02:00
|
|
|
gnutls-verify-error (not (getenv "INSECURE")) ; you shouldn't use this
|
2017-05-20 18:26:03 +02:00
|
|
|
tls-checktrust gnutls-verify-error
|
|
|
|
tls-program (list "gnutls-cli --x509cafile %t -p %p %h"
|
2017-05-26 20:17:51 +02:00
|
|
|
;; compatibility fallbacks
|
|
|
|
"gnutls-cli -p %p %h"
|
|
|
|
"openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof")
|
2017-05-19 22:28:01 +02:00
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
use-package-verbose doom-debug-mode
|
2017-03-01 19:16:49 -05:00
|
|
|
use-package-minimum-reported-time (if doom-debug-mode 0 0.1)
|
2017-02-06 01:23:24 -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
|
2017-01-31 18:59:58 -05:00
|
|
|
quelpa-dir (expand-file-name "quelpa" doom-packages-dir)
|
2017-02-06 01:23:24 -05:00
|
|
|
|
2017-04-06 19:43:56 -04:00
|
|
|
byte-compile-verbose doom-debug-mode
|
2017-04-17 02:17:26 -04:00
|
|
|
byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local))
|
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-05-14 18:40:35 +02:00
|
|
|
;; Helpers 'n hooks
|
2018-05-14 15:57:54 +02:00
|
|
|
;;
|
|
|
|
|
2018-05-14 18:40:35 +02:00
|
|
|
(defun doom--assert-stage-p (stage macro)
|
|
|
|
(cl-assert (eq stage doom--stage)
|
|
|
|
nil
|
|
|
|
"Found %s call in non-%s.el file (%s)"
|
|
|
|
macro (symbol-name stage)
|
|
|
|
(if (file-in-directory-p load-file-name doom-emacs-dir)
|
|
|
|
(file-relative-name load-file-name doom-emacs-dir)
|
|
|
|
(abbreviate-file-name load-file-name))))
|
|
|
|
|
|
|
|
(defun doom|display-benchmark (&optional return-p)
|
|
|
|
"Display a benchmark, showing number of packages and modules, and how quickly
|
|
|
|
they were loaded at startup.
|
|
|
|
|
|
|
|
If RETURN-P, return the message as a string instead of displaying it."
|
|
|
|
(funcall (if return-p #'format #'message)
|
|
|
|
"Doom loaded %s packages across %d modules in %.03fs"
|
2018-06-05 11:21:24 +02:00
|
|
|
(length package-activated-list)
|
2018-05-25 01:26:24 +02:00
|
|
|
(if doom-modules (hash-table-count doom-modules) 0)
|
2018-05-14 18:40:35 +02:00
|
|
|
(or doom-init-time
|
|
|
|
(setq doom-init-time (float-time (time-subtract (current-time) before-init-time))))))
|
|
|
|
|
2018-05-19 23:58:14 +02:00
|
|
|
(defun doom|post-init ()
|
|
|
|
"Run `doom-post-init-hook'. That's all."
|
|
|
|
(run-hooks 'doom-post-init-hook))
|
|
|
|
|
|
|
|
(defun doom|run-all-startup-hooks ()
|
2018-05-24 21:17:23 +02:00
|
|
|
"Run all startup Emacs hooks. Meant to be executed after starting Emacs with
|
|
|
|
-q or -Q, for example:
|
2018-05-19 23:58:14 +02:00
|
|
|
|
|
|
|
emacs -Q -l init.el -f doom|run-all-startup-hooks"
|
|
|
|
(run-hooks 'after-init-hook 'delayed-warnings-hook
|
|
|
|
'emacs-startup-hook 'term-setup-hook
|
|
|
|
'window-setup-hook))
|
2018-03-02 17:45:15 -05:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
;;
|
|
|
|
;; Bootstrap helpers
|
|
|
|
;;
|
|
|
|
|
2018-06-05 11:18:36 +02:00
|
|
|
(defvar doom--last-emacs-file (concat doom-local-dir "emacs-version.el"))
|
|
|
|
(defvar doom--last-emacs-version nil)
|
|
|
|
|
|
|
|
(defun doom-ensure-same-emacs-version-p ()
|
|
|
|
"Do an Emacs version check and set `doom-emacs-changed-p' if it has changed."
|
|
|
|
(if (load doom--last-emacs-file 'noerror 'nomessage 'nosuffix)
|
|
|
|
(setq doom-emacs-changed-p
|
|
|
|
(not (equal emacs-version doom--last-emacs-version)))
|
|
|
|
(with-temp-file doom--last-emacs-file
|
|
|
|
(princ `(setq doom--last-emacs-version ,(prin1-to-string emacs-version))
|
|
|
|
(current-buffer))))
|
|
|
|
(cond ((not doom-emacs-changed-p))
|
|
|
|
((y-or-n-p
|
|
|
|
(format
|
|
|
|
(concat "Your version of Emacs has changed from %s to %s, which may cause incompatibility\n"
|
|
|
|
"issues. Please run `bin/doom compile :plugins` afterwards to resolve any problems.\n\n"
|
|
|
|
"Continue?")
|
|
|
|
doom--last-emacs-version
|
|
|
|
emacs-version))
|
|
|
|
(delete-file doom--last-emacs-file))
|
|
|
|
(noninteractive (error "Aborting"))
|
|
|
|
((kill-emacs))))
|
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
(defun doom-ensure-packages-initialized (&optional force-p)
|
|
|
|
"Make sure package.el is initialized."
|
2018-06-08 16:04:31 +02:00
|
|
|
(when (or force-p (not (bound-and-true-p package--initialized)))
|
2018-05-24 19:00:41 +02:00
|
|
|
(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))))))
|
|
|
|
|
|
|
|
(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")))
|
|
|
|
|
|
|
|
(defun doom-ensure-core-directories ()
|
|
|
|
"Make sure all Doom's essential local directories (in and including
|
|
|
|
`doom-local-dir') exist."
|
|
|
|
(dolist (dir (list doom-local-dir doom-etc-dir doom-cache-dir doom-packages-dir))
|
|
|
|
(unless (file-directory-p dir)
|
|
|
|
(make-directory dir t))))
|
|
|
|
|
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
2018-03-02 17:45:15 -05:00
|
|
|
;; Bootstrap API
|
2017-01-16 23:15:48 -05:00
|
|
|
;;
|
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
(autoload 'doom//reload-doom-autoloads "autoload/modules" nil t)
|
|
|
|
(autoload 'doom//reload-package-autoloads "autoload/modules" nil t)
|
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
(defun doom-initialize (&optional force-p)
|
2018-05-20 00:01:07 +02:00
|
|
|
"Bootstrap Doom, if it hasn't already (or if FORCE-P is non-nil).
|
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
The bootstrap process involves making sure 1) the essential directories exist,
|
|
|
|
2) the core packages are installed, 3) `doom-autoload-file' and
|
|
|
|
`doom-package-autoload-file' exist and have been loaded, and 4) Doom's core
|
|
|
|
files are loaded.
|
2018-05-20 00:01:07 +02:00
|
|
|
|
|
|
|
If the cache exists, much of this function isn't run, which substantially
|
|
|
|
reduces startup time.
|
|
|
|
|
|
|
|
The overall load order of Doom is as follows:
|
|
|
|
|
|
|
|
~/.emacs.d/init.el
|
|
|
|
~/.emacs.d/core/core.el
|
|
|
|
`doom-pre-init-hook'
|
|
|
|
~/.doom.d/init.el
|
|
|
|
Module init.el files
|
|
|
|
`doom-init-hook'
|
|
|
|
Module config.el files
|
|
|
|
~/.doom.d/config.el
|
|
|
|
`after-init-hook'
|
|
|
|
`emacs-startup-hook'
|
|
|
|
`doom-post-init-hook' (at end of `emacs-startup-hook')
|
|
|
|
|
|
|
|
Module load order is determined by your `doom!' block. See `doom-modules-dirs'
|
|
|
|
for a list of all recognized module trees. Order defines precedence (from most
|
|
|
|
to least)."
|
2017-12-22 15:21:36 -05:00
|
|
|
(when (or force-p (not doom-init-p))
|
2018-05-24 19:00:41 +02:00
|
|
|
;; Set this to prevent infinite recursive calls to `doom-initialize'
|
|
|
|
(setq doom-init-p t)
|
|
|
|
;; `doom-autoload-file' tells Emacs where to load all its autoloaded
|
|
|
|
;; functions from. This includes everything in core/autoload/*.el and all
|
|
|
|
;; the autoload files in your enabled modules.
|
|
|
|
(unless (doom-initialize-autoloads doom-autoload-file force-p)
|
|
|
|
(doom-ensure-core-directories)
|
2018-06-05 12:09:42 +02:00
|
|
|
(doom-ensure-same-emacs-version-p)
|
2018-05-24 19:00:41 +02:00
|
|
|
(doom-ensure-packages-initialized force-p)
|
|
|
|
(doom-ensure-core-packages)
|
|
|
|
;; Regenerate `doom-autoload-file', which tells Doom where to find all its
|
|
|
|
;; module autoloaded functions.
|
|
|
|
(unless (or force-p noninteractive)
|
|
|
|
(doom//reload-doom-autoloads)))
|
|
|
|
;; Loads `doom-package-autoload-file', which caches `load-path',
|
|
|
|
;; `auto-mode-alist', `Info-directory-list', `doom-disabled-packages' and
|
|
|
|
;; `package-activated-list'. A big reduction in startup time.
|
2018-06-09 20:13:20 +02:00
|
|
|
(unless (or force-p
|
|
|
|
(doom-initialize-autoloads doom-package-autoload-file)
|
|
|
|
noninteractive)
|
|
|
|
(doom//reload-package-autoloads)))
|
2018-05-20 15:23:37 +02:00
|
|
|
;; Initialize Doom core
|
2018-05-14 18:40:35 +02:00
|
|
|
(unless noninteractive
|
2018-05-28 16:07:11 +02:00
|
|
|
(add-hook! 'emacs-startup-hook
|
|
|
|
#'(doom|post-init doom|display-benchmark))
|
2018-06-08 13:31:45 +02:00
|
|
|
(require 'core-os)
|
2018-05-14 18:40:35 +02:00
|
|
|
(require 'core-ui)
|
|
|
|
(require 'core-editor)
|
|
|
|
(require 'core-projects)
|
2018-05-24 19:00:41 +02:00
|
|
|
(require 'core-keybinds)))
|
|
|
|
|
|
|
|
(defun doom-initialize-modules (&optional force-p)
|
|
|
|
"Loads the init.el in `doom-private-dir' and sets up hooks for a healthy
|
|
|
|
session of Dooming. Will noop if used more than once, unless FORCE-P is
|
|
|
|
non-nil."
|
|
|
|
(when (or force-p (not doom-init-modules-p))
|
|
|
|
;; Set `doom-init-modules-p' early, so `doom-pre-init-hook' won't infinitely
|
|
|
|
;; recurse by accident if any of them need `doom-initialize-modules'.
|
|
|
|
(setq doom-init-modules-p t)
|
2018-05-19 23:58:14 +02:00
|
|
|
(when doom-private-dir
|
2018-06-01 17:07:53 +02:00
|
|
|
(load (expand-file-name "init" doom-private-dir)
|
|
|
|
'noerror 'nomessage))))
|
2018-05-24 19:00:41 +02:00
|
|
|
|
2018-06-09 20:13:20 +02:00
|
|
|
(defun doom-initialize-autoloads (file)
|
|
|
|
"Tries to load FILE (an autoloads file)."
|
2018-05-24 19:00:41 +02:00
|
|
|
(unless clear-p
|
2018-06-04 21:20:13 +02:00
|
|
|
(condition-case-unless-debug e
|
|
|
|
(load (file-name-sans-extension file) 'noerror 'nomessage)
|
|
|
|
('error
|
|
|
|
(message "Autoload error: %s -> %s"
|
|
|
|
(car e) (error-message-string e))))))
|
2017-02-11 00:46:42 -05: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-03-02 17:45:15 -05:00
|
|
|
;; `doom-packages'
|
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)))
|
|
|
|
(setq load-path 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-05-14 18:40:35 +02:00
|
|
|
|
2018-05-24 21:17:35 +02:00
|
|
|
(when (or force-p (not doom-packages))
|
2018-06-09 20:13:20 +02:00
|
|
|
(let ((doom-modules (doom-modules)))
|
2018-05-25 01:17:01 +02:00
|
|
|
(setq doom-packages nil)
|
|
|
|
(cl-flet
|
|
|
|
((_load
|
|
|
|
(file &optional noerror interactive)
|
|
|
|
(condition-case-unless-debug ex
|
|
|
|
(let ((noninteractive (not interactive)))
|
|
|
|
(load file noerror 'nomessage 'nosuffix))
|
|
|
|
('error
|
|
|
|
(lwarn 'doom-initialize-packages :warning
|
|
|
|
"%s in %s: %s"
|
|
|
|
(car ex)
|
|
|
|
(file-relative-name file doom-emacs-dir)
|
|
|
|
(error-message-string ex))))))
|
|
|
|
(let ((doom--stage 'packages))
|
|
|
|
(_load (expand-file-name "packages.el" doom-core-dir))
|
2018-06-01 17:03:01 +02:00
|
|
|
;; 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.
|
2018-06-09 20:13:20 +02:00
|
|
|
(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
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Module API
|
|
|
|
;;
|
|
|
|
|
2018-05-20 00:03:53 +02:00
|
|
|
(defun doom-module-p (category module)
|
|
|
|
"Returns t if CATEGORY MODULE is enabled (ie. present in `doom-modules')."
|
2018-03-02 17:45:15 -05:00
|
|
|
(and (hash-table-p doom-modules)
|
2018-05-20 00:03:53 +02:00
|
|
|
(gethash (cons category module) doom-modules)
|
2018-03-02 17:45:15 -05:00
|
|
|
t))
|
|
|
|
|
2018-05-20 00:03:53 +02:00
|
|
|
(defun doom-module-get (category module &optional property)
|
|
|
|
"Returns the plist for CATEGORY MODULE. Gets PROPERTY, specifically, if set."
|
|
|
|
(when-let* ((plist (gethash (cons category module) doom-modules)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(if property
|
|
|
|
(plist-get plist property)
|
|
|
|
plist)))
|
|
|
|
|
2018-05-20 00:03:53 +02:00
|
|
|
(defun doom-module-put (category module property value &rest rest)
|
|
|
|
"Set a PROPERTY for CATEGORY MODULE to VALUE. PLIST should be additional pairs
|
|
|
|
of PROPERTY and VALUEs."
|
|
|
|
(when-let* ((plist (doom-module-get category module)))
|
|
|
|
(plist-put plist property value)
|
|
|
|
(when rest
|
|
|
|
(when (cl-oddp (length rest))
|
2018-05-25 16:31:55 +02:00
|
|
|
(signal 'wrong-number-of-arguments (list (length rest))))
|
2018-05-20 00:03:53 +02:00
|
|
|
(while rest
|
|
|
|
(plist-put rest (pop rest) (pop rest))))
|
|
|
|
(puthash (cons category module) plist doom-modules)))
|
|
|
|
|
|
|
|
(defun doom-module-set (category module &rest plist)
|
|
|
|
"Enables a module by adding it to `doom-modules'.
|
|
|
|
|
|
|
|
CATEGORY is a keyword, module is a symbol, PLIST is a plist that accepts the
|
2018-03-02 17:45:15 -05:00
|
|
|
following properties:
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-05-20 00:03:53 +02:00
|
|
|
:flags [SYMBOL LIST] list of enabled category flags
|
|
|
|
:path [STRING] path to category root directory
|
2018-03-02 17:45:15 -05:00
|
|
|
|
|
|
|
Example:
|
2018-05-20 00:03:53 +02:00
|
|
|
(doom-module-set :lang 'haskell :flags '(+intero))"
|
2018-03-02 17:45:15 -05:00
|
|
|
(when plist
|
2018-05-20 00:03:53 +02:00
|
|
|
(let ((old-plist (doom-module-get category module)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(unless (plist-member plist :flags)
|
|
|
|
(plist-put plist :flags (plist-get old-plist :flags)))
|
|
|
|
(unless (plist-member plist :path)
|
|
|
|
(plist-put plist :path (or (plist-get old-plist :path)
|
2018-05-20 00:03:53 +02:00
|
|
|
(doom-module-locate-path category module))))))
|
|
|
|
(let ((key (cons category module)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(puthash key plist doom-modules)))
|
|
|
|
|
2018-05-20 00:03:53 +02:00
|
|
|
(defun doom-module-path (category module &optional file)
|
|
|
|
"Like `expand-file-name', but expands FILE relative to CATEGORY (keywordp) and
|
|
|
|
MODULE (symbol).
|
|
|
|
|
|
|
|
If the category isn't enabled this will always return nil. For finding disabled
|
|
|
|
modules use `doom-module-locate-path'."
|
|
|
|
(let ((path (doom-module-get category module :path)))
|
|
|
|
(if file (expand-file-name file path)
|
|
|
|
path)))
|
|
|
|
|
|
|
|
(defun doom-module-locate-path (category &optional module file)
|
|
|
|
"Searches `doom-modules-dirs' to find the path to a module.
|
|
|
|
|
|
|
|
CATEGORY is a keyword (e.g. :lang) and MODULE is a symbol (e.g. 'python). FILE
|
|
|
|
is a string that will be appended to the resulting path. If no path exists, this
|
|
|
|
returns nil, otherwise an absolute path.
|
|
|
|
|
|
|
|
This doesn't require modules to be enabled. For enabled modules us
|
|
|
|
`doom-module-path'."
|
|
|
|
(when (keywordp category)
|
|
|
|
(setq category (substring (symbol-name category) 1)))
|
|
|
|
(when (and module (symbolp module))
|
|
|
|
(setq module (symbol-name module)))
|
2018-03-02 17:45:15 -05:00
|
|
|
(cl-loop for default-directory in doom-modules-dirs
|
2018-05-20 00:03:53 +02:00
|
|
|
for path = (concat category "/" module "/" file)
|
2018-03-02 17:45:15 -05:00
|
|
|
if (file-exists-p path)
|
|
|
|
return (expand-file-name path)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-02-16 02:02:58 -05:00
|
|
|
(defun doom-module-from-path (&optional path)
|
2018-05-20 00:03:53 +02:00
|
|
|
"Returns a cons cell (CATEGORY . MODULE) derived from PATH (a file path)."
|
|
|
|
(or doom--current-module
|
|
|
|
(when path
|
2018-02-16 02:02:58 -05:00
|
|
|
(save-match-data
|
|
|
|
(setq path (file-truename path))
|
|
|
|
(when (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)/.*$" path)
|
|
|
|
(when-let* ((module (match-string 1 path))
|
|
|
|
(submodule (match-string 2 path)))
|
|
|
|
(cons (intern (concat ":" module))
|
2018-05-20 00:03:53 +02:00
|
|
|
(intern submodule))))))))
|
2018-03-02 17:45:15 -05:00
|
|
|
|
|
|
|
(defun doom-module-load-path ()
|
2018-06-09 20:13:20 +02:00
|
|
|
"Return a list of absolute file paths to activated modules."
|
|
|
|
(append (cl-loop for plist being the hash-values of (doom-modules)
|
2018-03-02 17:45:15 -05:00
|
|
|
collect (plist-get plist :path))
|
2018-06-01 17:01:39 +02:00
|
|
|
(list doom-private-dir)))
|
2017-11-08 22:47:06 +01:00
|
|
|
|
2018-06-09 20:13:20 +02:00
|
|
|
(defun doom-modules (&optional refresh-p)
|
|
|
|
"Minimally initialize `doom-modules' (a hash table) and return it."
|
|
|
|
(let ((noninteractive t))
|
|
|
|
(doom-initialize-modules refresh-p))
|
|
|
|
doom-modules)
|
2018-05-24 19:00:41 +02:00
|
|
|
|
2017-01-31 04:31:14 -05:00
|
|
|
|
|
|
|
;;
|
2018-05-18 01:21:09 +02:00
|
|
|
;; Use-package modifications
|
2017-01-31 04:31:14 -05:00
|
|
|
;;
|
2017-01-16 23:15:48 -05:00
|
|
|
|
2018-05-24 21:17:45 +02:00
|
|
|
(autoload 'use-package "use-package-core" nil nil t)
|
2018-05-20 20:07:15 +02:00
|
|
|
|
2018-05-24 21:17:23 +02:00
|
|
|
;; Adds the :after-call custom keyword to `use-package' (and consequently,
|
|
|
|
;; `def-package!'). :after-call takes a symbol ro list of symbols. These symbols
|
|
|
|
;; can be functions to hook variables.
|
|
|
|
;;
|
|
|
|
;; (use-package X :after-call find-file-hook)
|
|
|
|
;;
|
|
|
|
;; This will load X on the first invokation of `find-file-hook' (then it will
|
|
|
|
;; remove itself from the hook).
|
|
|
|
(defvar doom--deferred-packages-alist ())
|
2018-05-20 20:07:15 +02:00
|
|
|
(after! use-package-core
|
|
|
|
(add-to-list 'use-package-deferring-keywords :after-call nil #'eq)
|
|
|
|
|
|
|
|
(setq use-package-keywords
|
|
|
|
(use-package-list-insert :after-call use-package-keywords :after))
|
|
|
|
|
|
|
|
(defalias 'use-package-normalize/:after-call
|
|
|
|
'use-package-normalize-symlist)
|
|
|
|
|
|
|
|
(defun use-package-handler/:after-call (name-symbol _keyword hooks rest state)
|
|
|
|
(let ((fn (intern (format "doom|transient-hook--load-%s" name-symbol)))
|
|
|
|
(hooks (delete-dups hooks)))
|
|
|
|
(if (plist-get state :demand)
|
|
|
|
(use-package-process-keywords name rest state)
|
|
|
|
(use-package-concat
|
|
|
|
`((fset ',fn
|
|
|
|
(lambda (&rest _)
|
|
|
|
(require ',name-symbol)
|
|
|
|
(dolist (hook (cdr (assq ',name-symbol doom--deferred-packages-alist)))
|
|
|
|
(if (functionp hook)
|
|
|
|
(advice-remove hook #',fn)
|
|
|
|
(remove-hook hook #',fn)))
|
|
|
|
(map-delete doom--deferred-packages-alist ',name-symbol)
|
|
|
|
(fmakunbound ',fn))))
|
|
|
|
(cl-mapcan (lambda (hook)
|
|
|
|
(if (functionp hook)
|
|
|
|
`((advice-add #',hook :before #',fn))
|
|
|
|
`((add-hook ',hook #',fn))))
|
|
|
|
hooks)
|
|
|
|
`((map-put doom--deferred-packages-alist
|
|
|
|
',name-symbol
|
|
|
|
'(,@hooks ,@(cdr (assq name-symbol doom--deferred-packages-alist)))))
|
|
|
|
(use-package-process-keywords name rest state))))))
|
2018-05-18 01:21:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;; Module config macros
|
|
|
|
;;
|
|
|
|
|
2017-02-23 00:06:12 -05:00
|
|
|
(defmacro doom! (&rest modules)
|
2018-01-30 21:26:02 -05:00
|
|
|
"Bootstraps DOOM Emacs and its modules.
|
2017-07-02 16:47:02 +02:00
|
|
|
|
2018-05-24 19:00:41 +02:00
|
|
|
The bootstrap process involves making sure the essential directories exist, core
|
|
|
|
packages are installed, `doom-autoload-file' is loaded, `doom-packages-file'
|
|
|
|
cache exists (and is loaded) and, finally, loads your private init.el (which
|
|
|
|
should contain your `doom!' block).
|
|
|
|
|
|
|
|
If the cache exists, much of this function isn't run, which substantially
|
|
|
|
reduces startup time.
|
|
|
|
|
|
|
|
The overall load order of Doom is as follows:
|
|
|
|
|
|
|
|
~/.emacs.d/init.el
|
|
|
|
~/.emacs.d/core/core.el
|
|
|
|
`doom-pre-init-hook'
|
|
|
|
~/.doom.d/init.el
|
|
|
|
Module init.el files
|
|
|
|
`doom-init-hook'
|
|
|
|
Module config.el files
|
|
|
|
~/.doom.d/config.el
|
|
|
|
`after-init-hook'
|
|
|
|
`emacs-startup-hook'
|
|
|
|
`doom-post-init-hook' (at end of `emacs-startup-hook')
|
|
|
|
|
|
|
|
Module load order is determined by your `doom!' block. See `doom-modules-dirs'
|
|
|
|
for a list of all recognized module trees. Order defines precedence (from most
|
|
|
|
to least)."
|
2018-06-09 20:13:20 +02:00
|
|
|
(let ((doom-modules
|
|
|
|
(make-hash-table :test #'equal
|
|
|
|
:size (if modules (length modules) 100)
|
|
|
|
:rehash-threshold 1.0))
|
|
|
|
category
|
2018-05-27 12:44:22 +02:00
|
|
|
init-forms config-forms)
|
2018-06-09 20:13:20 +02:00
|
|
|
(dolist (m modules)
|
|
|
|
(cond ((keywordp m) (setq category m))
|
|
|
|
((not category) (error "No module category specified for %s" m))
|
|
|
|
((let* ((module (if (listp m) (car m) m))
|
|
|
|
(flags (if (listp m) (cdr m)))
|
|
|
|
(path (doom-module-locate-path category module)))
|
|
|
|
(if (not path)
|
|
|
|
(message "Couldn't find the %s %s module" category module)
|
|
|
|
(let ((key (cons category module)))
|
|
|
|
(doom-module-set category module :flags flags :path path)
|
|
|
|
(push `(let ((doom--current-module ',key))
|
|
|
|
(load! "init" ,path t))
|
|
|
|
init-forms)
|
|
|
|
(push `(let ((doom--current-module ',key))
|
|
|
|
(load! "config" ,path t))
|
|
|
|
config-forms)))))))
|
2018-03-12 13:07:17 -04:00
|
|
|
`(let (file-name-handler-alist)
|
|
|
|
(setq doom-modules ',doom-modules)
|
2018-05-15 11:23:44 +02:00
|
|
|
,@(nreverse init-forms)
|
2018-05-19 23:58:14 +02:00
|
|
|
(run-hooks 'doom-init-hook)
|
2018-05-14 18:40:35 +02:00
|
|
|
(unless noninteractive
|
|
|
|
(let ((doom--stage 'config))
|
|
|
|
,@(nreverse config-forms)
|
|
|
|
(when doom-private-dir
|
2018-05-24 19:00:41 +02:00
|
|
|
(let ((load-prefer-newer t))
|
|
|
|
(load ,(expand-file-name "config" doom-private-dir)
|
|
|
|
t (not doom-debug-mode)))))))))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-06-05 16:45:42 +02:00
|
|
|
(defmacro def-package! (name &rest plist)
|
2017-12-10 14:50:43 -05:00
|
|
|
"A thin wrapper around `use-package'."
|
|
|
|
;; Ignore package if NAME is in `doom-disabled-packages'
|
2017-06-05 16:45:42 +02:00
|
|
|
(when (and (memq name doom-disabled-packages)
|
|
|
|
(not (memq :disabled plist)))
|
2017-12-28 19:15:50 -05:00
|
|
|
(setq plist `(:disabled t ,@plist)))
|
2017-12-10 14:50:43 -05:00
|
|
|
;; If byte-compiling, ignore this package if it doesn't meet the condition.
|
|
|
|
;; This avoids false-positive load errors.
|
|
|
|
(unless (and (bound-and-true-p byte-compile-current-file)
|
2018-05-14 18:40:35 +02:00
|
|
|
(or (and (plist-member plist :if) (not (eval (plist-get plist :if) t)))
|
|
|
|
(and (plist-member plist :when) (not (eval (plist-get plist :when) t)))
|
|
|
|
(and (plist-member plist :unless) (eval (plist-get plist :unless) t))))
|
2018-05-20 20:07:15 +02:00
|
|
|
`(use-package ,name ,@plist)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2017-06-05 14:22:30 +02:00
|
|
|
(defmacro def-package-hook! (package when &rest body)
|
2017-07-02 16:47:02 +02:00
|
|
|
"Reconfigures a package's `def-package!' block.
|
2017-06-05 14:22:30 +02:00
|
|
|
|
2018-03-12 13:12:31 -04:00
|
|
|
Only use this macro in a module's init.el file.
|
|
|
|
|
2017-07-02 16:47:02 +02:00
|
|
|
Under the hood, this uses use-package's `use-package-inject-hooks'.
|
|
|
|
|
|
|
|
PACKAGE is a symbol; the package's name.
|
2017-06-05 16:45:42 +02:00
|
|
|
WHEN should be one of the following:
|
2018-04-03 15:00:52 -04:00
|
|
|
:pre-init :post-init :pre-config :post-config
|
2017-06-05 14:22:30 +02:00
|
|
|
|
2017-07-02 16:47:02 +02:00
|
|
|
WARNING: If :pre-init or :pre-config hooks return nil, the original
|
|
|
|
`def-package!''s :init/:config block (respectively) is overwritten, so remember
|
|
|
|
to have them return non-nil (or exploit that to overwrite Doom's config)."
|
2017-06-05 14:22:30 +02:00
|
|
|
(declare (indent defun))
|
2018-05-14 18:40:35 +02:00
|
|
|
(doom--assert-stage-p 'init #'package!)
|
2017-06-05 16:45:42 +02:00
|
|
|
(cond ((eq when :disable)
|
2018-03-26 02:57:34 -04:00
|
|
|
(message "Using :disable with `def-package-hook!' is deprecated. Use :disable in `package!' instead.")
|
|
|
|
(ignore (push package doom-disabled-packages)))
|
2017-06-05 16:45:42 +02:00
|
|
|
((memq when '(:pre-init :post-init :pre-config :post-config))
|
|
|
|
`(progn
|
|
|
|
(setq use-package-inject-hooks t)
|
|
|
|
(add-hook!
|
|
|
|
',(intern (format "use-package--%s--%s-hook"
|
|
|
|
package
|
|
|
|
(substring (symbol-name when) 1)))
|
|
|
|
,@body)))
|
2018-05-20 15:23:37 +02:00
|
|
|
((error "'%s' isn't a valid hook for def-package-hook!" when))))
|
2017-06-05 14:22:30 +02:00
|
|
|
|
2018-05-27 12:44:22 +02:00
|
|
|
(defmacro load! (filename &optional path noerror)
|
2017-07-02 16:38:28 +02:00
|
|
|
"Load a file relative to the current executing file (`load-file-name').
|
|
|
|
|
2018-05-28 12:30:20 +02:00
|
|
|
FILENAME is either a file path string or a form that should evaluate to such a
|
|
|
|
string at run time. PATH is where to look for the file (a string representing a
|
|
|
|
directory path). If omitted, the lookup is relative to either `load-file-name',
|
|
|
|
`byte-compile-current-file' or `buffer-file-name' (checked in that order).
|
2017-07-02 16:38:28 +02:00
|
|
|
|
|
|
|
If NOERROR is non-nil, don't throw an error if the file doesn't exist."
|
2018-05-27 12:44:22 +02:00
|
|
|
(unless path
|
|
|
|
(setq path (or (and (bound-and-true-p byte-compile-current-file)
|
|
|
|
(file-name-directory byte-compile-current-file))
|
|
|
|
(and load-file-name (file-name-directory load-file-name))
|
2018-06-05 11:22:20 +02:00
|
|
|
(and buffer-file-name (file-name-directory buffer-file-name))
|
2018-05-27 12:44:22 +02:00
|
|
|
(error "Could not detect path to look for '%s' in" filename))))
|
|
|
|
`(load ,(if path
|
|
|
|
`(expand-file-name ,filename ,path)
|
|
|
|
filename)
|
|
|
|
,noerror ,(not doom-debug-mode)))
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-06-04 00:06:01 +02:00
|
|
|
(defmacro require! (category module &rest plist)
|
|
|
|
"Loads the module specified by CATEGORY (a keyword) and MODULE (a symbol)."
|
2018-06-05 11:22:20 +02:00
|
|
|
(let ((doom-modules (copy-hash-table doom-modules)))
|
2018-06-04 00:06:01 +02:00
|
|
|
(apply #'doom-module-set category module
|
|
|
|
(mapcar #'eval plist))
|
|
|
|
(let ((module-path (doom-module-locate-path category module)))
|
|
|
|
(if (directory-name-p module-path)
|
|
|
|
`(condition-case-unless-debug ex
|
|
|
|
(let ((doom--current-module ',(cons category module)))
|
|
|
|
(load! "init" ,module-path :noerror)
|
|
|
|
(let ((doom--stage 'config))
|
|
|
|
(load! "config" ,module-path :noerror)))
|
|
|
|
('error
|
|
|
|
(lwarn 'doom-modules :error
|
|
|
|
"%s in '%s %s' -> %s"
|
|
|
|
(car ex) ,category ',module
|
|
|
|
(error-message-string ex))))
|
|
|
|
(warn 'doom-modules :warning "Couldn't find module '%s %s'"
|
|
|
|
category module)))))
|
2017-07-29 00:11:07 +02:00
|
|
|
|
|
|
|
(defmacro featurep! (module &optional submodule flag)
|
2018-01-30 21:26:02 -05:00
|
|
|
"Returns t if MODULE SUBMODULE is enabled. If FLAG is provided, returns t if
|
|
|
|
MODULE SUBMODULE has FLAG enabled.
|
|
|
|
|
2018-05-14 20:55:55 +02:00
|
|
|
(featurep! :config default)
|
2018-01-30 21:26:02 -05:00
|
|
|
|
|
|
|
Module FLAGs are set in your config's `doom!' block, typically in
|
|
|
|
~/.emacs.d/init.el. Like so:
|
|
|
|
|
2018-05-14 20:55:55 +02:00
|
|
|
:config (default +flag1 -flag2)
|
2018-01-30 21:26:02 -05:00
|
|
|
|
|
|
|
When this macro is used from inside a module, MODULE and SUBMODULE can be
|
|
|
|
omitted. eg. (featurep! +flag1)"
|
2017-07-29 00:11:07 +02:00
|
|
|
(unless submodule
|
2018-05-20 00:57:57 +02:00
|
|
|
(let* ((path (or (bound-and-true-p byte-compile-current-file)
|
|
|
|
load-file-name))
|
2017-09-15 13:47:05 +02:00
|
|
|
(module-pair (doom-module-from-path path)))
|
|
|
|
(unless module-pair
|
2018-05-14 20:55:55 +02:00
|
|
|
(error "featurep! couldn't detect what module its in! (in %s)" path))
|
2017-09-15 13:47:05 +02:00
|
|
|
(setq flag module
|
|
|
|
module (car module-pair)
|
|
|
|
submodule (cdr module-pair))))
|
2017-07-29 00:11:07 +02:00
|
|
|
(if flag
|
2018-03-02 17:45:15 -05:00
|
|
|
(and (memq flag (doom-module-get module submodule :flags)) t)
|
|
|
|
(doom-module-p module submodule)))
|
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-03-26 02:57:34 -04:00
|
|
|
(cond ((memq name doom-disabled-packages) nil)
|
|
|
|
((let ((disable (plist-get plist :disable)))
|
|
|
|
(and disable (eval disable)))
|
|
|
|
(push name doom-disabled-packages)
|
|
|
|
(setq doom-packages (map-delete doom-packages name))
|
|
|
|
nil)
|
|
|
|
((let* ((old-plist (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)))))
|
|
|
|
(when pkg-recipe
|
|
|
|
(when (= 0 (% (length pkg-recipe) 2))
|
|
|
|
(plist-put plist :recipe (cons name pkg-recipe)))
|
|
|
|
(when pkg-pin
|
|
|
|
(plist-put plist :pin nil)))
|
2018-03-26 16:32:05 -04:00
|
|
|
(dolist (prop '(:ignore :freeze))
|
|
|
|
(let ((val (plist-get plist prop)))
|
|
|
|
(when val
|
|
|
|
(plist-put plist prop (eval val)))))
|
2018-03-26 02:57:34 -04:00
|
|
|
`(progn
|
|
|
|
,(when (and pkg-pin t)
|
|
|
|
`(map-put package-pinned-packages ',name ,pkg-pin))
|
2018-05-15 23:11:48 +02:00
|
|
|
(map-put doom-packages ',name ',plist)
|
|
|
|
t)))))
|
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-02-11 00:46:42 -05:00
|
|
|
|
|
|
|
;;
|
2018-03-14 18:25:22 -04:00
|
|
|
;; Make package.el cooperate with Doom
|
2017-02-11 00:46:42 -05:00
|
|
|
;;
|
|
|
|
|
2017-03-27 13:05:30 -04:00
|
|
|
;; Updates QUELPA after deleting a package
|
2017-04-17 02:17:10 -04:00
|
|
|
(advice-add #'package-delete :after #'doom*package-delete)
|
2017-02-11 00:46:42 -05:00
|
|
|
|
2018-03-14 18:25:22 -04:00
|
|
|
;; Replace with Doom variants
|
2017-11-13 17:58:16 +01:00
|
|
|
(advice-add #'package-autoremove :override #'doom//packages-autoremove)
|
2018-03-14 18:25:22 -04:00
|
|
|
(advice-add #'package-install-selected-packages :override #'doom//packages-install)
|
2017-05-19 02:57:39 +02:00
|
|
|
|
2018-05-13 17:27:38 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;; Cross-module configuration
|
|
|
|
;;
|
|
|
|
|
2018-05-20 15:23:37 +02:00
|
|
|
;; I needed a way to reliably cross-configure modules without littering my
|
|
|
|
;; modules with `after!' blocks or testing whether they were enabled, so I wrote
|
|
|
|
;; `set!'. If a setting doesn't exist at runtime, the `set!' call is ignored and
|
|
|
|
;; its arguments are left unevaluated (and entirely omitted when byte-compiled).
|
|
|
|
|
2018-05-13 17:27:38 +02:00
|
|
|
(defmacro def-setting! (keyword arglist &optional docstring &rest forms)
|
|
|
|
"Define a setting. Like `defmacro', this should return a form to be executed
|
|
|
|
when called with `set!'. FORMS are not evaluated until `set!' calls it.
|
|
|
|
|
|
|
|
See `doom/describe-setting' for a list of available settings.
|
|
|
|
|
|
|
|
Do not use this for configuring Doom core."
|
|
|
|
(declare (indent defun) (doc-string 3))
|
2018-06-02 16:23:50 +02:00
|
|
|
(or (keywordp keyword)
|
|
|
|
(signal 'wrong-type-argument (list 'keywordp keyword)))
|
|
|
|
`(fset ',(intern (format "doom--set%s" keyword))
|
|
|
|
(lambda ,arglist ,docstring ,@forms)))
|
2018-05-13 17:27:38 +02:00
|
|
|
|
|
|
|
(defmacro set! (keyword &rest values)
|
|
|
|
"Set an option defined by `def-setting!'. Skip if doesn't exist. See
|
|
|
|
`doom/describe-setting' for a list of available settings.
|
|
|
|
|
|
|
|
VALUES doesn't get evaluated if the KEYWORD setting doesn't exist."
|
|
|
|
(declare (indent defun))
|
2018-06-02 16:23:50 +02:00
|
|
|
(let ((fn (intern-soft (format "doom--set%s" keyword))))
|
|
|
|
(if (and fn (fboundp fn))
|
|
|
|
(apply fn values)
|
|
|
|
(when doom-debug-mode
|
|
|
|
(message "No setting found for %s" keyword)
|
|
|
|
nil))))
|
2018-05-13 17:27:38 +02:00
|
|
|
|
2017-01-16 23:15:48 -05:00
|
|
|
(provide 'core-packages)
|
|
|
|
;;; core-packages.el ends here
|