Refactor doom-debug-mode

Store intiial value in symbol plist instead. More info in 8ec8b2b.
This commit is contained in:
Henrik Lissner 2021-05-06 00:28:39 -04:00
parent a0c73c2975
commit 45147aace8

View file

@ -20,7 +20,6 @@
Each entry can be a variable symbol or a cons cell whose CAR is the variable Each entry can be a variable symbol or a cons cell whose CAR is the variable
symbol and CDR is the value to set it to when `doom-debug-mode' is activated.") symbol and CDR is the value to set it to when `doom-debug-mode' is activated.")
(defvar doom--debug-vars-old-values nil)
(defvar doom--debug-vars-undefined nil) (defvar doom--debug-vars-undefined nil)
(defun doom--watch-debug-vars-h (&rest _) (defun doom--watch-debug-vars-h (&rest _)
@ -40,14 +39,14 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.")
(dolist (var doom-debug-variables) (dolist (var doom-debug-variables)
(cond ((listp var) (cond ((listp var)
(cl-destructuring-bind (var . val) var (cl-destructuring-bind (var . val) var
(if (not (boundp var)) (if (boundp var)
(add-to-list 'doom--debug-vars-undefined var) (set-default
(set-default var (if (not enabled)
var (if (not enabled) (prog1 (get var 'initial-value)
(alist-get var doom--debug-vars-old-values) (put 'x 'initial-value nil))
(setf (alist-get var doom--debug-vars-old-values) (put var 'initial-value (symbol-value var))
(symbol-value var)) val))
val))))) (add-to-list 'doom--debug-vars-undefined var))))
((if (boundp var) ((if (boundp var)
(set-default var enabled) (set-default var enabled)
(add-to-list 'doom--debug-vars-undefined var))))) (add-to-list 'doom--debug-vars-undefined var)))))
@ -92,7 +91,7 @@ symbol and CDR is the value to set it to when `doom-debug-mode' is activated.")
(let (forms) (let (forms)
(with-temp-buffer (with-temp-buffer
(insert-file-contents file) (insert-file-contents file)
(let (emacs-lisp-mode) (emacs-lisp-mode)) (let (emacs-lisp-mode-hook) (emacs-lisp-mode))
(while (re-search-forward (format "(%s " (regexp-quote form)) nil t) (while (re-search-forward (format "(%s " (regexp-quote form)) nil t)
(let ((ppss (syntax-ppss))) (let ((ppss (syntax-ppss)))
(unless (or (nth 4 ppss) (unless (or (nth 4 ppss)