From b309ef154d8c743917b517986d595a955f59fa54 Mon Sep 17 00:00:00 2001
From: Aryadev Chavali <aryadev@aryadevchavali.com>
Date: Sun, 9 Aug 2020 17:32:09 +0100
Subject: +better literate config

This is a smarter Emacs literate config. The way it works is simple:

- If no config output files exist, compile them. Otherwise just load
the config

- Add a hook when exiting emacs such that the config is compiled and
ready for next call.

This makes it so that load time is fast and compile occurs at a more
opportune time than at init.
---
 Emacs/.config/emacs/init.el | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

(limited to 'Emacs')

diff --git a/Emacs/.config/emacs/init.el b/Emacs/.config/emacs/init.el
index 5015f68..7ab3170 100644
--- a/Emacs/.config/emacs/init.el
+++ b/Emacs/.config/emacs/init.el
@@ -1,7 +1,24 @@
 ;; Load literate
 (require 'ob-tangle)
 (setq user-emacs-directory "~/.config/emacs/")
-(mapc #'(lambda (x) (org-babel-load-file (concat user-emacs-directory x))) (list "config.org"))
+(defconst +literate/files (list "config.org"))
+(defconst +literate/output-files (mapcar #'(lambda (x) (replace-regexp-in-string ".org" ".el" x)) +literate/files))
+(message "%s" +literate/output-files)
+
+(defun +literate/load-config ()
+  (mapc #'(lambda (x) (load-file (concat user-emacs-directory x))) +literate/output-files))
+
+(defun +literate/compile-config ()
+  (mapc #'(lambda (x) (org-babel-tangle-file (concat user-emacs-directory x))) +literate/files))
+
+(defun +literate/files-exist ()
+  (cl-reduce #'(lambda (x y) (or x y)) (mapc #'(lambda (x) (file-exists-p (concat user-emacs-directory x))) +literate/output-files)))
+
+(add-hook 'kill-emacs-hook #'+literate/compile-config)
+(unless (+literate/files-exist)
+  (+literate/compile-config))
+
+(+literate/load-config)
 
 ;; Programming
 (custom-set-variables
-- 
cgit v1.2.3-13-gbd6f