refactor: change doom-module-list signature

Used to return the hash-table `doom-modules` (if not all-p), but I've
changed it to return a list of cons cells (:CATEGORY . MODULE),
representing all enabled modules, in the order they were enabled.

The purpose of this change is to prepare for a change in the structure
of doom-modules, and how Doom stores its module metadata.
This commit is contained in:
Henrik Lissner 2022-09-12 22:50:25 +02:00
parent 775ee2f04a
commit 0c918f3b2d
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
5 changed files with 26 additions and 24 deletions

View file

@ -294,7 +294,7 @@ SEE ALSO:
(let ((cli-file "cli")) (let ((cli-file "cli"))
(defcli-group! "Module commands" (defcli-group! "Module commands"
(dolist (key (hash-table-keys doom-modules)) (dolist (key (doom-module-list))
(when-let (path (doom-module-expand-path (car key) (cdr key) cli-file)) (when-let (path (doom-module-expand-path (car key) (cdr key) cli-file))
(defcli-group! :prefix (format "+%s" (cdr key)) (defcli-group! :prefix (format "+%s" (cdr key))
(doom-load path t))))) (doom-load path t)))))

View file

@ -249,8 +249,8 @@ those directories. The first returned path is always `doom-user-dir'."
:mindepth 1 :mindepth 1
:depth 1))) :depth 1)))
(delq (delq
nil (cl-loop for plist being the hash-values of doom-modules nil (cl-loop for (cat . mod) in (doom-module-list)
collect (plist-get plist :path)) )) collect (doom-module-get cat mod :path))))
nil)) nil))
(defun doom-module-mplist-map (fn mplist) (defun doom-module-mplist-map (fn mplist)
@ -309,11 +309,15 @@ those directories. The first returned path is always `doom-user-dir'."
(nreverse results))) (nreverse results)))
(defun doom-module-list (&optional all-p) (defun doom-module-list (&optional all-p)
"Minimally initialize `doom-modules' (a hash table) and return it. "Return modules as a list of (:CATEGORY . MODULE) in their enabled order.
This value is cached. If REFRESH-P, then don't use the cached value."
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"
(if all-p (if all-p
(mapcar #'doom-module-from-path (cdr (doom-module-load-path 'all))) (mapcar #'doom-module-from-path (cdr (doom-module-load-path 'all)))
doom-modules)) (hash-table-keys doom-modules)))
;; ;;

View file

@ -452,8 +452,7 @@ ones."
(doom--read-packages (doom--read-packages
(doom-path doom-core-dir packages-file) all-p 'noerror) (doom-path doom-core-dir packages-file) all-p 'noerror)
(unless core-only-p (unless core-only-p
(let ((private-packages (doom-path doom-user-dir packages-file)) (let ((private-packages (doom-path doom-user-dir packages-file)))
(doom-modules (doom-module-list)))
(if all-p (if all-p
(mapc #'doom--read-packages (mapc #'doom--read-packages
(doom-files-in doom-modules-dir (doom-files-in doom-modules-dir
@ -465,10 +464,10 @@ ones."
;; overwritten. ;; overwritten.
(let (doom-packages) (let (doom-packages)
(doom--read-packages private-packages nil 'noerror)) (doom--read-packages private-packages nil 'noerror))
(cl-loop for key being the hash-keys of doom-modules (cl-loop for (cat . mod) in (doom-module-list)
for path = (doom-module-expand-path (car key) (cdr key) packages-file) for path = (doom-module-expand-path cat mod packages-file)
for doom--current-module = key for doom--current-module = (cons cat mod)
for doom--current-flags = (doom-module-get (car key) (cdr key) :flags) for doom--current-flags = (doom-module-get cat mod :flags)
do (doom--read-packages path nil 'noerror))) do (doom--read-packages path nil 'noerror)))
(doom--read-packages private-packages all-p 'noerror))) (doom--read-packages private-packages all-p 'noerror)))
(cl-remove-if-not (cl-remove-if-not

View file

@ -300,15 +300,15 @@ ready to be pasted in a bug report on github."
if (eq type 'theme-value) if (eq type 'theme-value)
collect var))) collect var)))
(modules (modules
,@(or (cl-loop with cat = nil ,@(or (cl-loop with lastcat = nil
for key being the hash-keys of doom-modules for (cat . mod) in (cddr (doom-module-list))
if (or (not cat) if (or (not lastcat)
(not (eq cat (car key)))) (not (eq lastcat cat)))
do (setq cat (car key)) do (setq lastcat cat)
and collect cat and collect lastcat
collect collect
(let* ((flags (doom-module-get cat (cdr key) :flags)) (let* ((flags (doom-module-get lastcat mod :flags))
(path (doom-module-get cat (cdr key) :path)) (path (doom-module-get lastcat mod :path))
(module (module
(append (append
(cond ((null path) (cond ((null path)
@ -316,8 +316,8 @@ ready to be pasted in a bug report on github."
((not (file-in-directory-p path doom-modules-dir)) ((not (file-in-directory-p path doom-modules-dir))
(list '&user))) (list '&user)))
(if flags (if flags
`(,(cdr key) ,@flags) `(,mod ,@flags)
(list (cdr key)))))) (list mod)))))
(if (= (length module) 1) (if (= (length module) 1)
(car module) (car module)
module))) module)))

View file

@ -342,8 +342,7 @@ without needing to check if they are available."
(describe-function fn)))) (describe-function fn))))
(defun doom--help-modules-list () (defun doom--help-modules-list ()
(cl-loop for path in (cdr (doom-module-load-path 'all)) (cl-loop for (cat . mod) in (doom-module-list 'all)
for (cat . mod) = (doom-module-from-path path)
for readme-path = (or (doom-module-locate-path cat mod "README.org") for readme-path = (or (doom-module-locate-path cat mod "README.org")
(doom-module-locate-path cat mod)) (doom-module-locate-path cat mod))
for format = (format "%s %s" cat mod) for format = (format "%s %s" cat mod)