diff --git a/bin/doom b/bin/doom index be2602309..a1c391f26 100755 --- a/bin/doom +++ b/bin/doom @@ -295,9 +295,9 @@ SEE ALSO: (let ((cli-file "cli")) (defcli-group! "Module commands" (dolist (key (hash-table-keys doom-modules)) - (when-let (path (plist-get (gethash key doom-modules) :path)) + (when-let (path (doom-module-expand-path (car key) (cdr key) cli-file)) (defcli-group! :prefix (format "+%s" (cdr key)) - (load! cli-file path t))))) + (doom-load path t))))) (load! cli-file doom-user-dir t)) diff --git a/lisp/cli/doctor.el b/lisp/cli/doctor.el index 070553151..789575035 100644 --- a/lisp/cli/doctor.el +++ b/lisp/cli/doctor.el @@ -251,8 +251,8 @@ in." (condition-case-unless-debug ex (let ((doom--current-module key) (doom--current-flags (plist-get plist :flags)) - (doctor-file (doom-module-path (car key) (cdr key) "doctor.el")) - (packages-file (doom-module-path (car key) (cdr key) "packages.el"))) + (doctor-file (doom-module-expand-path (car key) (cdr key) "doctor.el")) + (packages-file (doom-module-expand-path (car key) (cdr key) "packages.el"))) (cl-loop with doom-output-indent = 6 for name in (let (doom-packages doom-disabled-packages) diff --git a/lisp/doom-modules.el b/lisp/doom-modules.el index a062ad2e7..4ff2678ba 100644 --- a/lisp/doom-modules.el +++ b/lisp/doom-modules.el @@ -180,16 +180,15 @@ Example: (doom-module-set :lang 'haskell :flags '(+lsp))" (puthash (cons category module) plist doom-modules)) -(defun doom-module-path (category module &optional file) - "Like `expand-file-name', but expands FILE relative to CATEGORY (keywordp) and -MODULE (symbol). +(defun doom-module-expand-path (category module &optional file) + "Expands a path to FILE relative to CATEGORY and MODULE. -If the category isn't enabled this will always return nil. For finding disabled -modules use `doom-module-locate-path'." - (let ((path (doom-module-get category module :path))) +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)) (if file - (let (file-name-handler-alist) - (expand-file-name file path)) + (file-name-concat path file) path))) (defun doom-module-locate-path (category &optional module file) @@ -197,19 +196,22 @@ modules use `doom-module-locate-path'." 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 -returns nil, otherwise an absolute path. - -This doesn't require modules to be enabled. For enabled modules us -`doom-module-path'." - (when (keywordp category) - (setq category (doom-keyword-name category))) - (when (and module (symbolp module)) - (setq module (symbol-name module))) - (cl-loop with file-name-handler-alist = nil - for default-directory in doom-modules-dirs - for path = (concat category "/" module "/" file) - if (file-exists-p path) - return (expand-file-name path))) +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))))))) (defun doom-module-from-path (path &optional enabled-only) "Returns a cons cell (CATEGORY . MODULE) derived from PATH (a file path). diff --git a/lisp/doom-packages.el b/lisp/doom-packages.el index 012200dc9..6edc1a619 100644 --- a/lisp/doom-packages.el +++ b/lisp/doom-packages.el @@ -466,7 +466,7 @@ ones." (let (doom-packages) (doom--read-packages private-packages nil 'noerror)) (cl-loop for key being the hash-keys of doom-modules - for path = (doom-module-path (car key) (cdr key) packages-file) + for path = (doom-module-expand-path (car key) (cdr key) packages-file) for doom--current-module = key for doom--current-flags = (doom-module-get (car key) (cdr key) :flags) do (doom--read-packages path nil 'noerror)))