config/literate: always tangle asynchronously

Should also fix errors during tangling while running `bin/doom`
commands.
This commit is contained in:
Henrik Lissner 2019-07-28 23:28:38 +02:00
parent e3d6d13be5
commit 61b7451b52
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -1,11 +1,11 @@
;;; config/literate/init.el -*- lexical-binding: t; -*- ;;; config/literate/init.el -*- lexical-binding: t; -*-
(defvar +literate-config-file (defvar +literate-config-file
(expand-file-name "config.org" doom-private-dir) (concat doom-private-dir "config.org")
"The file path of your literate config file.") "The file path of your literate config file.")
(defvar +literate-config-cache-file (defvar +literate-config-cache-file
(expand-file-name "literate-last-compile" doom-cache-dir) (concat doom-cache-dir "literate-last-compile")
"The file path that `+literate-config-file' will be tangled to, then "The file path that `+literate-config-file' will be tangled to, then
byte-compiled from.") byte-compiled from.")
@ -13,38 +13,34 @@ byte-compiled from.")
;; ;;
(defun +literate-tangle (&optional force-p) (defun +literate-tangle (&optional force-p)
"Tangles `+literate-config-file' if it has changed." "Tangles `+literate-config-file' if it has changed."
(let ((default-directory doom-private-dir) (let ((default-directory doom-private-dir))
(org +literate-config-file)) (when (or (file-newer-than-file-p +literate-config-file
(when (or force-p (file-newer-than-file-p org +literate-config-cache-file)) +literate-config-cache-file)
force-p)
(message "Compiling your literate config...") (message "Compiling your literate config...")
(let* ((org (file-truename +literate-config-file)) (let* ((org (file-truename +literate-config-file))
(dest (concat (file-name-sans-extension org) ".el"))) (dest (concat (file-name-sans-extension org) ".el"))
(or (and (if (fboundp 'org-babel-tangle-file) (output (get-buffer-create "*org-tangle*")))
(org-babel-tangle-file org dest "emacs-lisp") (unwind-protect
;; We tangle in a separate, blank process because loading it ;; We tangle in a separate, blank process because loading it here
;; here would load all of :lang org (very expensive!). ;; would load all of :lang org (very expensive!).
(zerop (call-process (or (and (zerop (call-process
"emacs" nil nil nil "emacs" nil output nil
"-q" "--batch" "-q" "--batch"
;; HACK See lang/org/init.el on why this is necessary "-l" "ob-tangle"
"--eval" "--eval" (format "(org-babel-tangle-file %S %S)"
(prin1-to-string '(defun org-release () "9.3")) org dest)))
"--eval" (with-current-buffer output
(prin1-to-string '(fset 'org-git-release #'ignore)) (message "%s" (buffer-string))
"-l" "ob-tangle" "--eval" t)
(format "(org-babel-tangle-file %S %S \"emacs-lisp\")" ;; Write the cache file to serve as our mtime cache
org dest)))) (with-temp-file +literate-config-cache-file
;; Write the cache file to serve as our mtime cache (message "Done!")))
(with-temp-file +literate-config-cache-file (warn "There was a problem tangling your literate config!"))
(message "Done!"))) (kill-buffer output))))))
(warn "There was a problem tangling your literate config!"))))))
;; Let 'er rip! ;; Let 'er rip!
(when noninteractive
(require 'ob-tangle nil t))
(+literate-tangle (or doom-reloading-p noninteractive)) (+literate-tangle (or doom-reloading-p noninteractive))
;; No need to load the resulting file. Doom will do this for us after all ;; No need to load the resulting file. Doom will do this for us after all
;; modules have finished loading. ;; modules have finished loading.