doom-doctor: minor refactor

This commit is contained in:
Henrik Lissner 2017-12-31 17:49:15 -05:00
parent b0e6ba769e
commit c550851500
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

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