core-packages: add doom/compile-lite and make compile-lite

This commit is contained in:
Henrik Lissner 2017-03-25 01:03:02 -04:00
parent 34b76ef43b
commit e8e66c88d0
2 changed files with 39 additions and 21 deletions

View file

@ -19,7 +19,10 @@ autoloads: init.el
@$(EMACS) -f 'doom/reload-autoloads' @$(EMACS) -f 'doom/reload-autoloads'
compile: init.el clean compile: init.el clean
@$(EMACS) -f 'doom/recompile' @$(EMACS) -f 'doom/compile'
compile-lite: init.el clean
@$(EMACS) -f 'doom/compile-lite'
clean: clean:
@$(EMACS) -f 'doom/clean-compiled' @$(EMACS) -f 'doom/clean-compiled'

View file

@ -229,9 +229,10 @@ files."
"Returns `doom-modules' as a list of (MODULE . SUBMODULE) cons cells. The list "Returns `doom-modules' as a list of (MODULE . SUBMODULE) cons cells. The list
is sorted by order of insertion." is sorted by order of insertion."
(let (pairs) (let (pairs)
(maphash (lambda (key value) (push (cons (car key) (cdr key)) pairs)) (when (hash-table-p doom-modules)
doom-modules) (maphash (lambda (key value) (push (cons (car key) (cdr key)) pairs))
(nreverse pairs))) doom-modules)
(nreverse pairs))))
(defun doom--module-paths (&optional append-file) (defun doom--module-paths (&optional append-file)
"Returns a list of absolute file paths to modules, with APPEND-FILE added, if "Returns a list of absolute file paths to modules, with APPEND-FILE added, if
@ -424,34 +425,48 @@ the commandline."
(delete-file generated-autoload-file) (delete-file generated-autoload-file)
(error "Couldn't evaluate autoloads.el: %s" (cadr ex)))))) (error "Couldn't evaluate autoloads.el: %s" (cadr ex))))))
(defun doom/recompile () (defun doom/compile (&optional recompile-p lite-p)
"Byte (re)compile the important files in your emacs configuration (init.el, "Byte compile your emacs configuration (init.el, core/*.el &
core/*.el & modules/*/*/**.el). DOOM Emacs was designed to benefit from this. modules/*/*/**.el). DOOM Emacs was designed to benefit from this, but it may
This may take a while." take a while.
If RECOMPILE-P is non-nil, don't byte-compile *.el files that don't have an
accompanying *.elc file."
(interactive) (interactive)
;; Ensure all relevant config files are loaded. This way we don't need ;; Ensure all relevant config files are loaded. This way we don't need
;; eval-when-compile and require blocks scattered all over. ;; eval-when-compile and require blocks scattered all over.
(doom-initialize-packages (not noninteractive) noninteractive) (doom-initialize-packages (not noninteractive) noninteractive)
(let ((targets (let ((targets
(append (list (expand-file-name "init.el" doom-emacs-dir) (append (list (expand-file-name "init.el" doom-emacs-dir))
(expand-file-name "core.el" doom-core-dir)) (reverse (directory-files-recursively doom-core-dir "\\.el$"))))
(file-expand-wildcards (expand-file-name "core-*.el" doom-core-dir))
(file-expand-wildcards (expand-file-name "autoload/*.el" doom-core-dir))))
(n 0) (n 0)
results) results)
(dolist (path (doom--module-paths)) (unless lite-p
(nconc targets (nreverse (directory-files-recursively path "\\.el$")))) (dolist (path (doom--module-paths))
(nconc targets (nreverse (directory-files-recursively path "\\.el$")))))
(when recompile-p
(setq targets (cl-remove-if-not (lambda (file) (file-exists-p (concat (file-name-sans-extension file) ".elc")))
targets)))
(dolist (file targets) (dolist (file targets)
(push (cons (file-relative-name file doom-emacs-dir) (push (cons (file-relative-name file doom-emacs-dir)
(and (byte-recompile-file file nil 0) (byte-recompile-file file nil (unless recompile-p 0)))
(setq n (1+ n))))
results)) results))
(when noninteractive (let* ((n-fail (cl-count-if (lambda (x) (null (cdr x))) results))
(if targets (message "\n")) (n-nocompile (cl-count-if (lambda (x) (eq (cdr x) 'no-byte-compile)) results))
(message "Compiled %s/%s files" n (length results)) (total (- (length results) n-nocompile))
(when-let (errors (cl-remove-if 'cdr results)) (total-success (- total n-fail)))
(when (> total-success 0)
(message "\n"))
(when (> n-fail 0)
(message "\n%s" (mapconcat (lambda (file) (concat "+ ERROR: " (car file))) (message "\n%s" (mapconcat (lambda (file) (concat "+ ERROR: " (car file)))
(nreverse errors) "\n")))))) (cl-remove-if 'cdr (reverse results)) "\n")))
(message "%s %s file(s)"
(if recompile-p "Recompiled" "Compiled")
(format (if (= total 0) "%s" "%s/%s") total-success total)))))
(defun doom/compile-lite (&optional recompile-p)
(interactive)
(doom/compile recompile-p t))
(defun doom/clean-cache () (defun doom/clean-cache ()
"Clear local cache (`doom-cache-dir'). You may need to restart Emacs for some "Clear local cache (`doom-cache-dir'). You may need to restart Emacs for some