2018-06-11 23:18:15 +02:00
|
|
|
;;; core-modules.el --- module & package management system -*- lexical-binding: t; -*-
|
|
|
|
|
|
|
|
(defvar doom-init-modules-p nil
|
|
|
|
"Non-nil if `doom-initialize-modules' has run.")
|
|
|
|
|
|
|
|
(defvar doom-modules ()
|
|
|
|
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
|
|
|
|
|
|
|
|
(defvar doom-modules-dirs
|
2018-06-23 22:22:42 +02:00
|
|
|
(list (expand-file-name "modules/" doom-private-dir)
|
|
|
|
doom-modules-dir)
|
2018-06-11 23:18:15 +02:00
|
|
|
"A list of module root directories. Order determines priority.")
|
|
|
|
|
2018-06-15 13:10:00 +02:00
|
|
|
(defconst doom-obsolete-modules
|
2019-02-22 00:20:29 -05:00
|
|
|
'((:feature (version-control (:emacs vc) (:ui vc-gutter))
|
|
|
|
(spellcheck (:tools flyspell))
|
|
|
|
(syntax-checker (:tools flycheck)))
|
2019-02-18 00:01:58 -05:00
|
|
|
(:tools (rotate-text (:editor rotate-text)))
|
|
|
|
(:emacs (electric-indent (:emacs electric))
|
2019-03-01 15:12:27 -05:00
|
|
|
(hideshow (:editor fold)))
|
|
|
|
(:ui (doom-modeline (:ui modeline))))
|
2018-06-15 13:05:40 +02:00
|
|
|
"An alist of deprecated modules, mapping deprecated modules to an optional new
|
|
|
|
location (which will create an alias). Each CAR and CDR is a (CATEGORY .
|
2018-06-21 22:17:15 +02:00
|
|
|
MODULES). E.g.
|
2018-06-15 13:05:40 +02:00
|
|
|
|
2018-06-21 22:17:15 +02:00
|
|
|
((:emacs . electric-indent) . (:emacs electric))
|
|
|
|
((:feature . version-control) (:emacs vc) (:ui . vc-gutter))
|
2018-06-15 13:05:40 +02:00
|
|
|
|
|
|
|
A warning will be put out if these deprecated modules are used.")
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
(defvar doom--current-module nil)
|
2018-07-29 02:46:18 +02:00
|
|
|
(defvar doom--current-flags nil)
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-03-07 19:39:45 -05:00
|
|
|
;;; Custom hooks
|
|
|
|
|
|
|
|
(defvar doom-before-init-modules-hook nil
|
|
|
|
"A list of hooks to run before Doom's modules' config.el files are loaded, but
|
|
|
|
after their init.el files are loaded.")
|
|
|
|
|
|
|
|
(defvar doom-init-modules-hook nil
|
|
|
|
"A list of hooks to run after Doom's modules' config.el files have loaded, but
|
|
|
|
before the user's private module.")
|
|
|
|
|
|
|
|
(defvaralias 'doom-after-init-modules-hook 'after-init-hook)
|
|
|
|
|
|
|
|
(define-obsolete-variable-alias 'doom-post-init-hook 'doom-init-modules-hook "2.1.0")
|
|
|
|
(define-obsolete-variable-alias 'doom-init-hook 'doom-before-init-modules-hook "2.1.0")
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Bootstrap API
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(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))
|
|
|
|
(setq doom-init-modules-p t)
|
2018-08-08 21:45:07 +02:00
|
|
|
|
|
|
|
(load! "init" doom-private-dir t)
|
2018-08-12 02:46:06 +02:00
|
|
|
(unless doom-modules
|
2018-09-11 20:09:31 -04:00
|
|
|
(setq doom-modules (make-hash-table :test 'equal)))
|
2018-08-12 02:46:06 +02:00
|
|
|
|
2018-08-08 21:45:07 +02:00
|
|
|
(maphash (lambda (key plist)
|
|
|
|
(let ((doom--current-module key)
|
|
|
|
(doom--current-flags (plist-get plist :flags)))
|
|
|
|
(load! "init" (plist-get plist :path) t)))
|
|
|
|
doom-modules)
|
2019-03-04 20:35:47 -05:00
|
|
|
(run-hook-wrapped 'doom-before-init-modules-hook #'doom-try-run-hook)
|
2018-08-08 21:45:07 +02:00
|
|
|
(unless noninteractive
|
|
|
|
(maphash (lambda (key plist)
|
|
|
|
(let ((doom--current-module key)
|
|
|
|
(doom--current-flags (plist-get plist :flags)))
|
|
|
|
(load! "config" (plist-get plist :path) t)))
|
|
|
|
doom-modules)
|
2019-03-04 20:35:47 -05:00
|
|
|
(run-hook-wrapped 'doom-init-modules-hook #'doom-try-run-hook)
|
2018-08-08 21:45:07 +02:00
|
|
|
(load! "config" doom-private-dir t)
|
2018-08-25 17:26:57 +02:00
|
|
|
(unless custom-file
|
|
|
|
(setq custom-file (concat doom-local-dir "custom.el")))
|
|
|
|
(when (stringp custom-file)
|
2019-03-04 20:35:47 -05:00
|
|
|
(load custom-file t t t)))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-03-07 23:21:58 -05:00
|
|
|
;;; Module API
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(defun doom-module-p (category module)
|
|
|
|
"Returns t if CATEGORY MODULE is enabled (ie. present in `doom-modules')."
|
2018-06-24 19:54:50 +02:00
|
|
|
(declare (pure t) (side-effect-free t))
|
2018-06-11 23:18:15 +02:00
|
|
|
(and (hash-table-p doom-modules)
|
|
|
|
(gethash (cons category module) doom-modules)
|
|
|
|
t))
|
|
|
|
|
|
|
|
(defun doom-module-get (category module &optional property)
|
|
|
|
"Returns the plist for CATEGORY MODULE. Gets PROPERTY, specifically, if set."
|
2018-06-24 19:54:50 +02:00
|
|
|
(declare (pure t) (side-effect-free t))
|
2018-06-11 23:18:15 +02:00
|
|
|
(when-let* ((plist (gethash (cons category module) doom-modules)))
|
|
|
|
(if property
|
|
|
|
(plist-get plist property)
|
|
|
|
plist)))
|
|
|
|
|
2018-09-25 23:52:20 -04:00
|
|
|
(defun doom-module-put (category module &rest plist)
|
2018-06-11 23:18:15 +02:00
|
|
|
"Set a PROPERTY for CATEGORY MODULE to VALUE. PLIST should be additional pairs
|
2018-09-25 23:52:20 -04:00
|
|
|
of PROPERTY and VALUEs.
|
|
|
|
|
|
|
|
\(fn CATEGORY MODULE PROPERTY VALUE &rest [PROPERTY VALUE [...]])"
|
|
|
|
(if-let* ((old-plist (doom-module-get category module)))
|
|
|
|
(progn
|
|
|
|
(when plist
|
|
|
|
(when (cl-oddp (length plist))
|
|
|
|
(signal 'wrong-number-of-arguments (list (length plist))))
|
|
|
|
(while plist
|
|
|
|
(plist-put old-plist (pop plist) (pop plist))))
|
|
|
|
(puthash (cons category module) old-plist doom-modules))
|
2018-06-11 23:18:15 +02:00
|
|
|
(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
|
|
|
|
following properties:
|
|
|
|
|
|
|
|
:flags [SYMBOL LIST] list of enabled category flags
|
|
|
|
:path [STRING] path to category root directory
|
|
|
|
|
|
|
|
Example:
|
|
|
|
(doom-module-set :lang 'haskell :flags '(+intero))"
|
2018-06-19 20:55:44 +02:00
|
|
|
(puthash (cons category module)
|
|
|
|
plist
|
|
|
|
doom-modules))
|
2018-06-11 23:18:15 +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'."
|
2018-06-24 19:54:50 +02:00
|
|
|
(let ((path (doom-module-get category module :path))
|
|
|
|
file-name-handler-alist)
|
2018-06-11 23:18:15 +02:00
|
|
|
(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)
|
2018-09-25 23:52:20 -04:00
|
|
|
(setq category (doom-keyword-name category)))
|
2018-06-11 23:18:15 +02:00
|
|
|
(when (and module (symbolp module))
|
|
|
|
(setq module (symbol-name module)))
|
2018-06-24 19:54:50 +02:00
|
|
|
(cl-loop with file-name-handler-alist = nil
|
|
|
|
for default-directory in doom-modules-dirs
|
2018-06-11 23:18:15 +02:00
|
|
|
for path = (concat category "/" module "/" file)
|
|
|
|
if (file-exists-p path)
|
|
|
|
return (expand-file-name path)))
|
|
|
|
|
|
|
|
(defun doom-module-from-path (&optional path)
|
|
|
|
"Returns a cons cell (CATEGORY . MODULE) derived from PATH (a file path)."
|
|
|
|
(or doom--current-module
|
2018-09-25 23:52:20 -04:00
|
|
|
(let* (file-name-handler-alist
|
|
|
|
(path (or path (FILE!))))
|
2018-06-11 23:18:15 +02:00
|
|
|
(save-match-data
|
|
|
|
(setq path (file-truename path))
|
2018-06-15 16:04:27 +02:00
|
|
|
(when (string-match "/modules/\\([^/]+\\)/\\([^/]+\\)\\(?:/.*\\)?$" path)
|
2018-06-12 20:50:41 +02:00
|
|
|
(when-let* ((category (match-string 1 path))
|
|
|
|
(module (match-string 2 path)))
|
|
|
|
(cons (doom-keyword-intern category)
|
|
|
|
(intern module))))))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2018-06-12 15:03:45 +02:00
|
|
|
(defun doom-module-load-path (&optional all-p)
|
|
|
|
"Return a list of absolute file paths to activated modules. If ALL-P is
|
|
|
|
non-nil, return paths of possible modules, activated or otherwise."
|
2018-06-24 19:54:50 +02:00
|
|
|
(declare (pure t) (side-effect-free t))
|
2018-06-12 15:03:45 +02:00
|
|
|
(append (if all-p
|
|
|
|
(doom-files-in doom-modules-dirs
|
|
|
|
:type 'dirs
|
|
|
|
:mindepth 1
|
|
|
|
:depth 1
|
|
|
|
:full t)
|
|
|
|
(cl-loop for plist being the hash-values of (doom-modules)
|
|
|
|
collect (plist-get plist :path)))
|
2018-06-11 23:18:15 +02:00
|
|
|
(list doom-private-dir)))
|
|
|
|
|
|
|
|
(defun doom-modules (&optional refresh-p)
|
|
|
|
"Minimally initialize `doom-modules' (a hash table) and return it."
|
|
|
|
(or (unless refresh-p doom-modules)
|
|
|
|
(let ((noninteractive t)
|
2018-09-25 23:52:20 -04:00
|
|
|
doom-modules
|
2018-06-11 23:18:15 +02:00
|
|
|
doom-init-modules-p)
|
2018-08-08 21:45:07 +02:00
|
|
|
(load! "init" doom-private-dir t)
|
2018-09-25 23:52:20 -04:00
|
|
|
(or doom-modules
|
|
|
|
(make-hash-table :test 'equal
|
|
|
|
:size 20
|
|
|
|
:rehash-threshold 1.0)))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-03-07 23:21:58 -05:00
|
|
|
;;; Use-package modifications
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(autoload 'use-package "use-package-core" nil nil t)
|
|
|
|
|
2018-06-20 12:48:59 +02:00
|
|
|
(setq use-package-compute-statistics doom-debug-mode
|
|
|
|
use-package-verbose doom-debug-mode
|
|
|
|
use-package-minimum-reported-time (if doom-debug-mode 0 0.1)
|
|
|
|
use-package-expand-minimally (not noninteractive))
|
|
|
|
|
2018-12-23 00:25:51 -05:00
|
|
|
;; Adds two new keywords to `use-package' (and consequently, `def-package!'),
|
|
|
|
;; they are:
|
2018-06-18 14:52:24 +02:00
|
|
|
;;
|
2018-12-23 00:25:51 -05:00
|
|
|
;; :after-call SYMBOL|LIST
|
|
|
|
;; Takes a symbol or list of symbols representing functions or hook variables.
|
|
|
|
;; The first time any of these functions or hooks are executed, the package is
|
|
|
|
;; loaded. e.g.
|
2018-06-18 14:52:24 +02:00
|
|
|
;;
|
2018-12-23 00:25:51 -05:00
|
|
|
;; (def-package! projectile
|
|
|
|
;; :after-call (pre-command-hook after-find-file dired-before-readin-hook)
|
|
|
|
;; ...)
|
|
|
|
;;
|
|
|
|
;; :defer-incrementally SYMBOL|LIST|t
|
|
|
|
;; Takes a symbol or list of symbols representing packages that will be loaded
|
|
|
|
;; incrementally at startup before this one. This is helpful for large
|
|
|
|
;; packages like magit or org, which load a lot of dependencies on first load.
|
|
|
|
;; This lets you load them piece-meal, one at a time, during idle periods, so
|
|
|
|
;; that when you finally do need the package, it'll loads much quicker. e.g.
|
|
|
|
;;
|
|
|
|
;; (def-package! magit
|
|
|
|
;; ;; You do not need to include magit in this list!
|
|
|
|
;; :defer-incrementally (dash f s with-editor git-commit package)
|
|
|
|
;; ...)
|
|
|
|
;;
|
|
|
|
;; (def-package! x
|
|
|
|
;; ;; This is equivalent to :defer-incrementally (x)
|
|
|
|
;; :defer-incrementally t
|
|
|
|
;; ...)
|
2018-06-23 16:48:58 +02:00
|
|
|
(defvar doom--deferred-packages-alist '(t))
|
2018-06-11 23:18:15 +02:00
|
|
|
(after! use-package-core
|
2019-03-09 14:14:40 -05:00
|
|
|
;; :ensure and :pin don't work well with Doom, so we forcibly remove them.
|
|
|
|
(dolist (keyword '(:ensure :pin))
|
|
|
|
(setq use-package-keywords (delq keyword use-package-keywords)))
|
2018-09-20 10:41:19 -04:00
|
|
|
|
2019-03-09 14:14:40 -05:00
|
|
|
;; Insert new deferring keywords
|
|
|
|
(dolist (keyword '(:defer-incrementally :after-call))
|
|
|
|
(add-to-list 'use-package-deferring-keywords keyword nil #'eq)
|
|
|
|
(setq use-package-keywords
|
|
|
|
(use-package-list-insert keyword use-package-keywords :after)))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2018-09-20 10:41:19 -04:00
|
|
|
(defalias 'use-package-normalize/:defer-incrementally 'use-package-normalize-symlist)
|
|
|
|
(defun use-package-handler/:defer-incrementally (name _keyword targets rest state)
|
|
|
|
(use-package-concat
|
|
|
|
`((doom-load-packages-incrementally
|
2018-09-21 22:43:52 -04:00
|
|
|
',(if (equal targets '(t))
|
|
|
|
(list name)
|
2018-12-23 00:25:51 -05:00
|
|
|
(append targets (list name)))))
|
2018-09-20 10:41:19 -04:00
|
|
|
(use-package-process-keywords name rest state)))
|
|
|
|
|
2018-06-16 00:36:27 +02:00
|
|
|
(defalias 'use-package-normalize/:after-call 'use-package-normalize-symlist)
|
2018-06-14 11:53:52 +02:00
|
|
|
(defun use-package-handler/:after-call (name _keyword hooks rest state)
|
2018-06-23 19:29:29 +02:00
|
|
|
(if (plist-get state :demand)
|
|
|
|
(use-package-process-keywords name rest state)
|
|
|
|
(let ((fn (intern (format "doom|transient-hook--load-%s" name))))
|
2018-06-11 23:18:15 +02:00
|
|
|
(use-package-concat
|
|
|
|
`((fset ',fn
|
|
|
|
(lambda (&rest _)
|
2019-03-04 18:38:25 -05:00
|
|
|
(doom-log "Loading deferred package %s from %s" ',name ',fn)
|
2018-06-19 20:54:09 +02:00
|
|
|
(condition-case e (require ',name)
|
|
|
|
((debug error)
|
|
|
|
(message "Failed to load deferred package %s: %s" ',name e)))
|
2018-06-14 11:53:52 +02:00
|
|
|
(dolist (hook (cdr (assq ',name doom--deferred-packages-alist)))
|
2018-06-11 23:18:15 +02:00
|
|
|
(if (functionp hook)
|
|
|
|
(advice-remove hook #',fn)
|
|
|
|
(remove-hook hook #',fn)))
|
2019-03-09 14:14:40 -05:00
|
|
|
(setq doom--deferred-packages-alist
|
|
|
|
(delq (assq ',name doom--deferred-packages-alist)
|
|
|
|
doom--deferred-packages-alist))
|
2018-06-11 23:18:15 +02:00
|
|
|
(fmakunbound ',fn))))
|
2018-06-23 16:48:58 +02:00
|
|
|
(let (forms)
|
|
|
|
(dolist (hook hooks forms)
|
|
|
|
(push (if (functionp hook)
|
|
|
|
`(advice-add #',hook :before #',fn)
|
|
|
|
`(add-hook ',hook #',fn))
|
|
|
|
forms)))
|
|
|
|
`((unless (assq ',name doom--deferred-packages-alist)
|
|
|
|
(push '(,name) doom--deferred-packages-alist))
|
|
|
|
(nconc (assq ',name doom--deferred-packages-alist)
|
|
|
|
'(,@hooks)))
|
2018-06-11 23:18:15 +02:00
|
|
|
(use-package-process-keywords name rest state))))))
|
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-03-07 23:21:58 -05:00
|
|
|
;;; Module config macros
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(defmacro doom! (&rest modules)
|
|
|
|
"Bootstraps DOOM Emacs and its modules.
|
|
|
|
|
|
|
|
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
|
2018-12-05 22:11:14 -05:00
|
|
|
$DOOMDIR/init.el
|
|
|
|
{$DOOMDIR,~/.emacs.d}/modules/*/*/init.el
|
2019-03-04 20:35:47 -05:00
|
|
|
`doom-before-init-modules-hook'
|
2018-12-05 22:11:14 -05:00
|
|
|
{$DOOMDIR,~/.emacs.d}/modules/*/*/config.el
|
2019-03-04 20:35:47 -05:00
|
|
|
`doom-init-modules-hook'
|
2018-12-05 22:11:14 -05:00
|
|
|
$DOOMDIR/config.el
|
2019-03-07 19:39:45 -05:00
|
|
|
`doom-after-init-modules-hook'
|
2018-06-11 23:18:15 +02:00
|
|
|
`after-init-hook'
|
|
|
|
`emacs-startup-hook'
|
2019-03-04 20:35:47 -05:00
|
|
|
`window-setup-hook'
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
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-08-08 21:45:07 +02:00
|
|
|
(unless doom-modules
|
|
|
|
(setq doom-modules
|
2018-09-11 20:09:31 -04:00
|
|
|
(make-hash-table :test 'equal
|
2018-09-25 23:52:20 -04:00
|
|
|
:size (if modules (length modules) 150)
|
2018-08-08 21:45:07 +02:00
|
|
|
:rehash-threshold 1.0)))
|
|
|
|
(let (category m)
|
2018-06-21 22:17:15 +02:00
|
|
|
(while modules
|
2018-08-08 21:45:07 +02:00
|
|
|
(setq m (pop modules))
|
|
|
|
(cond ((keywordp m) (setq category m))
|
|
|
|
((not category) (error "No module category specified for %s" m))
|
|
|
|
((catch 'doom-modules
|
|
|
|
(let* ((module (if (listp m) (car m) m))
|
|
|
|
(flags (if (listp m) (cdr m))))
|
2018-09-25 23:52:20 -04:00
|
|
|
(when-let* ((obsolete (assq category doom-obsolete-modules))
|
|
|
|
(new (assq module obsolete)))
|
2018-08-08 21:45:07 +02:00
|
|
|
(let ((newkeys (cdr new)))
|
|
|
|
(if (null newkeys)
|
|
|
|
(message "Warning: the %s module is deprecated" key)
|
|
|
|
(message "Warning: the %s module is deprecated. Use %s instead."
|
|
|
|
(list category module) newkeys)
|
|
|
|
(push category modules)
|
|
|
|
(dolist (key newkeys)
|
|
|
|
(setq modules (append key modules)))
|
|
|
|
(throw 'doom-modules t))))
|
|
|
|
(if-let* ((path (doom-module-locate-path category module)))
|
|
|
|
(doom-module-set category module :flags flags :path path)
|
2018-09-25 23:52:20 -04:00
|
|
|
(message "Warning: couldn't find the %s %s module" category module))))))))
|
|
|
|
`(setq doom-modules ',doom-modules))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2018-06-16 00:36:27 +02:00
|
|
|
(defvar doom-disabled-packages)
|
2018-06-11 23:18:15 +02:00
|
|
|
(defmacro def-package! (name &rest plist)
|
2019-02-22 01:48:59 -05:00
|
|
|
"This is a thin wrapper around `use-package'. It is ignored if the NAME
|
|
|
|
package is disabled."
|
|
|
|
(unless (or (memq name doom-disabled-packages)
|
|
|
|
;; At compile-time, use-package will forcibly load its package to
|
|
|
|
;; prevent compile-time errors. However, Doom users can
|
|
|
|
;; intentionally disable packages, resulting if file-missing
|
|
|
|
;; package errors, so we preform this check at compile time:
|
|
|
|
(and (bound-and-true-p byte-compile-current-file)
|
|
|
|
(not (locate-library (symbol-name name)))))
|
2019-03-06 00:26:33 -05:00
|
|
|
`(use-package ,name ,@plist)))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(defmacro def-package-hook! (package when &rest body)
|
|
|
|
"Reconfigures a package's `def-package!' block.
|
|
|
|
|
|
|
|
Only use this macro in a module's init.el file.
|
|
|
|
|
|
|
|
Under the hood, this uses use-package's `use-package-inject-hooks'.
|
|
|
|
|
|
|
|
PACKAGE is a symbol; the package's name.
|
|
|
|
WHEN should be one of the following:
|
|
|
|
:pre-init :post-init :pre-config :post-config
|
|
|
|
|
|
|
|
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)."
|
|
|
|
(declare (indent defun))
|
|
|
|
(doom--assert-stage-p 'init #'package!)
|
|
|
|
(unless (memq when '(:pre-init :post-init :pre-config :post-config))
|
|
|
|
(error "'%s' isn't a valid hook for def-package-hook!" when))
|
|
|
|
`(progn
|
|
|
|
(setq use-package-inject-hooks t)
|
|
|
|
(add-hook!
|
|
|
|
',(intern (format "use-package--%s--%s-hook"
|
|
|
|
package
|
|
|
|
(substring (symbol-name when) 1)))
|
|
|
|
,@body)))
|
|
|
|
|
|
|
|
(defmacro require! (category module &rest plist)
|
|
|
|
"Loads the module specified by CATEGORY (a keyword) and MODULE (a symbol)."
|
2018-06-23 22:23:35 +02:00
|
|
|
`(let ((module-path (doom-module-locate-path ,category ',module)))
|
2018-09-25 23:52:20 -04:00
|
|
|
(doom-module-set
|
|
|
|
,category ',module
|
|
|
|
,@(when plist
|
|
|
|
(let ((old-plist (doom-module-get category module)))
|
|
|
|
(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)
|
|
|
|
(doom-module-locate-path category module)))))
|
|
|
|
plist))
|
2018-06-23 22:23:35 +02:00
|
|
|
(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))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2018-07-30 23:53:05 +02:00
|
|
|
(defmacro featurep! (category &optional module flag)
|
|
|
|
"Returns t if CATEGORY MODULE is enabled. If FLAG is provided, returns t if
|
|
|
|
CATEGORY MODULE has FLAG enabled.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(featurep! :config default)
|
|
|
|
|
|
|
|
Module FLAGs are set in your config's `doom!' block, typically in
|
|
|
|
~/.emacs.d/init.el. Like so:
|
|
|
|
|
|
|
|
:config (default +flag1 -flag2)
|
|
|
|
|
2018-07-30 23:53:05 +02:00
|
|
|
When this macro is used from inside a module, CATEGORY and MODULE can be
|
2018-06-11 23:18:15 +02:00
|
|
|
omitted. eg. (featurep! +flag1)"
|
2018-07-30 23:53:05 +02:00
|
|
|
(and (cond (flag (memq flag (doom-module-get category module :flags)))
|
|
|
|
(module (doom-module-p category module))
|
|
|
|
(doom--current-flags (memq category doom--current-flags))
|
2018-07-29 02:46:18 +02:00
|
|
|
((let ((module-pair
|
|
|
|
(or doom--current-module
|
|
|
|
(doom-module-from-path (FILE!)))))
|
|
|
|
(unless module-pair
|
|
|
|
(error "featurep! couldn't detect what module its in! (in %s)" (FILE!)))
|
2018-07-30 23:53:05 +02:00
|
|
|
(memq category (doom-module-get (car module-pair) (cdr module-pair) :flags)))))
|
2018-07-29 02:46:18 +02:00
|
|
|
t))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(provide 'core-modules)
|
|
|
|
;;; core-modules.el ends here
|