refactor: introduce doom-module-context

Where f9201eb introduced a general context system, this one introduces
one for modules, to simplify our let-bind game when interacting with
modules, and to more efficiently expose module state to modulep! (which
gets called at runtime a great deal, so its performance is important).

* lisp/doom-lib.el (doom-log): simplify macro and introduce
  doom-inhibit-log variable.
* lisp/doom-modules.el (modulep!): fix reported file path if modulep!
  fails to find the local module.
* lisp/lib/debug.el (doom-debug-variables): disable doom-inhibit-log
  when debug mode is on.

Ref: f9201eb218
This commit is contained in:
Henrik Lissner 2022-09-24 20:34:13 +02:00
parent 5d2313155c
commit 4efaf6837b
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
8 changed files with 118 additions and 72 deletions

View file

@ -17,29 +17,34 @@
;;
;;; Logging
(defun doom--log (text)
(let ((inhibit-message (not init-file-debug)))
(message "%s" (propertize text 'face 'font-lock-doc-face))))
(defvar doom-inhibit-log (not (or noninteractive init-file-debug))
"If non-nil, suppress `doom-log' output.")
(defmacro doom-log (output &rest args)
(defun doom--log (text &rest args)
(let ((inhibit-message (not init-file-debug))
(absolute? (string-prefix-p ":" text)))
(apply #'message
(propertize (concat "* %.06f:%s" (if (not absolute?) ":") text)
'face 'font-lock-doc-face)
(float-time (time-subtract (current-time) before-init-time))
(mapconcat
(lambda (x) (format "%s" x))
(unless absolute?
(append (cons '* (remq t (reverse doom-context)))
(if (bound-and-true-p doom-module-context)
(let ((key (doom-module-context-key)))
(delq nil (list (car key) (cdr key)))))))
":")
args)))
(defmacro doom-log (message &rest args)
"Log a message in *Messages*.
Does not emit the message in the echo area. This is a macro instead of a
function to prevent the potentially expensive evaluation of its arguments when
debug mode is off."
debug mode is off. Return non-nil."
(declare (debug t))
`(when (or init-file-debug noninteractive)
(doom--log
(with-no-warnings ; suppress 'more args than %-sequences' warning
(let* ((output ,output)
(absolute? (string-prefix-p ":" output)))
(format (concat "* %.06f%s" (if absolute? output (concat ":" output)))
(float-time (time-subtract (current-time) before-init-time))
(let ((context (remq t (reverse doom-context))))
(if (and context (not absolute?))
(concat "::" (mapconcat #'symbol-name context ":"))
""))
,@args))))))
`(unless doom-inhibit-log (doom--log ,message ,@args)))
;;