fix: make doom-module-from-path's PATH arg required

This commit is contained in:
Henrik Lissner 2022-09-12 20:26:43 +02:00
parent a5bb50e957
commit a67b212b99
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -211,20 +211,11 @@ This doesn't require modules to be enabled. For enabled modules us
if (file-exists-p path) if (file-exists-p path)
return (expand-file-name path))) return (expand-file-name path)))
(defun doom-module-from-path (&optional path enabled-only) (defun doom-module-from-path (path &optional enabled-only)
"Returns a cons cell (CATEGORY . MODULE) derived from PATH (a file path). "Returns a cons cell (CATEGORY . MODULE) derived from PATH (a file path).
If ENABLED-ONLY, return nil if the containing module isn't enabled." If ENABLED-ONLY, return nil if the containing module isn't enabled."
(if (null path)
(if doom--current-module
(if enabled-only
(and (doom-module-p (car doom--current-module)
(cdr doom--current-module))
doom--current-module)
doom--current-module)
(ignore-errors
(doom-module-from-path (file!))))
(let* ((file-name-handler-alist nil) (let* ((file-name-handler-alist nil)
(path (expand-file-name (or path (file!))))) (path (expand-file-name path)))
(save-match-data (save-match-data
(cond ((string-match "/modules/\\([^/]+\\)/\\([^/]+\\)\\(?:/.*\\)?$" path) (cond ((string-match "/modules/\\([^/]+\\)/\\([^/]+\\)\\(?:/.*\\)?$" path)
(when-let* ((category (doom-keyword-intern (match-string 1 path))) (when-let* ((category (doom-keyword-intern (match-string 1 path)))
@ -232,12 +223,10 @@ If ENABLED-ONLY, return nil if the containing module isn't enabled."
(and (or (null enabled-only) (and (or (null enabled-only)
(doom-module-p category module)) (doom-module-p category module))
(cons category module)))) (cons category module))))
((or (string-match-p (concat "^" (regexp-quote doom-core-dir)) path) ((file-in-directory-p path doom-core-dir)
(file-in-directory-p path doom-core-dir)) (cons :core nil))
(cons :core (intern (file-name-base path)))) ((file-in-directory-p path doom-user-dir)
((or (string-match-p (concat "^" (regexp-quote doom-user-dir)) path) (cons :user nil))))))
(file-in-directory-p path doom-user-dir))
(cons :user (intern (file-name-base path)))))))))
(defun doom-module-load-path (&optional module-dirs) (defun doom-module-load-path (&optional module-dirs)
"Return a list of file paths to activated modules. "Return a list of file paths to activated modules.
@ -569,7 +558,7 @@ CATEGORY and MODULE can be omitted When this macro is used from inside a module
(and (cond (flag (memq flag (doom-module-get category module :flags))) (and (cond (flag (memq flag (doom-module-get category module :flags)))
(module (doom-module-p category module)) (module (doom-module-p category module))
(doom--current-flags (memq category doom--current-flags)) (doom--current-flags (memq category doom--current-flags))
((if-let (module (doom-module-from-path)) ((if-let (module (doom-module-from-path (macroexpand '(file!))))
(memq category (doom-module-get (car module) (cdr module) :flags)) (memq category (doom-module-get (car module) (cdr module) :flags))
(error "(modulep! %s %s %s) couldn't figure out what module it was called from (in %s)" (error "(modulep! %s %s %s) couldn't figure out what module it was called from (in %s)"
category module flag (file!))))) category module flag (file!)))))