From c5508515007c9a03ddd81ed9a55136af6d0cff02 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 31 Dec 2017 17:49:15 -0500 Subject: [PATCH] doom-doctor: minor refactor --- bin/doom-doctor | 62 +++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/bin/doom-doctor b/bin/doom-doctor index 15ffe646e..eb8b55108 100755 --- a/bin/doom-doctor +++ b/bin/doom-doctor @@ -8,6 +8,7 @@ ;; In case it isn't defined (in really old versions of Emacs, like the one that ;; ships with MacOS). (defvar user-emacs-directory (expand-file-name "~/.emacs.d/")) +(defvar doom-debug-mode (getenv "DEBUG")) (unless (equal (expand-file-name user-emacs-directory) (expand-file-name "~/.emacs.d/")) @@ -70,11 +71,11 @@ (format "\e[%dm%s\e[%dm" code (apply #'format msg args) 0)) (defalias 'msg! #'message) -(defmacro error! (&rest args) `(message (color 1 (color 31 ,@args)))) -(defmacro warn! (&rest args) `(message (color 1 (color 33 ,@args)))) -(defmacro success! (&rest args) `(message (color 1 (color 32 ,@args)))) -(defmacro section! (&rest args) `(message (color 34 ,@args))) -(defmacro explain! (&rest args) `(message (indented 2 (autofill ,@args)))) +(defmacro error! (&rest args) `(msg! (color 1 (color 31 ,@args)))) +(defmacro warn! (&rest args) `(msg! (color 1 (color 33 ,@args)))) +(defmacro success! (&rest args) `(msg! (color 1 (color 32 ,@args)))) +(defmacro section! (&rest args) `(msg! (color 34 ,@args))) +(defmacro explain! (&rest args) `(msg! (indented 2 (autofill ,@args)))) ;;; Polyfills ;; early versions of emacs won't have this @@ -233,7 +234,7 @@ (`timeout (error! "Timed out trying to contact %s" ex)) (_ (error! "Failed to validate %s" url) - (when (getenv "DEBUG") + (when doom-debug-mode (explain! (pp-to-string it))))))) (dolist (url '("https://self-signed.badssl.com" "https://wrong.host.badssl.com/")) @@ -275,50 +276,51 @@ ;; --- report! ------------------------------------------------ -(when (getenv "DEBUG") +(when doom-debug-mode (msg! "\n====\nHave some debug information:\n") (when (bound-and-true-p doom-modules) (msg! " + enabled modules:\n%s" - (indented 4 - (columns 3 23 - (mapcar (lambda (x) (format "+%s" x)) - (mapcar #'cdr (doom-module-pairs))))))) + (indented 4 + (columns 3 23 + (mapcar (lambda (x) (format "+%s" x)) + (mapcar #'cdr (doom-module-pairs))))))) (when (and (bound-and-true-p doom-packages) (require 'package nil t)) (msg! " + enabled packages:\n%s" - (indented 4 - (columns 2 35 - (mapcar (lambda (pkg) - (let ((desc (cadr (assq pkg package-alist)))) - (when desc - (package-desc-full-name desc)))) - (sort (mapcar #'car doom-packages) #'string-lessp)))))) + (indented 4 + (columns 2 35 + (delq nil + (mapcar (lambda (pkg) + (let ((desc (cadr (assq pkg package-alist)))) + (when desc + (package-desc-full-name desc)))) + (sort (mapcar #'car doom-packages) #'string-lessp))))))) (msg! " + byte-compiled files:\n%s" - (indented 4 - (columns 2 39 - (let ((files (append (directory-files-recursively doom-core-dir ".elc$") - (directory-files-recursively doom-modules-dir ".elc$")))) - (or (and files (mapcar (lambda (file) (file-relative-name file doom-emacs-dir)) - (nreverse files))) - (list "n/a")))))) + (indented 4 + (columns 2 39 + (let ((files (append (directory-files-recursively doom-core-dir ".elc$") + (directory-files-recursively doom-modules-dir ".elc$")))) + (or (and files (mapcar (lambda (file) (file-relative-name file doom-emacs-dir)) + (nreverse files))) + (list "n/a")))))) (msg! " + exec-path:\n%s" - (indented 4 - (columns 1 79 exec-path))) + (indented 4 + (columns 1 79 exec-path))) (msg! " + PATH:\n%s" - (indented 4 - (columns 1 79 (split-string (getenv "PATH") ":"))))) + (indented 4 + (columns 1 79 (split-string (getenv "PATH") ":"))))) ;; (if (= doom-errors 0) (success! "Everything seems fine, happy Emacs'ing!") (message "\n----") (warn! "There were issues!") - (unless (getenv "DEBUG") + (unless doom-debug-mode (msg! "\nHopefully these can help you find problems. If not, run this doctor again with DEBUG=1:") (msg! "\n DEBUG=1 make doctor\n") (msg! "And file a bug report with its output at https://github.com/hlissner/.emacs.d/issues")))