From f5fe36af23382896d7e2397a7a9d19231e99efbe Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Tue, 5 Jun 2018 15:38:58 +0200 Subject: [PATCH] Add :config literate module It will tangle and byte-compile a config.org in your private config. Doom will then load the resulting config.elc later. Org is only loaded when updating this file. --- init.example.el | 4 ++++ modules/config/literate/config.el | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 modules/config/literate/config.el diff --git a/init.example.el b/init.example.el index de355bca0..7d03efd15 100644 --- a/init.example.el +++ b/init.example.el @@ -128,6 +128,10 @@ ;impatient-mode ; show off code over HTTP :config + ;; For literate config users. This will tangle+compile a config.org + ;; literate config in your `doom-private-dir' whenever it changes. + ;literate + ;; The default module set reasonable defaults for Emacs. It also provides ;; a Spacemacs-inspired keybinding scheme, a custom yasnippet library, ;; and additional ex commands for evil-mode. Use it as a reference for diff --git a/modules/config/literate/config.el b/modules/config/literate/config.el new file mode 100644 index 000000000..47223c057 --- /dev/null +++ b/modules/config/literate/config.el @@ -0,0 +1,31 @@ +;;; config/literate/config.el -*- lexical-binding: t; -*- + +(defvar +literate-config-file "config.org" + "The literate config file, searched for in `doom-private-dir' (unless this is +an absolute path).") + +(defvar +literate-config-dest-file "config.el" + "The file that `+literate-config-file' will be tangled to, then byte-compiled +from.") + + +;; +(let ((org (expand-file-name +literate-config-file doom-private-dir)) + (elc (expand-file-name (concat +literate-config-dest-file "c") doom-private-dir))) + ;; If config is pre-compiled, then load that + (when (file-newer-than-file-p org elc) + ;; We tangle in a separate, blank process because loading it here would load + ;; all of :lang org, which will be more expensive than it needs to be. + (or (zerop (call-process + "emacs" nil nil nil + "-q" "--batch" "-l" "ob-tangle" "--eval" + (format "(org-babel-tangle-file \"%s\" \"%s\" \"emacs-lisp\")" + org +literate-config-dest-file))) + (error "There was a problem tangling your literate config!")) + + ;; Then byte-compile it! + (require 'bytecomp) + (byte-compile-file +literate-config-dest-file))) + +;; No need to load the resulting file. Doom will do this for us after all +;; modules have finished loading.