refactor!: module API

BREAKING CHANGE: This backports some architectural choices from v3.0.
This changes Doom's module API, renaming some functions and removing
others, in order to facilitate some new features, prepare to move Doom's
modules into separate repos, and make way for two, much larger breaking
commits coming in the next few days.

This commit won't break anything for users unless they're tinkering with
Doom's internals/using its `doom-module-*` API directly. I am avoiding
broader backwards incompatibilities until the 3.0 release.

What's new:

- Negated flags. (modulep! :editor evil -everywhere) will return non-nil
  if :editor evil is active without its +everywhere flag.
- `modulep!` now takes multiple flags to simplify AND checks. E.g.

    (and (modulep! +foo)
         (modulep! +bar)
         (not (modulep! +baz)))

  Can now be expressed with:

    (modulep! +foo +bar -baz)
- Adds pcase matchers for `doom-module-context` and `doom-module`
  structs, making the following destructuring binds possible:

    (pcase-dolist ((doom-module group name flags features)
                   (hash-table-values doom-modules))
      ...)

  This will be used more in v3.0.
- Adds file cookie support to module init.el and config.el files.

Here's a summary of breaking changes made in this commit:

- `doom-module-context` was changed from a vector to a struct (record).
- `doom-modules` is now a table of `doom-module` structs, rather than
  free-form plists.
- The following macros have been renamed:
  - `doom-context-with` -> `with-doom-context`
  - `doom-module-context-with` -> `with-doom-module`
- The followings functions have been replaced/removed:
  - `doom-module-context`+`doom-module-context-get` -> `doom-module`
  - `doom-module-set` -> `doom-module--put`
  - `doom-module-p` -> `doom-module-active-p`
  - `doom-module-context-key` (is now a getter with the same name)
  - `doom-module-put` (removed)
  - `doom-module--context-field` (removed)
- The signatures for these functions have changed:
  - `doom-module-get CATEGORY &optional MODULE PROP` ->
    `doom-module-get (GROUP . MODULE) &optional PROP`
  - `doom-module-locate-path CATEGORY &optional MODULE FILE` ->
    `doom-module-locate-path (GROUP . MODULE) &optional FILE`
  - `doom-module-expand-path CATEGORY MODULE &optional FILE` ->
    `doom-module-expand-path (GROUP . MODULE) &optional FILE`
- Adds the following functions
  - `doom-module-exists-p`
  - `doom-module-key`
  - `doom-module->context`
  - `doom-module<-context`
- Removes the following variables
  - `doom-module--empty-context`

This commit results in a little redundancy, which I will address in
parts 2/3 and/or v3.0.
This commit is contained in:
Henrik Lissner
2024-10-19 15:29:56 -04:00
parent b9deb35aab
commit 15904349cf
24 changed files with 443 additions and 320 deletions

View File

@@ -157,12 +157,11 @@ exist, and `org-link' otherwise."
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path)
(when category
(let ((doom-modules-dirs (list doom-modules-dir)))
(if-let* ((path (doom-module-locate-path category module))
(path (or (car (doom-glob path "README.org"))
path)))
(find-file path)
(user-error "Can't find Doom module '%s'" module-path))))
(if-let* ((path (doom-module-locate-path (cons category module)))
(path (or (car (doom-glob path "README.org"))
path)))
(find-file path)
(user-error "Can't find Doom module '%s'" module-path)))
(when flag
(goto-char (point-min))
(when (and (re-search-forward "^\\*+ \\(?:TODO \\)?Module flags")
@@ -179,13 +178,13 @@ exist, and `org-link' otherwise."
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec module-path)
(let ((overall-face
(if (and category (doom-module-locate-path category module))
(if (and category (doom-module-locate-path (cons category module)))
'((:underline nil) org-link org-block bold)
'(shadow org-block bold)))
(icon-face
(cond
((doom-module-p category module flag) 'success)
((and category (doom-module-locate-path category module)) 'warning)
((doom-module-active-p category module flag) 'success)
((and category (doom-module-locate-path (cons category module))) 'warning)
(t 'error))))
(add-text-properties
start end
@@ -294,9 +293,9 @@ exist, and `org-link' otherwise."
(cl-destructuring-bind (&key category module flag)
(+org-link--read-module-spec (org-element-property :path link))
(cond
((doom-module-p category module)
((doom-module-active-p category module)
(propertize "enabled" 'face 'success))
((and category (doom-module-locate-path category module))
((and category (doom-module-locate-path (cons category module)))
(propertize "disabled" 'face 'error))
(t (propertize "unknown" 'face '(bold error)))))))
("doom-executable"

View File

@@ -1301,7 +1301,7 @@ between the two."
))
;;; Custom org modules
(dolist (flag (doom-module-context-get :flags))
(dolist (flag (doom-module :lang 'org :flags))
(load! (concat "contrib/" (substring (symbol-name flag) 1)) nil t))
;; Add our general hooks after the submodules, so that any hooks the