Refactor Doom core init process (again)

- Eager-load all core autoloaded libraries if autoloads file isn't
  present.
- Renames functions to be more descriptive of their true purpose:
  - doom-initialize-autoloads -> doom-load-autoloads-file
  - doom-load-env-vars -> doom-load-envvars-file
- Use doom-module-p instead of featurep! for backend use (the latter is
  mainly syntax sugar for module use, and evaluates at compile/expansion
  time, which may cause hash-table-p errors early in the startup
  process).
- Reorder plist library to prevent load order race condition with the
  functions using the macros that haven't been defined yet.
This commit is contained in:
Henrik Lissner 2019-07-22 22:28:43 +02:00
parent 23d111132a
commit 93f7520c79
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
11 changed files with 109 additions and 107 deletions

View file

@ -61,8 +61,8 @@ It is useful to only pull in changes performed by 'doom refresh' on the command
line."
(interactive "P")
;; TODO regenerate autoloads
(doom-initialize-autoloads doom-autoload-file)
(doom-initialize-autoloads doom-package-autoload-file))
(doom-load-autoloads-file doom-autoload-file)
(doom-load-autoloads-file doom-package-autoload-file))
;;;###autoload
(defun doom/reload-env ()
@ -75,7 +75,7 @@ Uses the same mechanism as 'bin/doom env reload'."
(sit-for 1))
(unless (file-readable-p doom-env-file)
(error "Failed to generate env file"))
(doom-load-env-vars doom-env-file))
(doom-load-envvars-file doom-env-file))
;;;###autoload
(defun doom/reload-theme ()

View file

@ -1,8 +1,5 @@
;;; core/autoload/packages.el -*- lexical-binding: t; -*-
(require 'straight)
;;
;;; Package metadata

View file

@ -1,39 +1,5 @@
;;; ../work/conf/doom-emacs/core/autoload/plist.el -*- lexical-binding: t; -*-
;;;###autoload
(defun doom-plist-get (plist prop &optional nil-value)
"Return PROP in PLIST, if it exists. Otherwise NIL-VALUE."
(if-let (val (plist-member plist prop))
(cadr val)
nil-value))
;;;###autoload
(defun doom-plist-merge (from-plist to-plist)
"Destructively merge FROM-PLIST onto TO-PLIST"
(while plist
(plist-put! old-plist (pop plist) (pop plist))))
;;;###autoload
(defun doom-plist-delete-nil (plist)
"Delete `nil' properties from a copy of PLIST."
(let (p)
(while plist
(if (car plist)
(setq p (plist-put p (car plist) (nth 1 plist))))
(setq plist (cddr plist)))
p))
;;;###autoload
(defun doom-plist-delete (plist prop)
"Delete PROP from a copy of PLIST."
(let (p)
(while plist
(if (not (eq prop (car plist)))
(setq p (plist-put p (car plist) (nth 1 plist))))
(setq plist (cddr plist)))
p))
;;
;;; Macros
@ -82,3 +48,40 @@ BODY."
,plist-sym
,(doom-keyword-intern (symbol-name prop))))))
,@body)))
;;
;;; Library
;;;###autoload
(defun doom-plist-get (plist prop &optional nil-value)
"Return PROP in PLIST, if it exists. Otherwise NIL-VALUE."
(if-let (val (plist-member plist prop))
(cadr val)
nil-value))
;;;###autoload
(defun doom-plist-merge (from-plist to-plist)
"Destructively merge FROM-PLIST onto TO-PLIST"
(while plist
(plist-put! old-plist (pop plist) (pop plist))))
;;;###autoload
(defun doom-plist-delete-nil (plist)
"Delete `nil' properties from a copy of PLIST."
(let (p)
(while plist
(if (car plist)
(plist-put! p (car plist) (nth 1 plist)))
(setq plist (cddr plist)))
p))
;;;###autoload
(defun doom-plist-delete (plist prop)
"Delete PROP from a copy of PLIST."
(let (p)
(while plist
(if (not (eq prop (car plist)))
(plist-put! p (car plist) (nth 1 plist)))
(setq plist (cddr plist)))
p))

View file

@ -111,7 +111,7 @@ If DIR is not a project, it will be indexed (but not cached)."
(call-interactively
;; Intentionally avoid `helm-projectile-find-file', because it runs
;; asynchronously, and thus doesn't see the lexical `default-directory'
(if (featurep! :completion ivy)
(if (doom-module-p :completion 'ivy)
#'counsel-projectile-find-file
#'projectile-find-file)))
((fboundp 'project-find-file-in) ; emacs 26.1+ only
@ -127,8 +127,8 @@ If DIR is not a project, it will be indexed (but not cached)."
"Traverse a file structure starting linearly from DIR."
(let ((default-directory (file-truename (expand-file-name dir))))
(call-interactively
(cond ((featurep! :completion ivy)
(cond ((doom-module-p :completion 'ivy)
#'counsel-find-file)
((featurep! :completion helm)
((doom-module-p :completion 'helm)
#'helm-find-files)
(#'find-file)))))