Fix doom/reload (recompiles if necessary); simplify doom/compile

This commit is contained in:
Henrik Lissner 2017-03-27 23:22:53 -04:00
parent e199b3f7ed
commit 4d89fd1cc9

View file

@ -379,10 +379,9 @@ server, if necessary) by `doom/packages-install', `doom/packages-update' and
`doom/packages-autoremove'. " `doom/packages-autoremove'. "
(interactive) (interactive)
(if noninteractive (if noninteractive
(progn (ignore-errors
(require 'server) (require 'server)
(ignore-errors (server-eval-at "server" '(let (noninteractive) (doom/reload))))
(server-eval-at "server" '(let (noninteractive) (doom/reload)))))
(doom-initialize t) (doom-initialize t)
(doom/compile t) (doom/compile t)
(message "Reloaded %d packages" (length doom--package-load-path)))) (message "Reloaded %d packages" (length doom--package-load-path))))
@ -434,13 +433,10 @@ 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/compile (&optional recompile-p lite-p) (defun doom/compile (&optional lite-p)
"Byte compile your emacs configuration (init.el, core/*.el & "Byte compile your emacs configuration (init.el, core/*.el &
modules/*/*/**.el). DOOM Emacs was designed to benefit from this, but it may modules/*/*/**.el). DOOM Emacs was designed to benefit from this, but it 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.
@ -452,13 +448,11 @@ accompanying *.elc file."
results) results)
(unless lite-p (unless lite-p
(dolist (path (doom--module-paths)) (dolist (path (doom--module-paths))
(nconc targets (nreverse (directory-files-recursively path "\\.el$"))))) (nconc targets (append (reverse (directory-files path t "\\.el$" t))
(when recompile-p (reverse (file-expand-wildcards (expand-file-name "*/*.el" path)))))))
(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)
(byte-recompile-file file nil (unless recompile-p 0))) (byte-recompile-file file t 0))
results)) results))
(let* ((n-fail (cl-count-if (lambda (x) (null (cdr x))) results)) (let* ((n-fail (cl-count-if (lambda (x) (null (cdr x))) results))
(n-nocompile (cl-count-if (lambda (x) (eq (cdr x) 'no-byte-compile)) results)) (n-nocompile (cl-count-if (lambda (x) (eq (cdr x) 'no-byte-compile)) results))
@ -468,16 +462,15 @@ accompanying *.elc file."
(message "\n")) (message "\n"))
(when (> n-fail 0) (when (> n-fail 0)
(message "\n%s" (mapconcat (lambda (file) (concat "+ ERROR: " (car file))) (message "\n%s" (mapconcat (lambda (file) (concat "+ ERROR: " (car file)))
(cl-remove-if 'cdr (reverse results)) "\n"))) (cl-remove-if-not 'cdr (reverse results)) "\n")))
(message "%s %s file(s)" (message "Compiled %s file(s)"
(if recompile-p "Recompiled" "Compiled")
(format (if (= total 0) "%s" "%s/%s") total-success total))))) (format (if (= total 0) "%s" "%s/%s") total-success total)))))
(defun doom/compile-lite (&optional recompile-p) (defun doom/compile-lite ()
"A light-weight version of `doom/compile' which only compiles core files in "A light-weight version of `doom/compile' which only compiles core files in
your emacs configuration (init.el and core/**/*.el)." your emacs configuration (init.el and core/**/*.el)."
(interactive) (interactive)
(doom/compile recompile-p t)) (doom/compile 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