From 776bc9697711449d06af0cb14f36a1bafe535dc3 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 20 Feb 2017 13:12:24 -0500 Subject: [PATCH] Refactor doom/autoloads init process --- Makefile | 17 +++++++---------- core/core-packages.el | 36 ++++++++++++++++++------------------ core/core.el | 6 +++--- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 8dea39f99..16edb5258 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,14 @@ EMACS=emacs --batch --eval "(setq user-emacs-directory default-directory)" # Tasks all: install update autoloads -install: init.el .local/autoloads.el - @$(EMACS) -l core/core.el -f 'doom/packages-install' +install: init.el + @$(EMACS) -l core/core.el -f 'doom-initialize-autoloads' -f 'doom/packages-install' -update: init.el .local/autoloads.el - @$(EMACS) -l core/core.el -f 'doom/packages-update' +update: init.el + @$(EMACS) -l core/core.el -f 'doom-initialize-autoloads' -f 'doom/packages-update' -autoremove: init.el .local/autoloads.el - @$(EMACS) -l core/core.el -f 'doom/packages-autoremove' +autoremove: init.el + @$(EMACS) -l core/core.el -f 'doom-initialize-autoloads' -f 'doom/packages-autoremove' autoloads: init.el @$(EMACS) -l core/core.el -f 'doom/reload-autoloads' @@ -33,9 +33,6 @@ run: @emacs --eval "(setq user-emacs-directory default-directory)" -q -l init.el init.el: - @[ -f init.el ] || $(error No init.el file; create one or copy init.example.el) - -.local/autoloads.el: - @$(EMACS) -l core/core.el -f 'doom/reload-autoloads' + @[ -e init.el ] || $(error No init.el file; create one or copy init.example.el) .PHONY: all test diff --git a/core/core-packages.el b/core/core-packages.el index 99f500bed..251faafb8 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -142,14 +142,11 @@ to speed up startup." (setq doom-init-p t))) -(defun doom-initialize-autoloads (&optional force-p) +(defun doom-initialize-autoloads (&optional inhibit-reload-p) "Ensures that `doom-autoload-file' exists and is loaded. Otherwise run `doom/reload-autoloads' to generate it." - (unless (ignore-errors (require 'autoloads doom-autoload-file t)) - (unless noninteractive - (doom/reload-autoloads) - (unless (file-exists-p doom-autoload-file) - (error "Autoloads file couldn't be generated"))))) + (unless (file-exists-p doom-autoload-file) + (@quiet (doom/reload-autoloads)))) (defun doom-initialize-packages (&optional force-p load-p) "Crawls across your emacs.d in order to fill `doom-modules' (from init.el) and @@ -387,7 +384,7 @@ In modules, checks modules/*/autoload.el and modules/*/autoload/*.el. Rerun this whenever init.el is modified. You can also use `make autoloads` from the commandline." (interactive) - (doom-initialize-packages noninteractive) + (doom-initialize-packages (not noninteractive)) (let ((generated-autoload-file doom-autoload-file) (autoload-files (file-expand-wildcards @@ -413,18 +410,21 @@ the commandline." (update-file-autoloads file)) (message "Scanned %s" (file-relative-name file doom-emacs-dir))) (condition-case ex - (with-current-buffer (get-file-buffer generated-autoload-file) - (save-buffer) - (eval-buffer) - (message "Done!")) - ('error (error "Couldn't evaluate autoloads.el: %s" (cadr ex)))))) + (let ((buf (get-file-buffer generated-autoload-file))) + (unwind-protect + (with-current-buffer buf + (save-buffer) + (eval-buffer) + (message "Finished generating autoloads.el!")) + (kill-buffer buf))) + ('error + (delete-file generated-autoload-file) + (error "Couldn't evaluate autoloads.el: %s" (cadr ex)))))) -(defun doom/recompile (&optional simple-p) - "Byte (re)compile the important files in your emacs configuration (init.el & -core/*.el). DOOM Emacs was designed to benefit from this. - -If SIMPLE-P is nil, also byte-compile modules/*/*/*.el (except for packages.el). -There should be a measurable benefit from this, but it may take a while." +(defun doom/recompile () + "Byte (re)compile the important files in your emacs configuration (init.el, +core/*.el & modules/*/*/**.el). DOOM Emacs was designed to benefit from this. +This may take a while." (interactive) ;; Ensure all relevant config files are loaded. This way we don't need ;; eval-when-compile and require blocks scattered all over. diff --git a/core/core.el b/core/core.el index 162395be0..285ae34cc 100644 --- a/core/core.el +++ b/core/core.el @@ -46,8 +46,7 @@ line or use --debug-init to enable this.") (defvar doom-autoload-file (concat doom-local-dir "autoloads.el") - "Location of the autoloads.el, which is generated by `doom/reload-autoloads' -and `doom-initialize-autoloads'.") + "Location of the autoloads file generated by `doom/reload-autoloads'.") (defgroup doom nil "" @@ -139,7 +138,8 @@ enable multiple minor modes for the same regexp.") ;;; Let 'er rip (require 'core-lib) (require 'core-os) ; consistent behavior across Oses - (doom-initialize-autoloads) + (with-demoted-errors "AUTOLOAD ERROR: %s" + (require 'autoloads doom-autoload-file t)) (unless noninteractive (require 'core-ui) ; draw me like one of your French editors