doomemacs/bin/doctor

177 lines
6.3 KiB
Plaintext
Raw Normal View History

#!/bin/sh
":"; exec emacs --no-site-file --script "$0" -- "$@" # -*-emacs-lisp-*-
;; Uses a couple simple heuristics to locate issues with your environment that
;; could interfere with running or setting up DOOM Emacs.
(defconst IS-MAC (eq system-type 'darwin))
(require 'package)
2017-05-21 20:10:33 +08:00
(load "~/.emacs.d/core/autoload/message" nil t)
2017-05-21 20:10:33 +08:00
(unless (equal (expand-file-name user-emacs-directory)
(expand-file-name "~/.emacs.d/"))
(error "Couldn't find ~/.emacs.d"))
;;
(defvar doom-errors 0)
(defmacro check! (cond &rest body)
(declare (indent defun))
`(when ,cond
,@body
(setq doom-errors (1+ doom-errors))))
(defun indented (spc msg)
(declare (indent defun))
(with-temp-buffer
(insert msg)
(indent-rigidly (point-min) (point-max) spc)
(buffer-string)))
2017-05-21 20:10:33 +08:00
(defun autofill (&rest msgs)
(declare (indent defun))
(let ((fill-column 70))
(with-temp-buffer
(dolist (line msgs)
(when line
(insert line)))
(fill-region (point-min) (point-max))
(buffer-string))))
(defun columns (cols length strings)
(declare (indent defun))
(with-temp-buffer
(let ((sub-format (format "%%-%ds " (1- length)))
col-format)
2017-05-21 20:10:33 +08:00
(dotimes (i (1- cols))
(setq col-format (concat col-format sub-format)))
2017-05-21 20:10:33 +08:00
(setq col-format (concat col-format "%s"))
(while strings
(insert (apply #'format col-format
(let (args)
(dotimes (i cols (nreverse args))
(push (if strings (pop strings) "") args))))
"\n")))
(buffer-string)))
2017-05-21 20:10:33 +08:00
(defmacro error! (&rest args) `(message! (bold (red ,@args))))
(defmacro warn! (&rest args) `(message! (bold (yellow ,@args))))
(defmacro success! (&rest args) `(message! (bold (green ,@args))))
(defmacro explain! (&rest args) `(message! (indented 2 (autofill ,@args))))
;;
2017-05-21 21:24:45 +08:00
(message! "%s\nRunning Emacs v%s"
2017-05-21 20:10:33 +08:00
(bold "DOOM Doctor")
2017-05-21 21:24:45 +08:00
(bold emacs-version))
(message! "Compiled with:\n%s" (indented 2 (autofill system-configuration-features)))
(message! "uname -a:\n%s" (indented 2 (autofill (shell-command-to-string "uname -a"))))
(message "----\n")
;; --- is emacs set up properly? ------------------------------
(check! (version< emacs-version "25.1")
2017-05-21 20:10:33 +08:00
(error! "Important: Emacs %s detected [%s]" emacs-version (executable-find "emacs"))
(explain!
"DOOM only supports >= 25.1. Perhaps your PATH wasn't set up properly."
(when IS-MAC
(concat "\nMacOS users should use homebrew (https://brew.sh) to install Emacs\n"
" brew install emacs --with-modules --with-imagemagick --with-cocoa"))))
;; --- is the environment set up properly? --------------------
(check! (not (executable-find "git"))
2017-05-21 20:10:33 +08:00
(error! "Important: Couldn't find git"))
(check! (memq system-type '(windows-nt ms-dos cygwin))
2017-05-21 20:10:33 +08:00
(warn! "Warning: Windows detected")
(explain! "DOOM was designed for MacOS and Linux. Expect a bumpy ride!"))
(if (executable-find "tar")
(check! (not (string-match-p "(GNU tar)" (shell-command-to-string "tar --version")))
2017-05-21 20:10:33 +08:00
(warn! "Warning: BSD tar detected")
(explain!
"QUELPA (through package-build) uses the system tar to build plugins."
"BSD tar *could* cause errors during package installation or updating from"
"non-ELPA sources."
(when IS-MAC
(concat "\nMacOS users can install gnu-tar via homebrew:\n"
" brew install gnu-tar"))))
(check! nil (error! "Important: Couldn't find tar"))) ; very unlikely
(check! (not (executable-find "gnutls-cli"))
2017-05-21 20:10:33 +08:00
(cond ((executable-find "openssl")
(warn! "Warning: couldn't find gnutls-cli")
(explain! "...but found openssl (which is possibly less secure)"))
(t
(error! "Warning: neither gnutls-cli or openssl were found")
(explain! "You will be unable to install/update packages through secure sources (HTTPS)"))))
;; --- report! ------------------------------------------------
(when (getenv "DEBUG")
2017-05-21 20:10:33 +08:00
(message! "\n====\nHave some debug information:\n")
(let (doom-core-packages doom-debug-mode)
(condition-case ex
(progn
(let ((inhibit-message t))
(load "~/.emacs.d/core/core.el" nil t))
(doom-initialize-packages)
2017-05-21 20:10:33 +08:00
(success! " + Attempt to load DOOM: success! Loaded v%s" doom-version)
(when (executable-find "git")
2017-05-21 20:10:33 +08:00
(message! " Revision %s"
(or (ignore-errors
(let ((default-directory user-emacs-directory))
(shell-command-to-string "git rev-parse HEAD")))
"\n"))))
2017-05-21 20:10:33 +08:00
('error (warn! " + Attempt to load DOOM: failed\n %s\n" (or (cdr-safe ex) (car ex))))))
2017-05-21 20:10:33 +08:00
(message! " + Emacs directory: %s\n" user-emacs-directory)
(when (bound-and-true-p doom-modules)
2017-05-21 20:10:33 +08:00
(message! " + enabled modules:\n%s"
(indented 4
2017-05-21 20:10:33 +08:00
(columns 3 23
(mapcar (lambda (x) (format "+%s" x))
2017-05-21 20:10:33 +08:00
(mapcar #'cdr (doom--module-pairs)))))))
(when (bound-and-true-p doom-packages)
2017-05-21 20:10:33 +08:00
(message! " + enabled packages:\n%s"
(indented 4
2017-05-21 20:10:33 +08:00
(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))))))
2017-05-21 20:10:33 +08:00
(message! " + byte-compiled files:\n%s"
(indented 4
2017-05-21 20:10:33 +08:00
(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"))))))
2017-05-21 20:10:33 +08:00
(message! " + exec-path:\n%s"
(indented 4
2017-05-21 20:10:33 +08:00
(columns 1 79 exec-path)))
2017-05-21 20:10:33 +08:00
(message! " + PATH:\n%s"
(indented 4
2017-05-21 20:10:33 +08:00
(columns 1 79 (split-string (getenv "PATH") ":")))))
;;
(if (= doom-errors 0)
2017-05-21 20:10:33 +08:00
(success! "Everything seems fine, happy Emacs'ing!")
(message "\n----")
(warn! "There were issues!")
(unless (getenv "DEBUG")
2017-05-21 20:10:33 +08:00
(message! "\nHopefully these can help you find problems. If not, run this doctor again with DEBUG=1:")
(message! "\n DEBUG=1 make doctor\n")
(message! "And file a bug report with its output at https://github.com/hlissner/.emacs.d/issues")))