Refactor config/literate module
+ Now recompiles literate config if you modify org files in DOOMDIR + Replaced +literate/compile with +literate/reload + Calls org-babel-tangle-file directly if org package is loaded + Change mtime check mechanism for literate tangling at startup
This commit is contained in:
parent
b3d931d7ce
commit
5cdc2127be
2 changed files with 35 additions and 21 deletions
|
@ -1,7 +1,14 @@
|
||||||
;;; config/literate/autoload.el -*- lexical-binding: t; -*-
|
;;; config/literate/autoload.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +literate/compile (&optional load)
|
(defalias '+literate/reload #'doom/reload)
|
||||||
"TODO"
|
|
||||||
(interactive "P")
|
;;;###autoload
|
||||||
(+literate-compile load))
|
(defun +literate|recompile-maybe ()
|
||||||
|
"Recompile config.org if we're editing an org file in our DOOMDIR.
|
||||||
|
|
||||||
|
We assume any org file in `doom-private-dir' is connected to your literate
|
||||||
|
config, and should trigger a recompile if changed."
|
||||||
|
(when (and (eq major-mode 'org-mode)
|
||||||
|
(file-in-directory-p buffer-file-name doom-private-dir))
|
||||||
|
(+literate-tangle 'force)))
|
||||||
|
|
|
@ -4,34 +4,41 @@
|
||||||
(expand-file-name "config.org" doom-private-dir)
|
(expand-file-name "config.org" doom-private-dir)
|
||||||
"The file path of your literate config file.")
|
"The file path of your literate config file.")
|
||||||
|
|
||||||
(defvar +literate-config-dest-file
|
(defvar +literate-config-cache-file
|
||||||
(expand-file-name "config.el" doom-private-dir)
|
(expand-file-name "literate-last-compile" doom-cache-dir)
|
||||||
"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.")
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
(defun +literate-compile (&optional load)
|
(defun +literate-tangle (&optional force-p)
|
||||||
"Tangles & compiles `+literate-config-file' if it has changed. If LOAD is
|
"Tangles `+literate-config-file' if it has changed."
|
||||||
non-nil, load it too!"
|
(let ((default-directory doom-private-dir)
|
||||||
(let ((org +literate-config-file)
|
(org +literate-config-file))
|
||||||
(el +literate-config-dest-file))
|
(when (or force-p (file-newer-than-file-p org +literate-config-cache-file))
|
||||||
(when (file-newer-than-file-p org el)
|
|
||||||
(message "Compiling your literate config...")
|
(message "Compiling your literate config...")
|
||||||
|
|
||||||
;; We tangle in a separate, blank process because loading it here would
|
(or (and (if (fboundp 'org-babel-tangle-file)
|
||||||
;; load all of :lang org (very expensive!). We only need ob-tangle.
|
(org-babel-tangle-file org nil "emacs-lisp")
|
||||||
(or (zerop (call-process
|
;; We tangle in a separate, blank process because loading it here
|
||||||
"emacs" nil nil nil
|
;; would load all of :lang org (very expensive!).
|
||||||
"-q" "--batch" "-l" "ob-tangle" "--eval"
|
(zerop (call-process
|
||||||
(format "(org-babel-tangle-file \"%s\" \"%s\" \"emacs-lisp\")"
|
"emacs" nil nil nil
|
||||||
org el)))
|
"-q" "--batch" "-l" "ob-tangle" "--eval"
|
||||||
|
(format "(org-babel-tangle-file %S nil \"emacs-lisp\")"
|
||||||
|
org))))
|
||||||
|
;; Write the cache file to serve as our mtime cache
|
||||||
|
(with-temp-file +literate-config-cache-file t))
|
||||||
(warn "There was a problem tangling your literate config!"))
|
(warn "There was a problem tangling your literate config!"))
|
||||||
|
|
||||||
(message "Done!"))))
|
(message "Done!"))))
|
||||||
|
|
||||||
;; Let 'er rip!
|
;; Let 'er rip!
|
||||||
(+literate-compile)
|
(+literate-tangle doom-reloading-p)
|
||||||
|
|
||||||
;; 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.
|
||||||
|
|
||||||
|
|
||||||
|
;; Recompile our literate config if we modify it
|
||||||
|
(after! org
|
||||||
|
(add-hook 'after-save-hook #'+literate|recompile-maybe))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue