Major refactor of the Doctor
- Reorganize tests into logical groups - Report Doom initialization with more granularity - Make better use of whitespace and indentation in output - Use backquotes for quoting symbols in pcase (for backward compatibility) - Initialize Doom completely and manually (less maintanence headache and more certain to work across Doom updates).
This commit is contained in:
parent
25a86c18c8
commit
0caf0abcbb
1 changed files with 244 additions and 197 deletions
151
bin/doom-doctor
151
bin/doom-doctor
|
@ -8,10 +8,11 @@
|
|||
;; that uses a series of simple heuristics to diagnose common issues on your
|
||||
;; system. Issues that could intefere with Doom Emacs.
|
||||
;;
|
||||
;; Doom module may optionally have a doctor.el file to run their own heuristics
|
||||
;; in. Doctor scripts may run in versions of Emacs as old as Emacs 23, so you
|
||||
;; are limited to very basic standard library calls (e.g. avoid cl, subr-x, and
|
||||
;; any Doom dependencies).
|
||||
;; Doom modules may optionally have a doctor.el file to run their own heuristics
|
||||
;; in. Doctor scripts may run in versions of Emacs as old as Emacs 23, so make
|
||||
;; no assumptions about the standard library limited to very basic standard
|
||||
;; library (e.g. avoid cl/cl-lib, subr-x, map, seq, etc).
|
||||
|
||||
|
||||
;; Ensure Doom doctor always runs out of the current Emacs directory (optionally
|
||||
;; specified by the EMACSDIR envvar)
|
||||
|
@ -28,7 +29,8 @@
|
|||
|
||||
(require 'pp)
|
||||
|
||||
;;
|
||||
|
||||
;;; Helpers
|
||||
(defvar doom-init-p nil)
|
||||
(defvar doom-warnings 0)
|
||||
(defvar doom-errors 0)
|
||||
|
@ -83,6 +85,13 @@
|
|||
(defmacro explain! (&rest args)
|
||||
`(message (indented (+ indent 2) (autofill ,@args))))
|
||||
|
||||
(defun elc-check-dir (dir)
|
||||
(dolist (file (directory-files-recursively dir "\\.elc$"))
|
||||
(when (file-newer-than-file-p (concat (file-name-sans-extension file) ".el")
|
||||
file)
|
||||
(warn! "%s is out-of-date" (abbreviate-file-name file)))))
|
||||
|
||||
|
||||
;;; Polyfills
|
||||
;; early versions of emacs won't have this
|
||||
(unless (fboundp 'string-match-p)
|
||||
|
@ -103,14 +112,14 @@
|
|||
(msg! (color 1 "Doom Doctor"))
|
||||
(msg! "Emacs v%s" emacs-version)
|
||||
(msg! "Doom v%s (%s)"
|
||||
(or (and (file-exists-p (expand-file-name "core/core.el" user-emacs-directory))
|
||||
(or (let ((core-file (expand-file-name "core/core.el" user-emacs-directory)))
|
||||
(and (file-exists-p core-file)
|
||||
(with-temp-buffer
|
||||
(insert-file-contents-literally
|
||||
(expand-file-name "core/core.el" user-emacs-directory))
|
||||
(insert-file-contents-literally core-file)
|
||||
(goto-char (point-min))
|
||||
(when (re-search-forward "doom-version")
|
||||
(when (re-search-forward "doom-version" nil t)
|
||||
(forward-char)
|
||||
(sexp-at-point))))
|
||||
(sexp-at-point)))))
|
||||
"???")
|
||||
(if (and (executable-find "git")
|
||||
(file-directory-p (expand-file-name ".git" user-emacs-directory)))
|
||||
|
@ -125,9 +134,13 @@
|
|||
(message "Compiled with:\n%s" (indented 2 system-configuration-features)))
|
||||
(message "uname -msrv:\n%s\n" (indented 2 (sh "uname -msrv")))
|
||||
|
||||
|
||||
;; --- is emacs set up properly? ------------------------------
|
||||
|
||||
(when (version< emacs-version "25.3")
|
||||
(section! "Checking Emacs")
|
||||
(let ((indent 4))
|
||||
(section! "Checking your Emacs version is 25.3 or newer...")
|
||||
(when (version< emacs-version "25.3")
|
||||
(error! "Important: Emacs %s detected [%s]" emacs-version (executable-find "emacs"))
|
||||
(explain!
|
||||
"DOOM only supports >= 25.3. Perhaps your PATH wasn't set up properly."
|
||||
|
@ -135,39 +148,58 @@
|
|||
(concat "\nMacOS users should use homebrew (https://brew.sh) to install Emacs\n"
|
||||
" brew install emacs --with-modules --with-imagemagick --with-cocoa"))))
|
||||
|
||||
(let ((xdg-dir (concat (or (getenv "XDG_CONFIG_HOME")
|
||||
(section! "Checking if your version of Emacs has changed recently...")
|
||||
(let ((version-file (expand-file-name ".local/emacs-version.el" user-emacs-directory))
|
||||
doom--last-emacs-version)
|
||||
(when (and (load version-file 'noerror 'nomessage 'nosuffix)
|
||||
(not (equal emacs-version doom--last-emacs-version)))
|
||||
(warn! "Your version of Emacs has changed from %S to %S. Recompile your packages!"
|
||||
doom--last-emacs-version
|
||||
emacs-version)
|
||||
(explain! "Byte-code compiled in one version of Emacs may not work in another version."
|
||||
"It is recommended that you reinstall your plugins or recompile them with"
|
||||
"`bin/doom compile :plugins'.")))
|
||||
|
||||
(section! "Checking for private config conflicts...")
|
||||
(let ((xdg-dir (concat (or (getenv "XDG_CONFIG_HOME")
|
||||
"~/.config")
|
||||
"/doom/"))
|
||||
(doom-dir "~/.doom.d/"))
|
||||
(when (and (file-directory-p xdg-dir)
|
||||
(doom-dir (or (getenv "DOOMDIR")
|
||||
"~/.doom.d/")))
|
||||
(when (and (not (file-equal-p xdg-dir doom-dir))
|
||||
(file-directory-p xdg-dir)
|
||||
(file-directory-p doom-dir))
|
||||
(warn! "Detected two private configs, in %s and %s"
|
||||
(abbreviate-file-name xdg-dir)
|
||||
doom-dir)
|
||||
(explain! "The second directory will be ignored, as it has lower precedence.")))
|
||||
|
||||
(section! "Checking for stale elc files...")
|
||||
(elc-check-dir user-emacs-directory))
|
||||
|
||||
|
||||
;; --- is the environment set up properly? --------------------
|
||||
|
||||
;; on windows?
|
||||
(section! "Checking your OS...")
|
||||
(when (memq system-type '(windows-nt ms-dos cygwin))
|
||||
(section! "Checking your system...")
|
||||
(let ((indent 4))
|
||||
;; on windows?
|
||||
(when (memq system-type '(windows-nt ms-dos cygwin))
|
||||
(warn! "Warning: Windows detected")
|
||||
(explain! "DOOM was designed for MacOS and Linux. Expect a bumpy ride!"))
|
||||
|
||||
;; are all default fonts present?
|
||||
(section! "Checking your fonts...")
|
||||
(if (not (fboundp 'find-font))
|
||||
;; are all default fonts present?
|
||||
(section! "Checking your fonts...")
|
||||
(if (not (fboundp 'find-font))
|
||||
(progn
|
||||
(warn! "Warning: unable to detect font")
|
||||
(explain! "The `find-font' function is missing. This could indicate the incorrect "
|
||||
"version of Emacs is being used!"))
|
||||
;; all-the-icons fonts
|
||||
(let ((font-dest (pcase system-type
|
||||
('gnu/linux (concat (or (getenv "XDG_DATA_HOME")
|
||||
(`gnu/linux (concat (or (getenv "XDG_DATA_HOME")
|
||||
"~/.local/share")
|
||||
"/fonts/"))
|
||||
('darwin "~/Library/Fonts/"))))
|
||||
(`darwin "~/Library/Fonts/"))))
|
||||
(when (and font-dest (require 'all-the-icons nil t))
|
||||
(dolist (font all-the-icons-font-names)
|
||||
(if (file-exists-p (expand-file-name font font-dest))
|
||||
|
@ -178,9 +210,9 @@
|
|||
"This could also mean you've installed them in non-standard locations, in which "
|
||||
"case feel free to ignore this warning."))))))
|
||||
|
||||
;; gnutls-cli & openssl
|
||||
(section! "Checking gnutls/openssl...")
|
||||
(cond ((executable-find "gnutls-cli"))
|
||||
;; gnutls-cli & openssl
|
||||
(section! "Checking gnutls/openssl...")
|
||||
(cond ((executable-find "gnutls-cli"))
|
||||
((executable-find "openssl")
|
||||
(let* ((output (sh "openssl ciphers -v"))
|
||||
(protocols
|
||||
|
@ -214,9 +246,9 @@
|
|||
"network, provider, government, neckbearded mother-in-laws, geeky roommates, "
|
||||
"or just about anyone who knows more about computers than you do!")))
|
||||
|
||||
;; are certificates validated properly?
|
||||
(section! "Testing your root certificates...")
|
||||
(cond ((not (ignore-errors (gnutls-available-p)))
|
||||
;; are certificates validated properly?
|
||||
(section! "Testing your root certificates...")
|
||||
(cond ((not (ignore-errors (gnutls-available-p)))
|
||||
(warn! "Warning: Emacs wasn't installed with gnutls support")
|
||||
(explain!
|
||||
"This may cause 'pecular error' errors with the Doom doctor, and is likely to "
|
||||
|
@ -263,9 +295,9 @@
|
|||
|
||||
((error! "Nope!")))
|
||||
|
||||
;; which variant of tar is on your system? bsd or gnu tar?
|
||||
(section! "Checking for GNU/BSD tar...")
|
||||
(let ((tar-bin (or (executable-find "gtar")
|
||||
;; which variant of tar is on your system? bsd or gnu tar?
|
||||
(section! "Checking for GNU/BSD tar...")
|
||||
(let ((tar-bin (or (executable-find "gtar")
|
||||
(executable-find "tar"))))
|
||||
(if tar-bin
|
||||
(unless (string-match-p "(GNU tar)" (sh (format "%s --version" tar-bin)))
|
||||
|
@ -280,38 +312,53 @@
|
|||
(error! "Important: Couldn't find tar")
|
||||
(explain!
|
||||
"This is required by package.el and QUELPA to build packages and will "
|
||||
"prevent you from installing & updating packages.")))
|
||||
"prevent you from installing & updating packages."))))
|
||||
|
||||
|
||||
;; --- are your modules set up properly? ----------------------
|
||||
;; --- is Doom Emacs set up correctly? ------------------------
|
||||
|
||||
(condition-case-unless-debug ex
|
||||
(progn
|
||||
(let ((inhibit-message t)
|
||||
(after-init-time (current-time))
|
||||
(let ((after-init-time (current-time))
|
||||
noninteractive)
|
||||
(delq 'core features)
|
||||
(load-file (concat user-emacs-directory "init.el"))
|
||||
(section! "Checking DOOM Emacs...")
|
||||
(load (concat user-emacs-directory "core/core.el") nil t)
|
||||
(unless (file-directory-p doom-private-dir)
|
||||
(error "No DOOMDIR was found, did you run `doom quickstart` yet?"))
|
||||
|
||||
(let ((indent 4))
|
||||
;; Make sure everything is loaded
|
||||
(require 'core-cli)
|
||||
(require 'core-keybinds)
|
||||
(require 'core-ui)
|
||||
(require 'core-projects)
|
||||
(require 'core-editor)
|
||||
(require 'core-packages)
|
||||
(success! "Loaded Doom Emacs %s" doom-version)
|
||||
|
||||
;; ...and initialized
|
||||
(doom-initialize)
|
||||
(success! "Initialized Doom Emacs" doom-version)
|
||||
|
||||
(doom-initialize-modules)
|
||||
(if (hash-table-p doom-modules)
|
||||
(success! "Initialized %d modules" (hash-table-count doom-modules))
|
||||
(warn! "Failed to load any modules. Do you have an private init.el?"))
|
||||
|
||||
(doom-initialize-packages)
|
||||
(success! "Attempt to load DOOM: success! Loaded v%s" doom-version))
|
||||
(success! "Initialized %d packages" (length doom-packages))
|
||||
|
||||
(section! "Checking Doom core for irregularities...")
|
||||
(let ((indent 4))
|
||||
(let ((indent (+ indent 2)))
|
||||
(load (expand-file-name "doctor.el" doom-core-dir) nil 'nomessage))
|
||||
|
||||
(section! "Checking for stale elc files...")
|
||||
(let ((elc-files (doom-files-in (list doom-emacs-dir doom-private-dir)
|
||||
:match "\\.elc$"
|
||||
:depth 2)))
|
||||
(dolist (file elc-files)
|
||||
(when (file-newer-than-file-p (concat (file-name-sans-extension file) ".el")
|
||||
file)
|
||||
(warn! "%s is out-of-date" (abbreviate-file-name file)))))
|
||||
(section! "Checking for stale elc files in your DOOMDIR...")
|
||||
(when (file-directory-p doom-private-dir)
|
||||
(let ((indent (+ indent 2)))
|
||||
(elc-check-dir doom-private-dir)))
|
||||
|
||||
(when (bound-and-true-p doom-modules)
|
||||
(when doom-modules
|
||||
(section! "Checking your enabled modules...")
|
||||
(let ((indent 4))
|
||||
(let ((indent (+ indent 2)))
|
||||
(advice-add #'require :around #'doom*shut-up)
|
||||
(maphash
|
||||
(lambda (key plist)
|
||||
|
@ -333,9 +380,9 @@
|
|||
(load doctor-file 'noerror 'nomessage)))
|
||||
(file-missing (error! "%s" (error-message-string ex)))
|
||||
(error (error! "Syntax error: %s" ex)))))
|
||||
doom-modules))))
|
||||
doom-modules)))))
|
||||
(error
|
||||
(warn! "Attempt to load DOOM: failed\n %s\n"
|
||||
(warn! "Attempt to load DOOM failed\n %s\n"
|
||||
(or (cdr-safe ex) (car ex)))
|
||||
(setq doom-modules nil)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue