2018-06-08 16:23:13 +02:00
|
|
|
;;; config/literate/init.el -*- lexical-binding: t; -*-
|
|
|
|
|
2018-06-05 16:09:03 +02:00
|
|
|
(defvar +literate-config-file
|
2019-07-28 23:28:38 +02:00
|
|
|
(concat doom-private-dir "config.org")
|
2018-06-05 16:09:03 +02:00
|
|
|
"The file path of your literate config file.")
|
2018-06-05 15:38:58 +02:00
|
|
|
|
2019-03-28 01:59:25 -04:00
|
|
|
(defvar +literate-config-cache-file
|
2019-07-28 23:28:38 +02:00
|
|
|
(concat doom-cache-dir "literate-last-compile")
|
2018-06-05 16:09:03 +02:00
|
|
|
"The file path that `+literate-config-file' will be tangled to, then
|
|
|
|
byte-compiled from.")
|
2018-06-05 15:38:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-03-28 01:59:25 -04:00
|
|
|
(defun +literate-tangle (&optional force-p)
|
|
|
|
"Tangles `+literate-config-file' if it has changed."
|
2019-07-28 23:28:38 +02:00
|
|
|
(let ((default-directory doom-private-dir))
|
|
|
|
(when (or (file-newer-than-file-p +literate-config-file
|
|
|
|
+literate-config-cache-file)
|
|
|
|
force-p)
|
2018-06-05 16:14:38 +02:00
|
|
|
(message "Compiling your literate config...")
|
2019-11-19 20:37:49 -05:00
|
|
|
(let* ((org (expand-file-name +literate-config-file))
|
2019-10-09 21:02:49 -05:00
|
|
|
(dest (concat (file-name-sans-extension +literate-config-file) ".el"))
|
2019-07-28 23:28:38 +02:00
|
|
|
(output (get-buffer-create "*org-tangle*")))
|
|
|
|
(unwind-protect
|
|
|
|
;; We tangle in a separate, blank process because loading it here
|
|
|
|
;; would load all of :lang org (very expensive!).
|
|
|
|
(or (and (zerop (call-process
|
|
|
|
"emacs" nil output nil
|
|
|
|
"-q" "--batch"
|
|
|
|
"-l" "ob-tangle"
|
|
|
|
"--eval" (format "(org-babel-tangle-file %S %S)"
|
|
|
|
org dest)))
|
|
|
|
(with-current-buffer output
|
|
|
|
(message "%s" (buffer-string))
|
|
|
|
t)
|
|
|
|
;; Write the cache file to serve as our mtime cache
|
|
|
|
(with-temp-file +literate-config-cache-file
|
|
|
|
(message "Done!")))
|
|
|
|
(warn "There was a problem tangling your literate config!"))
|
|
|
|
(kill-buffer output))))))
|
2018-06-08 16:23:13 +02:00
|
|
|
|
2018-06-05 15:38:58 +02:00
|
|
|
|
2018-06-05 16:09:03 +02:00
|
|
|
;; Let 'er rip!
|
2019-03-28 15:07:39 -04:00
|
|
|
(+literate-tangle (or doom-reloading-p noninteractive))
|
2018-06-05 15:38:58 +02:00
|
|
|
;; No need to load the resulting file. Doom will do this for us after all
|
|
|
|
;; modules have finished loading.
|
2019-03-28 01:59:25 -04:00
|
|
|
|
|
|
|
|
|
|
|
;; Recompile our literate config if we modify it
|
|
|
|
(after! org
|
2019-07-18 15:27:20 +02:00
|
|
|
(add-hook 'after-save-hook #'+literate-recompile-maybe-h))
|