From 3a0f1aa3ef6623ee65765b7fa68e5aded2c518e4 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 13 Sep 2022 00:28:28 +0200 Subject: [PATCH] refactor: register :core & :user as virtual modules ...that are always enabled. This way, the module API treats them as any other module. This also changes doom-module-load-path. If supplied directories, doom-user-dir will not be the CAR of its return value. If no dirs are supplied, then doom-core-dir and doom-user-dir are included (and will always be the first two items in the returned list). --- .doomrc | 2 +- lisp/cli/autoloads.el | 5 ++--- lisp/cli/compile.el | 2 +- lisp/doom-modules.el | 39 ++++++++++++++++++++++----------------- lisp/lib/packages.el | 6 +----- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.doomrc b/.doomrc index d0d07a4e7..e01f5c0a6 100644 --- a/.doomrc +++ b/.doomrc @@ -19,7 +19,7 @@ (after! doom-cli-make ;;; Codeowners - (dolist (path (cdr (doom-module-load-path (list doom-modules-dir)))) + (dolist (path (doom-module-load-path (list doom-modules-dir))) ;; I will be the default owner for everything in the repo unless a later ;; match takes precedence. (add-to-list 'doom-make-codeowners "# The default owner(s) unless another takes precedence") diff --git a/lisp/cli/autoloads.el b/lisp/cli/autoloads.el index 66b77a46c..42471589a 100644 --- a/lisp/cli/autoloads.el +++ b/lisp/cli/autoloads.el @@ -56,7 +56,7 @@ hoist buggy forms into autoloads.") (doom-autoloads--scan (append (doom-glob doom-core-dir "lib/*.el") (cl-loop for dir - in (append (cdr (doom-module-load-path 'all-p)) + in (append (doom-module-load-path doom-modules-dirs) (list doom-user-dir)) if (doom-glob dir "autoload.el") collect (car it) if (doom-glob dir "autoload/*.el") append it) @@ -198,8 +198,7 @@ hoist buggy forms into autoloads.") (generated-autoload-load-name (file-name-sans-extension file)) (target-buffer (current-buffer)) (module (doom-module-from-path file)) - (module-enabled-p (and (or (memq (car module) '(:core :user)) - (doom-module-p (car module) (cdr module))) + (module-enabled-p (and (doom-module-p (car module) (cdr module)) (doom-file-cookie-p file "if" t)))) (save-excursion (when module-enabled-p diff --git a/lisp/cli/compile.el b/lisp/cli/compile.el index a205bc6c4..3dc9004b0 100644 --- a/lisp/cli/compile.el +++ b/lisp/cli/compile.el @@ -41,7 +41,7 @@ and your private config files, respectively. To recompile your packages, use ;; Only compile Doom's modules (doom-rpartial #'file-in-directory-p doom-emacs-dir) ;; Omit `doom-user-dir', which is always first - (cdr (doom-module-load-path))))) + (doom-module-load-path)))) recompile-p verbose-p)) diff --git a/lisp/doom-modules.el b/lisp/doom-modules.el index aa5e1e36f..df20134a2 100644 --- a/lisp/doom-modules.el +++ b/lisp/doom-modules.el @@ -246,23 +246,19 @@ If ENABLED-ONLY, return nil if the containing module isn't enabled." 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 -those directories. The first returned path is always `doom-user-dir'." +those directories." (declare (pure t) (side-effect-free t)) - (append (list doom-user-dir) - (if module-dirs - (mapcar (lambda (m) (doom-module-locate-path (car m) (cdr m))) - (delete-dups - (doom-files-in (if (listp module-dirs) - module-dirs - doom-modules-dirs) - :map #'doom-module-from-path - :type 'dirs - :mindepth 1 - :depth 1))) - (delq - nil (cl-loop for (cat . mod) in (doom-module-list) - collect (doom-module-get cat mod :path)))) - nil)) + (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))))) (defun doom-module-mplist-map (fn mplist) "Apply FN to each module in MPLIST." @@ -327,7 +323,7 @@ they're enabled, and in lexicographical order. If ALL-P is `real', only return *real" (if all-p - (mapcar #'doom-module-from-path (cdr (doom-module-load-path 'all))) + (mapcar #'doom-module-from-path (doom-module-load-path doom-modules-dirs)) (hash-table-keys doom-modules))) @@ -584,5 +580,14 @@ CATEGORY and MODULE can be omitted When this macro is used from inside a module category module flag (file!))))) t)) + +;; +;;; 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) + (provide 'doom-modules) ;;; doom-modules.el ends here diff --git a/lisp/lib/packages.el b/lisp/lib/packages.el index bcbff4612..42c8798e7 100644 --- a/lisp/lib/packages.el +++ b/lisp/lib/packages.el @@ -163,11 +163,7 @@ each package." (ignore-errors (intern (cadr module))) current-prefix-arg))) (mapc (lambda! ((cat . mod)) - (if-let (packages-file - (pcase cat - (:user (car (doom-glob doom-user-dir "packages.el"))) - (:core (car (doom-glob doom-core-dir "packages.el"))) - (_ (doom-module-locate-path cat mod "packages.el")))) + (if-let (packages-file (doom-module-locate-path cat mod "packages.el")) (with-current-buffer (or (get-file-buffer packages-file) (find-file-noselect packages-file))