2018-06-05 16:09:03 +02:00
|
|
|
;;; config/literate/autoload.el -*- lexical-binding: t; -*-
|
|
|
|
|
2020-05-26 00:59:44 -04:00
|
|
|
(defvar +literate-config-file
|
|
|
|
(concat doom-private-dir "config.org")
|
|
|
|
"The file path of your literate config file.")
|
|
|
|
|
|
|
|
(defvar +literate-config-cache-file
|
|
|
|
(concat doom-cache-dir "literate-last-compile")
|
|
|
|
"The file path that `+literate-config-file' will be tangled to, then
|
|
|
|
byte-compiled from.")
|
|
|
|
|
|
|
|
;;;###autoload
|
2020-07-25 22:33:52 -04:00
|
|
|
(defun +literate-tangle-h ()
|
2020-05-26 00:59:44 -04:00
|
|
|
"Tangles `+literate-config-file' if it has changed."
|
2020-07-25 22:33:52 -04:00
|
|
|
(print! (start "Compiling your literate config..."))
|
|
|
|
(print-group!
|
|
|
|
(let* ((default-directory doom-private-dir)
|
2020-07-31 01:39:24 -04:00
|
|
|
(org (expand-file-name +literate-config-file))
|
2020-08-04 13:58:40 -04:00
|
|
|
(dest (concat (file-name-sans-extension +literate-config-file) ".el"))
|
|
|
|
;; Operate on a copy because `org-babel-tangle' has side-effects we
|
|
|
|
;; don't want to impose on the User's config permanently.
|
|
|
|
(backup (make-temp-file (concat (file-name-nondirectory org) "."))))
|
|
|
|
(unwind-protect
|
|
|
|
(and (require 'ox)
|
|
|
|
(require 'ob-tangle)
|
2020-07-25 22:33:52 -04:00
|
|
|
(letf! ((defun message (msg &rest args)
|
|
|
|
(when msg
|
|
|
|
(print! (info "%s") (apply #'format msg args))))
|
2020-07-31 01:39:24 -04:00
|
|
|
;; Prevent infinite recursion due to recompile-on-save
|
|
|
|
;; hooks later.
|
2020-08-04 13:58:40 -04:00
|
|
|
(org-mode-hook nil))
|
2020-07-25 22:33:52 -04:00
|
|
|
(copy-file org backup t)
|
2020-08-04 13:43:14 -04:00
|
|
|
(with-current-buffer (find-file-noselect backup)
|
|
|
|
;; Tangling won't ordinarily expand #+INCLUDE directives
|
2020-07-25 22:33:52 -04:00
|
|
|
(org-export-expand-include-keyword)
|
2020-08-04 13:43:14 -04:00
|
|
|
(org-babel-tangle nil dest)
|
|
|
|
(kill-buffer (current-buffer)))
|
2020-07-25 22:33:52 -04:00
|
|
|
t)
|
2020-08-04 13:58:40 -04:00
|
|
|
;; Write an empty file to serve as our mtime cache
|
|
|
|
(with-temp-file +literate-config-cache-file))
|
|
|
|
(ignore-errors (delete-file backup))))))
|
2020-05-26 00:59:44 -04:00
|
|
|
|
2020-05-25 16:03:34 -04:00
|
|
|
;;;###autoload
|
2020-07-24 15:21:44 -04:00
|
|
|
(add-hook 'org-mode-hook #'+literate-enable-recompile-h)
|
2020-05-25 16:03:34 -04:00
|
|
|
|
2018-06-05 16:09:03 +02:00
|
|
|
;;;###autoload
|
2019-03-28 01:59:25 -04:00
|
|
|
(defalias '+literate/reload #'doom/reload)
|
|
|
|
|
2020-07-24 15:21:44 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defun +literate-enable-recompile-h ()
|
|
|
|
"Enable literate-compiling-on-save in the current buffer."
|
|
|
|
(add-hook 'after-save-hook #'+literate-recompile-maybe-h nil 'local))
|
|
|
|
|
2019-03-28 01:59:25 -04:00
|
|
|
;;;###autoload
|
2019-07-18 15:27:20 +02:00
|
|
|
(defun +literate-recompile-maybe-h ()
|
2020-07-24 15:21:44 -04:00
|
|
|
"Recompile literate config to `doom-private-dir'.
|
2019-03-28 01:59:25 -04:00
|
|
|
|
|
|
|
We assume any org file in `doom-private-dir' is connected to your literate
|
|
|
|
config, and should trigger a recompile if changed."
|
2020-07-24 15:21:44 -04:00
|
|
|
(when (file-in-directory-p buffer-file-name doom-private-dir)
|
2020-07-25 22:33:52 -04:00
|
|
|
(+literate-tangle-h)))
|