From fca6187021833c1c81a70f7c7ed4a9731ce3c301 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 26 Oct 2024 08:14:46 -0400 Subject: [PATCH] refactor: with-doom-module: context constructor --- lisp/doom-modules.el | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/lisp/doom-modules.el b/lisp/doom-modules.el index d91dffd74..9f683e811 100644 --- a/lisp/doom-modules.el +++ b/lisp/doom-modules.el @@ -159,17 +159,24 @@ Never set this variable directly, use `with-doom-module'.") (defmacro with-doom-module (key &rest body) "Evaluate BODY with `doom-module-context' informed by KEY." (declare (indent 1)) - `(let ((doom-module-context - (let ((key ,key)) - (cond ((null key) (make-doom-module-context)) - ((doom-module-context-p key) key) - ((doom-module-p key) (doom-module->context key)) - ((doom-module (car key) (cdr key))) - ((doom-module->context key)) - ((error "Invalid module: %S" key)))))) + `(let ((doom-module-context (doom-module-context ,key))) (doom-log ":context:module: =%s" doom-module-context) ,@body)) +(defun doom-module-context (key) + "Return a `doom-module-context' from KEY. + +KEY can be a `doom-module-context', `doom-module', or a `doom-module-key' cons +cell." + (declare (side-effect-free t)) + (unless key + (error "Invalid module context: %S" key)) + (or (pcase (type-of key) + (`doom-module-context key) + (`doom-module (doom-module->context key)) + (`cons (doom-module (car key) (cdr key)))) + (error "Invalid module context or key: %S" key))) + (defun doom-module<-context (context) "Return a `doom-module' plist from CONTEXT." (declare (side-effect-free t))