2022-07-30 21:49:00 +02:00
|
|
|
;;; doom-modules.el --- module & package management system -*- lexical-binding: t; -*-
|
2022-09-12 18:05:14 +02:00
|
|
|
;;; Commentary:
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Variables
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2020-05-25 21:51:35 -04:00
|
|
|
(defvar doom-modules (make-hash-table :test 'equal)
|
2018-06-11 23:18:15 +02:00
|
|
|
"A hash table of enabled modules. Set by `doom-initialize-modules'.")
|
|
|
|
|
|
|
|
(defvar doom-modules-dirs
|
2022-08-13 21:27:11 +02:00
|
|
|
(list (expand-file-name "modules/" doom-user-dir)
|
2018-06-23 22:22:42 +02:00
|
|
|
doom-modules-dir)
|
2018-06-11 23:18:15 +02:00
|
|
|
"A list of module root directories. Order determines priority.")
|
|
|
|
|
2020-05-25 03:09:46 -04:00
|
|
|
(defvar doom-module-init-file "init"
|
|
|
|
"The basename of init files for modules.
|
|
|
|
|
|
|
|
Init files are loaded early, just after Doom core, and before modules' config
|
|
|
|
files. They are always loaded, even in non-interactive sessions, and before
|
2022-09-14 14:48:21 +02:00
|
|
|
`doom-before-modules-init-hook'. Related to `doom-module-config-file'.")
|
2020-05-25 03:09:46 -04:00
|
|
|
|
|
|
|
(defvar doom-module-config-file "config"
|
|
|
|
"The basename of config files for modules.
|
|
|
|
|
|
|
|
Config files are loaded later, and almost always in interactive sessions. These
|
2022-09-14 14:48:21 +02:00
|
|
|
run before `doom-after-modules-config-hook'. Relevant to `doom-module-init-file'.")
|
2020-05-25 03:09:46 -04:00
|
|
|
|
2018-06-15 13:10:00 +02:00
|
|
|
(defconst doom-obsolete-modules
|
2020-05-25 21:51:35 -04:00
|
|
|
'((:feature (version-control (:emacs vc) (:ui vc-gutter))
|
|
|
|
(spellcheck (:checkers spell))
|
|
|
|
(syntax-checker (:checkers syntax))
|
|
|
|
(evil (:editor evil))
|
|
|
|
(snippets (:editor snippets))
|
|
|
|
(file-templates (:editor file-templates))
|
|
|
|
(workspaces (:ui workspaces))
|
|
|
|
(eval (:tools eval))
|
|
|
|
(lookup (:tools lookup))
|
|
|
|
(debugger (:tools debugger)))
|
|
|
|
(:tools (rotate-text (:editor rotate-text))
|
|
|
|
(vterm (:term vterm))
|
|
|
|
(password-store (:tools pass))
|
|
|
|
(flycheck (:checkers syntax))
|
2020-08-20 02:10:25 -04:00
|
|
|
(flyspell (:checkers spell))
|
|
|
|
(macos (:os macos)))
|
2020-05-25 21:51:35 -04:00
|
|
|
(:emacs (electric-indent (:emacs electric))
|
|
|
|
(hideshow (:editor fold))
|
|
|
|
(eshell (:term eshell))
|
|
|
|
(term (:term term)))
|
|
|
|
(:ui (doom-modeline (:ui modeline))
|
|
|
|
(fci (:ui fill-column))
|
|
|
|
(evil-goggles (:ui ophints))
|
2020-08-12 18:52:14 -04:00
|
|
|
(tabbar (:ui tabs))
|
|
|
|
(pretty-code (:ui ligatures)))
|
2020-05-25 21:51:35 -04:00
|
|
|
(:app (email (:email mu4e))
|
2020-06-05 21:01:23 +02:00
|
|
|
(notmuch (:email notmuch)))
|
2020-06-05 15:22:32 -04:00
|
|
|
(:lang (perl (:lang raku))))
|
2019-04-21 19:59:44 -04:00
|
|
|
"A tree alist that maps deprecated modules to their replacement(s).
|
2018-06-15 13:05:40 +02:00
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
Each entry is a three-level tree. For example:
|
2018-06-15 13:05:40 +02:00
|
|
|
|
2019-04-21 19:59:44 -04:00
|
|
|
(:feature (version-control (:emacs vc) (:ui vc-gutter))
|
2020-01-14 03:04:26 -05:00
|
|
|
(spellcheck (:checkers spell))
|
2019-04-21 19:59:44 -04:00
|
|
|
(syntax-checker (:tools flycheck)))
|
|
|
|
|
|
|
|
This marks :feature version-control, :feature spellcheck and :feature
|
|
|
|
syntax-checker modules obsolete. e.g. If :feature version-control is found in
|
|
|
|
your `doom!' block, a warning is emitted before replacing it with :emacs vc and
|
|
|
|
:ui vc-gutter.")
|
2018-06-15 13:05:40 +02:00
|
|
|
|
2022-06-24 21:15:31 +02:00
|
|
|
(defvar doom-inhibit-module-warnings (not noninteractive)
|
2019-07-21 15:39:45 +02:00
|
|
|
"If non-nil, don't emit deprecated or missing module warnings at startup.")
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2019-03-07 19:39:45 -05:00
|
|
|
;;; Custom hooks
|
2022-09-14 14:48:21 +02:00
|
|
|
(defcustom doom-before-modules-init-hook nil
|
|
|
|
"Hooks run before module init.el files are loaded."
|
|
|
|
:group 'doom
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
(defcustom doom-after-modules-init-hook nil
|
|
|
|
"Hooks run after module init.el files are loaded."
|
|
|
|
:group 'doom
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
(defcustom doom-before-modules-config-hook nil
|
|
|
|
"Hooks run before module config.el files are loaded."
|
|
|
|
:group 'doom
|
|
|
|
:type 'hook)
|
|
|
|
|
|
|
|
(defcustom doom-after-modules-config-hook nil
|
|
|
|
"Hooks run after module config.el files are loaded (but before the user's)."
|
|
|
|
:group 'doom
|
|
|
|
:type 'hook)
|
2019-03-07 19:39:45 -05:00
|
|
|
|
2019-07-21 15:39:45 +02:00
|
|
|
(defvar doom--current-module nil)
|
|
|
|
(defvar doom--current-flags nil)
|
2019-03-07 19:39:45 -05:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-07-07 14:07:11 +02:00
|
|
|
(defun doom-module-p (category module &optional flag)
|
2018-06-11 23:18:15 +02:00
|
|
|
"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))
|
2020-01-05 19:58:59 -05:00
|
|
|
(when-let (plist (gethash (cons category module) doom-modules))
|
|
|
|
(or (null flag)
|
|
|
|
(and (memq flag (plist-get plist :flags))
|
|
|
|
t))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(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))
|
2019-06-25 21:38:16 +02:00
|
|
|
(when-let (plist (gethash (cons category module) doom-modules))
|
2018-06-11 23:18:15 +02:00
|
|
|
(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 [...]])"
|
Backport bits of CLI rewrite
The rewrite for Doom's CLI is taking a while, so I've backported a few
important changes in order to ease the transition and fix a couple bugs
sooner.
Fixes #2802, #2737, #2386
The big highlights are:
- Fix #2802: We now update recipe repos *before* updating/installing any
new packages. No more "Could not find package X in recipe repositories".
- Fix #2737: An edge case where straight couldn't reach a pinned
commit (particularly with agda).
- Doom is now smarter about what option it recommends when straight
prompts you to make a choice.
- Introduces a new init path for Doom. The old way:
- Launch in "minimal" CLI mode in non-interactive sessions
- Launch a "full" interactive mode otherwise.
The new way
- Launch in "minimal" CLI mode *only* for bin/doom
- Launch is a simple mode for non-interactive sessions that still need
access to your interactive config (like async org export/babel).
- Launch a "full" interactive mode otherwise.
This should fix compatibility issues with plugins that use the
async.el library or spawn child Emacs processes to fake
parallelization (like org's async export and babel functionality).
- Your private init.el is now loaded more reliably when running any
bin/doom command. This gives you an opportunity to configure its
settings.
- Added doom-first-{input,buffer,file}-hook hooks, which we use to queue
deferred activation of a number of packages. Users can remove these
modes from these hooks; altogether preventing them from loading,
rather than waiting for them to load to then disable them,
e.g. (after! smartparens (smartparens-global-mode -1)) -> (remove-hook
'doom-first-buffer #'smartparens-global-mode)
Hooks added to doom-first-*-hook variables will be removed once they
run.
This should also indirectly fix #2386, by preventing interactive modes
from running in non-interactive session.
- Added `doom/bump-*` commands to make bumping modules and packages
easier, and `doom/bumpify-*` commands for converting package!
statements into user/repo@sha1hash format for bump commits.
- straight.el is now commit-pinned, like all other packages. We also
more reliably install straight.el by cloning it ourselves, rather than
relying on its bootstrap.el.
This should prevent infinite "straight has diverged from master"
prompts whenever we change branches (though, you might have to put up
with it one more after this update -- see #2937 for workaround).
All the other minor changes:
- Moved core/autoload/cli.el to core/autoload/process.el
- The package manager will log attempts to check out pinned commits
- If package state is incomplete while rebuilding packages, emit a
simpler error message instead of an obscure one!
- Added -u switch to 'doom sync' to make it run 'doom update' afterwards
- Added -p switch to 'doom sync' to make it run 'doom purge' afterwards
- Replace doom-modules function with doom-modules-list
- The `with-plist!` macro was removed, since `cl-destructuring-bind`
already serves that purpose well enough.
- core/autoload/packages.el was moved into core-packages.el
- bin/doom will no longer die if DOOMDIR or DOOMLOCALDIR don't have a
trailing slash
- Introduces doom-debug-variables; a list of variables to toggle on
doom/toggle-debug-mode.
- The sandbox has been updated to reflect the above changes, also:
1. Child instances will no longer inherit the process environment of
the host instance,
2. It will no longer produce an auto-save-list directory in ~/.emacs.d
2020-05-14 15:00:23 -04:00
|
|
|
(puthash (cons category module)
|
|
|
|
(if-let (old-plist (doom-module-get category module))
|
|
|
|
(if (null plist)
|
|
|
|
old-plist
|
|
|
|
(when (cl-oddp (length plist))
|
|
|
|
(signal 'wrong-number-of-arguments (list (length plist))))
|
|
|
|
(while plist
|
|
|
|
(plist-put old-plist (pop plist) (pop plist)))
|
|
|
|
old-plist)
|
|
|
|
plist)
|
|
|
|
doom-modules))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
(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
|
|
|
|
|
2022-09-13 00:07:27 +02:00
|
|
|
If PLIST consists of a single nil, unset and disable CATEGORY MODULE.
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
Example:
|
2021-08-03 19:20:45 +03:00
|
|
|
(doom-module-set :lang 'haskell :flags '(+lsp))"
|
2022-09-13 00:07:27 +02:00
|
|
|
(if (car plist)
|
|
|
|
(progn
|
|
|
|
;; Doom caches flags and features using symbol plists for fast lookups in
|
|
|
|
;; `modulep!'. plists lack the overhead, and are much faster for datasets this
|
|
|
|
;; small. The format of this case is (cons FEATURES FLAGS)
|
|
|
|
(put category module (cons t (plist-get plist :flags)))
|
|
|
|
;; But the hash table will always been Doom's formal storage for modules.
|
|
|
|
(puthash (cons category module) plist doom-modules))
|
|
|
|
(remhash (cons category module) doom-modules)
|
|
|
|
(cl-remf (symbol-plist category) module)))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-12 22:41:09 +02:00
|
|
|
(defun doom-module-expand-path (category module &optional file)
|
|
|
|
"Expands a path to FILE relative to CATEGORY and MODULE.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-12 22:41:09 +02:00
|
|
|
CATEGORY is a keyword. MODULE is a symbol. FILE is an optional string path.
|
|
|
|
If the category isn't enabled this returns nil. For finding disabled modules use
|
|
|
|
`doom-module-locate-path'."
|
|
|
|
(when-let (path (doom-module-get category module :path))
|
2019-07-21 15:39:45 +02:00
|
|
|
(if file
|
2022-09-12 22:41:09 +02:00
|
|
|
(file-name-concat path file)
|
2018-06-11 23:18:15 +02:00
|
|
|
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
|
2022-09-12 22:41:09 +02:00
|
|
|
returns nil, otherwise an absolute path."
|
|
|
|
(let (file-name-handler-alist)
|
|
|
|
(if-let (path (doom-module-expand-path category module file))
|
|
|
|
(if (or (null file)
|
|
|
|
(file-exists-p path))
|
|
|
|
path)
|
|
|
|
(let* ((category (doom-keyword-name category))
|
|
|
|
(module (if module (symbol-name module)))
|
|
|
|
(path (file-name-concat category module file)))
|
|
|
|
(if file
|
|
|
|
;; PERF: locate-file-internal is a little faster for finding files,
|
|
|
|
;; but its interface for finding directories is clumsy.
|
|
|
|
(locate-file-internal path doom-modules-dirs)
|
|
|
|
(cl-loop for default-directory in doom-modules-dirs
|
|
|
|
if (file-exists-p path)
|
|
|
|
return (expand-file-name path)))))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-12 20:26:43 +02:00
|
|
|
(defun doom-module-from-path (path &optional enabled-only)
|
2019-07-21 15:39:45 +02:00
|
|
|
"Returns a cons cell (CATEGORY . MODULE) derived from PATH (a file path).
|
|
|
|
If ENABLED-ONLY, return nil if the containing module isn't enabled."
|
2022-09-12 20:26:43 +02:00
|
|
|
(let* ((file-name-handler-alist nil)
|
|
|
|
(path (expand-file-name path)))
|
|
|
|
(save-match-data
|
|
|
|
(cond ((string-match "/modules/\\([^/]+\\)/\\([^/]+\\)\\(?:/.*\\)?$" path)
|
|
|
|
(when-let* ((category (doom-keyword-intern (match-string 1 path)))
|
|
|
|
(module (intern (match-string 2 path))))
|
|
|
|
(and (or (null enabled-only)
|
|
|
|
(doom-module-p category module))
|
|
|
|
(cons category module))))
|
|
|
|
((file-in-directory-p path doom-core-dir)
|
|
|
|
(cons :core nil))
|
|
|
|
((file-in-directory-p path doom-user-dir)
|
|
|
|
(cons :user nil))))))
|
2019-07-21 15:39:45 +02:00
|
|
|
|
|
|
|
(defun doom-module-load-path (&optional module-dirs)
|
|
|
|
"Return a list of file paths to activated modules.
|
|
|
|
|
|
|
|
The list is in no particular order and its file paths are absolute. If
|
|
|
|
MODULE-DIRS is non-nil, include all modules (even disabled ones) available in
|
2022-09-13 00:28:28 +02:00
|
|
|
those directories."
|
2018-06-24 19:54:50 +02:00
|
|
|
(declare (pure t) (side-effect-free t))
|
2022-09-13 00:28:28 +02:00
|
|
|
(if module-dirs
|
|
|
|
(mapcar (lambda (m) (doom-module-locate-path (car m) (cdr m)))
|
|
|
|
(delete-dups
|
|
|
|
(doom-files-in module-dirs
|
|
|
|
:map #'doom-module-from-path
|
|
|
|
:type 'dirs
|
|
|
|
:mindepth 1
|
|
|
|
:depth 1)))
|
|
|
|
(delq
|
|
|
|
nil (cl-loop for (cat . mod) in (cddr (doom-module-list))
|
|
|
|
collect (doom-module-get cat mod :path)))))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2020-05-25 21:51:35 -04:00
|
|
|
(defun doom-module-mplist-map (fn mplist)
|
|
|
|
"Apply FN to each module in MPLIST."
|
|
|
|
(let ((mplist (copy-sequence mplist))
|
|
|
|
(inhibit-message doom-inhibit-module-warnings)
|
|
|
|
obsolete
|
|
|
|
results
|
|
|
|
category m)
|
|
|
|
(while mplist
|
|
|
|
(setq m (pop mplist))
|
|
|
|
(cond ((keywordp m)
|
|
|
|
(setq category m
|
|
|
|
obsolete (assq m doom-obsolete-modules)))
|
|
|
|
((null category)
|
|
|
|
(error "No module category specified for %s" m))
|
|
|
|
((and (listp m) (keywordp (car m)))
|
|
|
|
(pcase (car m)
|
|
|
|
(:cond
|
|
|
|
(cl-loop for (cond . mods) in (cdr m)
|
|
|
|
if (eval cond t)
|
|
|
|
return (prependq! mplist mods)))
|
|
|
|
(:if (if (eval (cadr m) t)
|
|
|
|
(push (caddr m) mplist)
|
|
|
|
(prependq! mplist (cdddr m))))
|
2021-01-29 23:07:03 +01:00
|
|
|
(test (if (xor (eval (cadr m) t)
|
|
|
|
(eq test :unless))
|
2020-05-25 21:51:35 -04:00
|
|
|
(prependq! mplist (cddr m))))))
|
|
|
|
((catch 'doom-modules
|
|
|
|
(let* ((module (if (listp m) (car m) m))
|
|
|
|
(flags (if (listp m) (cdr m))))
|
|
|
|
(when-let (new (assq module obsolete))
|
|
|
|
(let ((newkeys (cdr new)))
|
|
|
|
(if (null newkeys)
|
2022-09-16 00:03:36 +02:00
|
|
|
(print! (warn "%s module was removed"))
|
2020-05-25 21:51:35 -04:00
|
|
|
(if (cdr newkeys)
|
2022-09-16 00:03:36 +02:00
|
|
|
(print! (warn "%s module was removed and split into the %s modules")
|
|
|
|
(list category module)
|
|
|
|
(mapconcat #'prin1-to-string newkeys ", "))
|
|
|
|
(print! (warn "%s module was moved to %s")
|
|
|
|
(list category module)
|
|
|
|
(car newkeys)))
|
2020-05-25 21:51:35 -04:00
|
|
|
(push category mplist)
|
|
|
|
(dolist (key newkeys)
|
|
|
|
(push (if flags
|
|
|
|
(nconc (cdr key) flags)
|
|
|
|
(cdr key))
|
|
|
|
mplist)
|
|
|
|
(push (car key) mplist))
|
|
|
|
(throw 'doom-modules t))))
|
2022-09-15 23:37:04 +02:00
|
|
|
(push (funcall fn category module :flags (if (listp m) (cdr m)))
|
|
|
|
results))))))
|
2022-06-24 21:15:31 +02:00
|
|
|
(when noninteractive
|
2020-05-25 21:51:35 -04:00
|
|
|
(setq doom-inhibit-module-warnings t))
|
|
|
|
(nreverse results)))
|
|
|
|
|
Backport bits of CLI rewrite
The rewrite for Doom's CLI is taking a while, so I've backported a few
important changes in order to ease the transition and fix a couple bugs
sooner.
Fixes #2802, #2737, #2386
The big highlights are:
- Fix #2802: We now update recipe repos *before* updating/installing any
new packages. No more "Could not find package X in recipe repositories".
- Fix #2737: An edge case where straight couldn't reach a pinned
commit (particularly with agda).
- Doom is now smarter about what option it recommends when straight
prompts you to make a choice.
- Introduces a new init path for Doom. The old way:
- Launch in "minimal" CLI mode in non-interactive sessions
- Launch a "full" interactive mode otherwise.
The new way
- Launch in "minimal" CLI mode *only* for bin/doom
- Launch is a simple mode for non-interactive sessions that still need
access to your interactive config (like async org export/babel).
- Launch a "full" interactive mode otherwise.
This should fix compatibility issues with plugins that use the
async.el library or spawn child Emacs processes to fake
parallelization (like org's async export and babel functionality).
- Your private init.el is now loaded more reliably when running any
bin/doom command. This gives you an opportunity to configure its
settings.
- Added doom-first-{input,buffer,file}-hook hooks, which we use to queue
deferred activation of a number of packages. Users can remove these
modes from these hooks; altogether preventing them from loading,
rather than waiting for them to load to then disable them,
e.g. (after! smartparens (smartparens-global-mode -1)) -> (remove-hook
'doom-first-buffer #'smartparens-global-mode)
Hooks added to doom-first-*-hook variables will be removed once they
run.
This should also indirectly fix #2386, by preventing interactive modes
from running in non-interactive session.
- Added `doom/bump-*` commands to make bumping modules and packages
easier, and `doom/bumpify-*` commands for converting package!
statements into user/repo@sha1hash format for bump commits.
- straight.el is now commit-pinned, like all other packages. We also
more reliably install straight.el by cloning it ourselves, rather than
relying on its bootstrap.el.
This should prevent infinite "straight has diverged from master"
prompts whenever we change branches (though, you might have to put up
with it one more after this update -- see #2937 for workaround).
All the other minor changes:
- Moved core/autoload/cli.el to core/autoload/process.el
- The package manager will log attempts to check out pinned commits
- If package state is incomplete while rebuilding packages, emit a
simpler error message instead of an obscure one!
- Added -u switch to 'doom sync' to make it run 'doom update' afterwards
- Added -p switch to 'doom sync' to make it run 'doom purge' afterwards
- Replace doom-modules function with doom-modules-list
- The `with-plist!` macro was removed, since `cl-destructuring-bind`
already serves that purpose well enough.
- core/autoload/packages.el was moved into core-packages.el
- bin/doom will no longer die if DOOMDIR or DOOMLOCALDIR don't have a
trailing slash
- Introduces doom-debug-variables; a list of variables to toggle on
doom/toggle-debug-mode.
- The sandbox has been updated to reflect the above changes, also:
1. Child instances will no longer inherit the process environment of
the host instance,
2. It will no longer produce an auto-save-list directory in ~/.emacs.d
2020-05-14 15:00:23 -04:00
|
|
|
(defun doom-module-list (&optional all-p)
|
2022-09-12 22:50:25 +02:00
|
|
|
"Return modules as a list of (:CATEGORY . MODULE) in their enabled order.
|
|
|
|
|
|
|
|
If ALL-P, return a list of *all* available modules instead, whether or not
|
|
|
|
they're enabled, and in lexicographical order.
|
|
|
|
|
|
|
|
If ALL-P is `real', only return *real"
|
Backport bits of CLI rewrite
The rewrite for Doom's CLI is taking a while, so I've backported a few
important changes in order to ease the transition and fix a couple bugs
sooner.
Fixes #2802, #2737, #2386
The big highlights are:
- Fix #2802: We now update recipe repos *before* updating/installing any
new packages. No more "Could not find package X in recipe repositories".
- Fix #2737: An edge case where straight couldn't reach a pinned
commit (particularly with agda).
- Doom is now smarter about what option it recommends when straight
prompts you to make a choice.
- Introduces a new init path for Doom. The old way:
- Launch in "minimal" CLI mode in non-interactive sessions
- Launch a "full" interactive mode otherwise.
The new way
- Launch in "minimal" CLI mode *only* for bin/doom
- Launch is a simple mode for non-interactive sessions that still need
access to your interactive config (like async org export/babel).
- Launch a "full" interactive mode otherwise.
This should fix compatibility issues with plugins that use the
async.el library or spawn child Emacs processes to fake
parallelization (like org's async export and babel functionality).
- Your private init.el is now loaded more reliably when running any
bin/doom command. This gives you an opportunity to configure its
settings.
- Added doom-first-{input,buffer,file}-hook hooks, which we use to queue
deferred activation of a number of packages. Users can remove these
modes from these hooks; altogether preventing them from loading,
rather than waiting for them to load to then disable them,
e.g. (after! smartparens (smartparens-global-mode -1)) -> (remove-hook
'doom-first-buffer #'smartparens-global-mode)
Hooks added to doom-first-*-hook variables will be removed once they
run.
This should also indirectly fix #2386, by preventing interactive modes
from running in non-interactive session.
- Added `doom/bump-*` commands to make bumping modules and packages
easier, and `doom/bumpify-*` commands for converting package!
statements into user/repo@sha1hash format for bump commits.
- straight.el is now commit-pinned, like all other packages. We also
more reliably install straight.el by cloning it ourselves, rather than
relying on its bootstrap.el.
This should prevent infinite "straight has diverged from master"
prompts whenever we change branches (though, you might have to put up
with it one more after this update -- see #2937 for workaround).
All the other minor changes:
- Moved core/autoload/cli.el to core/autoload/process.el
- The package manager will log attempts to check out pinned commits
- If package state is incomplete while rebuilding packages, emit a
simpler error message instead of an obscure one!
- Added -u switch to 'doom sync' to make it run 'doom update' afterwards
- Added -p switch to 'doom sync' to make it run 'doom purge' afterwards
- Replace doom-modules function with doom-modules-list
- The `with-plist!` macro was removed, since `cl-destructuring-bind`
already serves that purpose well enough.
- core/autoload/packages.el was moved into core-packages.el
- bin/doom will no longer die if DOOMDIR or DOOMLOCALDIR don't have a
trailing slash
- Introduces doom-debug-variables; a list of variables to toggle on
doom/toggle-debug-mode.
- The sandbox has been updated to reflect the above changes, also:
1. Child instances will no longer inherit the process environment of
the host instance,
2. It will no longer produce an auto-save-list directory in ~/.emacs.d
2020-05-14 15:00:23 -04:00
|
|
|
(if all-p
|
2022-09-13 00:28:28 +02:00
|
|
|
(mapcar #'doom-module-from-path (doom-module-load-path doom-modules-dirs))
|
2022-09-12 22:50:25 +02:00
|
|
|
(hash-table-keys doom-modules)))
|
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
|
|
|
|
2020-05-27 16:11:59 -04:00
|
|
|
(defvar doom--deferred-packages-alist '(t))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2020-05-27 16:11:59 -04:00
|
|
|
(autoload 'use-package "use-package-core" nil nil t)
|
2018-06-20 12:48:59 +02:00
|
|
|
|
2022-06-24 21:15:31 +02:00
|
|
|
(setq use-package-compute-statistics init-file-debug
|
|
|
|
use-package-verbose init-file-debug
|
|
|
|
use-package-minimum-reported-time (if init-file-debug 0 0.1)
|
|
|
|
use-package-expand-minimally (not noninteractive))
|
2020-05-27 16:11:59 -04:00
|
|
|
|
2021-01-18 02:16:45 +10:00
|
|
|
;; A common mistake for new users is that they inadvertently install their
|
2020-05-27 16:11:59 -04:00
|
|
|
;; packages with package.el, by copying over old `use-package' declarations with
|
|
|
|
;; an :ensure t property. Doom doesn't use package.el, so this will throw an
|
|
|
|
;; error that will confuse beginners, so we disable `:ensure'.
|
2020-08-03 19:11:15 -04:00
|
|
|
(setq use-package-ensure-function
|
|
|
|
(lambda (name &rest _)
|
|
|
|
(message "Ignoring ':ensure t' in '%s' config" name)))
|
2020-05-27 16:11:59 -04:00
|
|
|
;; ...On the other hand, if the user has loaded `package', then we should assume
|
|
|
|
;; they know what they're doing and restore the old behavior:
|
|
|
|
(add-transient-hook! 'package-initialize
|
|
|
|
(when (eq use-package-ensure-function #'ignore)
|
|
|
|
(setq use-package-ensure-function #'use-package-ensure-elpa)))
|
2019-05-01 19:12:52 -04:00
|
|
|
|
|
|
|
(with-eval-after-load 'use-package-core
|
2019-09-20 23:55:50 -04:00
|
|
|
;; We define :minor and :magic-minor from the `auto-minor-mode' package here
|
|
|
|
;; so we don't have to load `auto-minor-mode' so early.
|
2019-07-21 14:49:09 +02:00
|
|
|
(dolist (keyword '(:minor :magic-minor))
|
|
|
|
(setq use-package-keywords
|
|
|
|
(use-package-list-insert keyword use-package-keywords :commands)))
|
|
|
|
|
|
|
|
(defalias 'use-package-normalize/:minor #'use-package-normalize-mode)
|
|
|
|
(defun use-package-handler/:minor (name _ arg rest state)
|
|
|
|
(use-package-handle-mode name 'auto-minor-mode-alist arg rest state))
|
|
|
|
|
|
|
|
(defalias 'use-package-normalize/:magic-minor #'use-package-normalize-mode)
|
|
|
|
(defun use-package-handler/:magic-minor (name _ arg rest state)
|
|
|
|
(use-package-handle-mode name 'auto-minor-mode-magic-alist arg rest state))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2020-06-01 18:22:29 -04:00
|
|
|
;; HACK Fix `:load-path' so it resolves relative paths to the containing file,
|
|
|
|
;; rather than `user-emacs-directory'. This is a done as a convenience
|
|
|
|
;; for users, wanting to specify a local directory.
|
2021-08-04 01:18:06 -04:00
|
|
|
(defadvice! doom--resolve-load-path-from-containg-file-a (fn label arg &optional recursed)
|
2020-06-01 18:22:29 -04:00
|
|
|
"Resolve :load-path from the current directory."
|
|
|
|
:around #'use-package-normalize-paths
|
2020-06-01 21:06:03 -04:00
|
|
|
;; `use-package-normalize-paths' resolves paths relative to
|
|
|
|
;; `user-emacs-directory', so we change that.
|
2022-04-06 23:06:32 +02:00
|
|
|
(let ((user-emacs-directory
|
|
|
|
(or (and (stringp arg)
|
|
|
|
(not (file-name-absolute-p arg))
|
|
|
|
(ignore-errors (dir!)))
|
2022-07-04 02:34:51 +02:00
|
|
|
doom-emacs-dir)))
|
2021-08-04 01:18:06 -04:00
|
|
|
(funcall fn label arg recursed)))
|
2020-06-01 18:22:29 -04:00
|
|
|
|
2019-09-20 23:55:50 -04:00
|
|
|
;; Adds two keywords to `use-package' to expand its lazy-loading capabilities:
|
|
|
|
;;
|
|
|
|
;; :after-call SYMBOL|LIST
|
|
|
|
;; :defer-incrementally SYMBOL|LIST|t
|
|
|
|
;;
|
|
|
|
;; Check out `use-package!'s documentation for more about these two.
|
|
|
|
(dolist (keyword '(:defer-incrementally :after-call))
|
|
|
|
(push keyword use-package-deferring-keywords)
|
|
|
|
(setq use-package-keywords
|
|
|
|
(use-package-list-insert keyword use-package-keywords :after)))
|
|
|
|
|
2019-05-21 00:34:32 -04:00
|
|
|
(defalias 'use-package-normalize/:defer-incrementally #'use-package-normalize-symlist)
|
2018-09-20 10:41:19 -04:00
|
|
|
(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)))
|
|
|
|
|
2019-05-21 00:34:32 -04: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)
|
2019-07-18 15:27:20 +02:00
|
|
|
(let ((fn (make-symbol (format "doom--after-call-%s-h" name))))
|
2018-06-11 23:18:15 +02:00
|
|
|
(use-package-concat
|
|
|
|
`((fset ',fn
|
|
|
|
(lambda (&rest _)
|
2022-09-16 16:25:48 +02:00
|
|
|
(doom-log "use-package: lazy loading %s from %s" ',name ',fn)
|
2019-03-22 14:11:59 -04:00
|
|
|
(condition-case e
|
2019-08-26 20:36:39 -04:00
|
|
|
;; If `default-directory' is a directory that doesn't
|
|
|
|
;; exist or is unreadable, Emacs throws up file-missing
|
|
|
|
;; errors, so we set it to a directory we know exists and
|
|
|
|
;; is readable.
|
|
|
|
(let ((default-directory doom-emacs-dir))
|
|
|
|
(require ',name))
|
2018-06-19 20:54:09 +02:00
|
|
|
((debug error)
|
|
|
|
(message "Failed to load deferred package %s: %s" ',name e)))
|
2019-06-25 21:38:16 +02:00
|
|
|
(when-let (deferral-list (assq ',name doom--deferred-packages-alist))
|
2019-03-22 14:11:59 -04:00
|
|
|
(dolist (hook (cdr deferral-list))
|
2019-04-30 15:12:07 -04:00
|
|
|
(advice-remove hook #',fn)
|
|
|
|
(remove-hook hook #',fn))
|
2019-05-21 00:34:32 -04:00
|
|
|
(delq! deferral-list doom--deferred-packages-alist)
|
|
|
|
(unintern ',fn nil)))))
|
2018-06-23 16:48:58 +02:00
|
|
|
(let (forms)
|
|
|
|
(dolist (hook hooks forms)
|
2019-04-30 15:12:07 -04:00
|
|
|
(push (if (string-match-p "-\\(?:functions\\|hook\\)$" (symbol-name hook))
|
|
|
|
`(add-hook ',hook #',fn)
|
|
|
|
`(advice-add #',hook :before #',fn))
|
2018-06-23 16:48:58 +02:00
|
|
|
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
|
|
|
|
2019-07-26 12:05:13 +02:00
|
|
|
(put :if 'lisp-indent-function 2)
|
|
|
|
(put :when 'lisp-indent-function 'defun)
|
|
|
|
(put :unless 'lisp-indent-function 'defun)
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
(defmacro doom! (&rest modules)
|
|
|
|
"Bootstraps DOOM Emacs and its modules.
|
|
|
|
|
2019-12-02 16:07:25 -05:00
|
|
|
If the first item in MODULES doesn't satisfy `keywordp', MODULES is evaluated,
|
|
|
|
otherwise, MODULES is a multiple-property list (a plist where each key can have
|
|
|
|
multiple, linear values).
|
|
|
|
|
2018-06-11 23:18:15 +02:00
|
|
|
The bootstrap process involves making sure the essential directories exist, core
|
2020-08-24 00:36:52 -04:00
|
|
|
packages are installed, `doom-autoloads-file' is loaded, `doom-packages-file'
|
2018-06-11 23:18:15 +02:00
|
|
|
cache exists (and is loaded) and, finally, loads your private init.el (which
|
|
|
|
should contain your `doom!' block).
|
|
|
|
|
|
|
|
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)."
|
2022-06-24 21:15:31 +02:00
|
|
|
`(when noninteractive
|
2020-05-25 21:51:35 -04:00
|
|
|
(doom-module-mplist-map
|
|
|
|
(lambda (category module &rest plist)
|
2022-09-15 23:37:04 +02:00
|
|
|
(let ((path (doom-module-locate-path category module)))
|
|
|
|
(unless path
|
|
|
|
(print! (warn "Failed to locate a '%s %s' module") category module))
|
|
|
|
(apply #'doom-module-set category module
|
|
|
|
:path path
|
|
|
|
plist)))
|
2020-05-25 21:51:35 -04:00
|
|
|
,@(if (keywordp (car modules))
|
|
|
|
(list (list 'quote modules))
|
|
|
|
modules))
|
|
|
|
doom-modules))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2018-06-16 00:36:27 +02:00
|
|
|
(defvar doom-disabled-packages)
|
2019-07-23 12:44:03 +02:00
|
|
|
(defmacro use-package! (name &rest plist)
|
2019-05-01 19:12:52 -04:00
|
|
|
"Declares and configures a package.
|
2019-03-09 15:06:45 -05:00
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
This is a thin wrapper around `use-package', and is ignored if the NAME package
|
|
|
|
is disabled by the user (with `package!').
|
2019-03-09 15:06:45 -05:00
|
|
|
|
2019-05-01 19:12:52 -04:00
|
|
|
See `use-package' to see what properties can be provided. Doom adds support for
|
|
|
|
two extra properties:
|
2019-03-09 15:06:45 -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
|
2019-10-03 14:51:08 -04:00
|
|
|
loaded.
|
2019-03-09 15:06:45 -05:00
|
|
|
|
|
|
|
: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 during idle periods, so that when you finally do need
|
2019-10-03 14:51:08 -04:00
|
|
|
the package, it'll load quicker.
|
2019-03-09 15:06:45 -05:00
|
|
|
|
|
|
|
NAME is implicitly added if this property is present and non-nil. No need to
|
2019-10-03 14:51:08 -04:00
|
|
|
specify it. A value of `t' implies NAME."
|
2019-07-24 16:53:33 +02:00
|
|
|
(declare (indent 1))
|
2019-02-22 01:48:59 -05:00
|
|
|
(unless (or (memq name doom-disabled-packages)
|
2019-05-01 19:12:52 -04:00
|
|
|
;; At compile-time, use-package will forcibly load packages to
|
|
|
|
;; prevent compile-time errors. However, if a Doom user has
|
|
|
|
;; disabled packages you get file-missing package errors, so it's
|
|
|
|
;; necessary to check for packages at compile time:
|
2019-02-22 01:48:59 -05:00
|
|
|
(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
|
|
|
|
2019-07-23 12:44:03 +02:00
|
|
|
(defmacro use-package-hook! (package when &rest body)
|
|
|
|
"Reconfigures a package's `use-package!' block.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2019-10-01 17:41:25 -04:00
|
|
|
This macro must be used *before* PACKAGE's `use-package!' block. Often, this
|
|
|
|
means using it from your DOOMDIR/init.el.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2019-10-01 17:41:25 -04:00
|
|
|
WARNINGS:
|
|
|
|
- The use of this macro is more often than not a code smell. Use it as last
|
|
|
|
resort. There is almost always a better alternative.
|
|
|
|
- If you are using this solely for :post-config, stop! `after!' is much better.
|
|
|
|
- If :pre-init or :pre-config hooks return nil, the original `use-package!''s
|
|
|
|
:init/:config block (respectively) is overwritten, so remember to have them
|
|
|
|
return non-nil (or exploit that to overwrite Doom's config)."
|
2018-06-11 23:18:15 +02:00
|
|
|
(declare (indent defun))
|
|
|
|
(unless (memq when '(:pre-init :post-init :pre-config :post-config))
|
2019-07-23 12:44:03 +02:00
|
|
|
(error "'%s' isn't a valid hook for use-package-hook!" when))
|
2018-06-11 23:18:15 +02:00
|
|
|
`(progn
|
|
|
|
(setq use-package-inject-hooks t)
|
2019-07-26 19:57:13 +02:00
|
|
|
(add-hook ',(intern (format "use-package--%s--%s-hook"
|
|
|
|
package
|
|
|
|
(substring (symbol-name when) 1)))
|
|
|
|
(lambda () ,@body)
|
|
|
|
'append)))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-08-12 20:29:19 +02:00
|
|
|
;; DEPRECATED Remove in 3.0
|
|
|
|
(define-obsolete-function-alias 'featurep! 'modulep! "3.0.0")
|
|
|
|
|
|
|
|
(defmacro modulep! (category &optional module flag)
|
2022-09-15 23:29:37 +02:00
|
|
|
"Return t if :CATEGORY MODULE (and +FLAGS) are enabled.
|
2019-04-20 02:17:51 -04:00
|
|
|
|
|
|
|
If FLAG is provided, returns t if CATEGORY MODULE has FLAG enabled.
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-15 23:29:37 +02:00
|
|
|
(modulep! :config default +flag)
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-15 23:29:37 +02:00
|
|
|
CATEGORY and MODULE may be omitted when this macro is used from a Doom module's
|
|
|
|
source (except your DOOMDIR, which is a special module). Like so:
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-15 23:29:37 +02:00
|
|
|
(modulep! +flag)
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-15 23:29:37 +02:00
|
|
|
For more about modules and flags, see `doom!'."
|
2022-09-12 23:44:04 +02:00
|
|
|
(and (cond (flag (memq flag (cdr (get category module))))
|
|
|
|
(module (get category module))
|
2018-07-30 23:53:05 +02:00
|
|
|
(doom--current-flags (memq category doom--current-flags))
|
2022-09-12 22:57:25 +02:00
|
|
|
(doom--current-module
|
2022-09-12 23:44:04 +02:00
|
|
|
(memq category (cdr (get (car doom--current-module)
|
|
|
|
(cdr doom--current-module)))))
|
2022-09-12 20:26:43 +02:00
|
|
|
((if-let (module (doom-module-from-path (macroexpand '(file!))))
|
2022-09-12 23:44:04 +02:00
|
|
|
(memq category (cdr (get (car module) (cdr module))))
|
2022-08-12 20:29:19 +02:00
|
|
|
(error "(modulep! %s %s %s) couldn't figure out what module it was called from (in %s)"
|
2020-05-27 16:11:59 -04:00
|
|
|
category module flag (file!)))))
|
2018-07-29 02:46:18 +02:00
|
|
|
t))
|
2018-06-11 23:18:15 +02:00
|
|
|
|
2022-09-13 00:28:28 +02:00
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Defaults
|
|
|
|
|
|
|
|
;; Register Doom's two virtual module categories, representing Doom's core and
|
|
|
|
;; the user's config; which are always enabled.
|
|
|
|
(doom-module-set :core nil :path doom-core-dir)
|
|
|
|
(doom-module-set :user nil :path doom-user-dir)
|
|
|
|
|
2022-07-30 21:49:00 +02:00
|
|
|
(provide 'doom-modules)
|
|
|
|
;;; doom-modules.el ends here
|