Move emacs version check into doom-initialize

Also fixes void-function errors caused by (now removed)
doom-same-emacs-version-p not being defined in all the contexts it was
needed.

Where it was before was clumsy design.
This commit is contained in:
Henrik Lissner 2018-06-05 11:18:36 +02:00
parent 7b1a83079d
commit 282e0d6653
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
3 changed files with 33 additions and 32 deletions

View file

@ -117,13 +117,13 @@ modified."
(dolist (file (doom-files-in auto-dir :match "\\.el$" :full t))
(push file targets)))))
(if (and (not force-p)
(not doom-emacs-changed-p)
(file-exists-p doom-autoload-file)
(not (file-newer-than-file-p (expand-file-name "init.el" doom-private-dir)
doom-autoload-file))
(not (cl-loop for file in targets
if (file-newer-than-file-p file doom-autoload-file)
return t))
(doom-same-emacs-version-p))
return t)))
(ignore (print! (green "Doom core autoloads is up-to-date"))
(doom-initialize-autoloads doom-autoload-file))
(doom-delete-autoloads-file doom-autoload-file)
@ -197,14 +197,14 @@ FORCE-P (universal argument) is non-nil, regenerate it anyway.
This should be run whenever your `doom!' block or update your packages."
(interactive)
(if (and (not force-p)
(not doom-emacs-changed-p)
(file-exists-p doom-package-autoload-file)
(not (file-newer-than-file-p package-user-dir doom-package-autoload-file))
(not (ignore-errors
(cl-loop for key being the hash-keys of (doom-module-table)
for path = (doom-module-path (car key) (cdr key) "packages.el")
if (file-newer-than-file-p path doom-package-autoload-file)
return t)))
(doom-same-emacs-version-p))
return t))))
(ignore (print! (green "Doom package autoloads is up-to-date"))
(doom-initialize-autoloads doom-package-autoload-file))
(doom-delete-autoloads-file doom-package-autoload-file)
@ -317,8 +317,8 @@ If RECOMPILE-P is non-nil, only recompile out-of-date files."
(unless recompile-p
(doom//clean-byte-compiled-files))
(unless targets
(message "Regenerating autoloads files (if necessary)")
(let ((inhibit-message t)
doom-emacs-changed-p
noninteractive)
;; But first we must be sure that Doom and your private config have
;; been fully loaded. Which usually aren't so in an noninteractive

View file

@ -1,32 +1,5 @@
;;; -*- lexical-binding: t; no-byte-compile: t; -*-
;; Do an Emacs version check and warn the user if it has changed.
(defvar doom--last-emacs-file (concat doom-local-dir "emacs-version.el"))
(defvar doom--last-emacs-version nil)
(defun doom-refresh-emacs-version ()
(with-temp-file doom--last-emacs-file
(princ `(setq doom--last-emacs-version ,(prin1-to-string emacs-version))
(current-buffer))))
(defun doom-same-emacs-version-p ()
(if (or doom--last-emacs-version
(load doom--last-emacs-file t t t))
(equal emacs-version doom--last-emacs-version)
(setq doom--last-emacs-version emacs-version)
(doom-refresh-emacs-version)
t))
(unless (doom-same-emacs-version-p)
(unless (y-or-n-p
(format (concat "Your version of Emacs has changed from %s to %s, which may cause incompatibility\n"
"issues. Please run `bin/doom compile :plugins` afterwards to resolve any problems.\n\n"
"Continue?")
doom--last-emacs-version
emacs-version))
(error "Aborting"))
(doom-refresh-emacs-version))
;; Eagerly load these libraries because this module may be loaded in a session
;; that hasn't been fully initialized (where autoloads files haven't been
;; generated or `load-path' populated).

View file

@ -80,6 +80,10 @@ file.")
(defvar doom-reload-hook nil
"A list of hooks to run when `doom//reload-load-path' is called.")
(defvar doom-emacs-changed-p nil
"If non-nil, the running version of Emacs is different from the first time
Doom was setup, which can cause problems.")
(defvar doom--current-module nil)
(defvar doom--refreshed-p nil)
(defvar doom--stage 'init)
@ -171,6 +175,29 @@ If RETURN-P, return the message as a string instead of displaying it."
;; Bootstrap helpers
;;
(defvar doom--last-emacs-file (concat doom-local-dir "emacs-version.el"))
(defvar doom--last-emacs-version nil)
(defun doom-ensure-same-emacs-version-p ()
"Do an Emacs version check and set `doom-emacs-changed-p' if it has changed."
(if (load doom--last-emacs-file 'noerror 'nomessage 'nosuffix)
(setq doom-emacs-changed-p
(not (equal emacs-version doom--last-emacs-version)))
(with-temp-file doom--last-emacs-file
(princ `(setq doom--last-emacs-version ,(prin1-to-string emacs-version))
(current-buffer))))
(cond ((not doom-emacs-changed-p))
((y-or-n-p
(format
(concat "Your version of Emacs has changed from %s to %s, which may cause incompatibility\n"
"issues. Please run `bin/doom compile :plugins` afterwards to resolve any problems.\n\n"
"Continue?")
doom--last-emacs-version
emacs-version))
(delete-file doom--last-emacs-file))
(noninteractive (error "Aborting"))
((kill-emacs))))
(defun doom-ensure-packages-initialized (&optional force-p)
"Make sure package.el is initialized."
(when (or force-p (not package--initialized))
@ -248,6 +275,7 @@ to least)."
;; functions from. This includes everything in core/autoload/*.el and all
;; the autoload files in your enabled modules.
(unless (doom-initialize-autoloads doom-autoload-file force-p)
(doom-ensure-same-emacs-version-p)
(doom-ensure-core-directories)
(doom-ensure-packages-initialized force-p)
(doom-ensure-core-packages)