Major rewrite of doom module API

+ Fix #446, where the .local/packages.el cache was generated with
  a faulty load-path.
+ Entries in the doom-modules hash table are now plists, containing
  :flags and :path, at least.
+ Add doom-initialize-modules for loading module config.el files.
+ Add doom-module-get for accessing this plist, e.g.

    (doom-module-get :some module)         ; returns plist
    (doom-module-get :some module :flags)  ; return specific property

+ Replace doom-module-enable with doom-module-set, e.g.

    (doom-module-set :some module :flags '(+a +b +c))

+ Remove doom-module-flags (use doom-module-get instead)
+ Rename doom-module-enabled-p with doom-module-p
+ Replace doom-module-path with doom-module-find-path and
  doom-module-expand-file. The former will search for an existing module
  or file in doom-modules-dirs. The latter will expand the path from
  whatever path is stored in doom-modules.
+ Replace doom-module-paths with doom-module-load-path
+ Changed doom! to allow for nested doom! calls by delaying the loading
  of module config.el files until as late as possible.
+ Refactor doom-initialize-packages to only ihitialize package state
  (i.e. doom-packages, package-alist, and quelpa-cache), rather than its
  previous behavior of loading all Doom files (and sometimes all module
  files). This is faster and more predictable.
This commit is contained in:
Henrik Lissner 2018-03-02 17:45:15 -05:00
parent 01f9ca9e67
commit 0425724571
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
7 changed files with 351 additions and 282 deletions

View file

@ -120,7 +120,7 @@ ready to be pasted in a bug report on github."
if (or (not cat) (not (eq cat (car key))))
do (setq cat (car key)) and collect cat
else collect
(let ((flags (doom-module-flags cat (cdr key))))
(let ((flags (doom-module-get cat (cdr key) :flags)))
(if (equal flags '(t))
(cdr key)
(list (cdr key) flags))))

View file

@ -95,9 +95,9 @@ in, or d) the module associated with the current major mode (see
nil t module))))
(cl-destructuring-bind (category submodule)
(mapcar #'intern (split-string module " "))
(unless (doom-module-enabled-p category submodule)
(unless (doom-module-p category submodule)
(error "'%s' isn't a valid module" module))
(let ((doc-path (expand-file-name "README.org" (doom-module-path category submodule))))
(let ((doc-path (doom-module-expand-file category submodule "README.org")))
(unless (file-exists-p doc-path)
(error "There is no documentation for this module"))
(find-file doc-path))))

View file

@ -3,10 +3,9 @@
(load! cache)
(require 'use-package)
(require 'quelpa)
(require 'package)
(require 'async)
(doom-initialize-packages)
;;;###autoload
(defun doom-refresh-packages (&optional force-p)
"Refresh ELPA packages."
@ -113,7 +112,7 @@ Warning: this function is expensive; it re-evaluates all of doom's config files.
Be careful not to use it in a loop.
If INSTALLED-ONLY-P, only return packages that are installed."
(doom-initialize-packages t)
(doom-initialize-packages 'internal)
(cl-loop with packages = (append doom-core-packages (mapcar #'car doom-packages))
for sym in (cl-delete-duplicates packages)
if (and (or (not installed-only-p)
@ -146,7 +145,7 @@ containing (PACKAGE-SYMBOL OLD-VERSION-LIST NEW-VERSION-LIST).
If INCLUDE-FROZEN-P is non-nil, check frozen packages as well.
Used by `doom//packages-update'."
(doom-initialize-packages t)
(doom-initialize-packages 'internal)
(require 'async)
(let (quelpa-pkgs elpa-pkgs)
;; Separate quelpa from elpa packages
@ -184,7 +183,7 @@ Used by `doom//packages-update'."
depended on.
Used by `doom//packages-autoremove'."
(doom-initialize-packages t)
(doom-initialize-packages 'internal)
(let ((package-selected-packages
(append (mapcar #'car doom-packages) doom-core-packages)))
(append (package--removable-packages)
@ -204,7 +203,7 @@ If INCLUDE-IGNORED-P is non-nil, includes missing packages that are ignored,
i.e. they have an :ignore property.
Used by `doom//packages-install'."
(doom-initialize-packages t)
(doom-initialize-packages 'internal)
(cl-loop for desc in (doom-get-packages)
for (name . plist) = desc
if (and (or include-ignored-p

View file

@ -8,52 +8,52 @@ command line args following a double dash (each arg should be in the
If neither is available, run all tests in all enabled modules."
(interactive)
;; ensure DOOM is initialized
(doom-initialize-packages t)
(condition-case-unless-debug ex
(let ((target-paths
;; Convert targets (either from MODULES or `argv') into a list of
;; string paths, pointing to the root directory of modules
(cond ((string= (car argv) "--") ; command line
(save-match-data
(cl-loop for arg in (cdr argv)
if (equal arg "core") collect doom-core-dir
else if (string-match-p "/" arg)
nconc (cl-loop for dir in doom-modules-dirs
collect (expand-file-name arg dir))
else
nconc (cl-loop for dir in doom-modules-dirs
for path = (expand-file-name arg dir)
if (file-directory-p path)
nconc
(cl-remove-if-not
#'file-directory-p
(directory-files path t "^[^.]" t)))
finally do (setq argv nil))))
(let ((doom-modules (make-hash-table :test #'equal)))
;; ensure DOOM is initialized
(doom-initialize-packages t)
(condition-case-unless-debug ex
(let ((target-paths
;; Convert targets (either from MODULES or `argv') into a list of
;; string paths, pointing to the root directory of modules
(cond ((string= (car argv) "--") ; command line
(save-match-data
(cl-loop for arg in (cdr argv)
if (equal arg "core") collect doom-core-dir
else if (string-match-p "/" arg)
nconc (cl-loop for dir in doom-modules-dirs
collect (expand-file-name arg dir))
else
nconc (cl-loop for dir in doom-modules-dirs
for path = (expand-file-name arg dir)
if (file-directory-p path)
nconc
(cl-remove-if-not
#'file-directory-p
(directory-files path t "^[^.]" t)))
finally do (setq argv nil))))
(modules ; cons-cells given to MODULES
(cl-loop for (module . submodule) in modules
if (doom-module-path module submodule)
collect it))
(modules ; cons-cells given to MODULES
(cl-loop for (module . submodule) in modules
if (doom-module-find-path module submodule)
collect it))
((let (noninteractive)
(setq doom-modules (clrhash doom-modules))
(load (expand-file-name "init.test.el" user-emacs-directory) nil t)
(append (list doom-core-dir) (doom-module-paths)))))))
;; Load all the unit test files...
(dolist (path target-paths)
(let ((test-path (expand-file-name "test/" path)))
(when (file-directory-p test-path)
(dolist (test-file (reverse (doom-packages--files test-path "\\.el$")))
(load test-file nil :noerror)))))
;; ... then run them
(if noninteractive
(ert-run-tests-batch-and-exit)
(call-interactively #'ert-run-tests-interactively)))
('error
(lwarn 'doom-test :error
"%s -> %s"
(car ex) (error-message-string ex)))))
((let (noninteractive)
(load (expand-file-name "init.test.el" user-emacs-directory) nil t)
(append (list doom-core-dir) (doom-module-load-path)))))))
;; Load all the unit test files...
(dolist (path target-paths)
(let ((test-path (expand-file-name "test/" path)))
(when (file-directory-p test-path)
(dolist (test-file (reverse (doom-packages--files test-path "\\.el$")))
(load test-file nil :noerror)))))
;; ... then run them
(if noninteractive
(ert-run-tests-batch-and-exit)
(call-interactively #'ert-run-tests-interactively)))
('error
(lwarn 'doom-test :error
"%s -> %s"
(car ex) (error-message-string ex))))))
;; --- Test helpers -----------------------