From b49bbba7bcabcc47d9edd33cf6d6f4461a1bd66a Mon Sep 17 00:00:00 2001 From: AChavali Date: Tue, 31 Dec 2019 13:42:06 +0000 Subject: ~renamed some stuff and moved around sections --- doom.d/modules/literate.org | 50 ++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) (limited to 'doom.d/modules') diff --git a/doom.d/modules/literate.org b/doom.d/modules/literate.org index 9a0b7b5..302ef5a 100644 --- a/doom.d/modules/literate.org +++ b/doom.d/modules/literate.org @@ -4,8 +4,8 @@ My setup to produce a literate configuration. Allows me to write org files all around the /doom-private-dir/ and access them. Also shaved like 0.2s off my loading time. -* Variables -Initialise some basic constants for where stuff is +* Constants +Initialise some basic constants for where stuff is. #+BEGIN_SRC elisp (setq oreodave/literate/bin-dir (expand-file-name (concat doom-private-dir "bin/"))) (setq oreodave/literate/preloaded-files (list "README.org" "modules/config.org" "modules/literate.org")) @@ -21,6 +21,15 @@ expanded file names. (let ((parsed-remove-files (map 'list #'(lambda (i) (expand-file-name (concat doom-private-dir i))) remove-files))) (remove-if-not #'(lambda (l) (not (member l parsed-remove-files))) files))) #+END_SRC +* Destination for parser +Generate the destination for a literate config org file to parse to, in this +case the bin folder in the private directory +#+BEGIN_SRC elisp +(defun oreodave/literate/destination(SRC) + (replace-regexp-in-string ".*/\\(\\w+\\).org" (expand-file-name (concat oreodave/literate/bin-dir "\\1.el")) SRC)) +#+END_SRC +This is not fitted onto the parser because the parser could be fitted to +multiple /differing/ outputs easily if it isn't specified a destination. * Parser First we need to get some sort of parser which can, given a source org file and a destination, parse and produce an Emacs lisp file. We'll copy this from the @@ -43,15 +52,22 @@ literate module of doom. (warn (format "Problem with tanging %S to %S" SRC DEST))) (kill-buffer output)))))) #+END_SRC -* Destination for parser -Generate the destination for a literate config org file to parse to, in this -case the bin folder in the private directory +* Hook on save +Now we need to make a hook function that, when the current buffer is an org file +in the doom directory, will run the literate config procedure from above. Use +this hook function and add it to the after-save-hook once org mode has been +loaded. README.org has been added as an exception because it doesn't contain +literate contents. #+BEGIN_SRC elisp -(defun oreodave/literate/destination(SRC) - (replace-regexp-in-string ".*/\\(\\w+\\).org" (expand-file-name (concat oreodave/literate/bin-dir "\\1.el")) SRC)) +(defun oreodave/literate/compile-hook () + (when (and (eq major-mode 'org-mode) + (file-in-directory-p buffer-file-name doom-private-dir) + (not (string= buffer-file-name (expand-file-name (concat doom-private-dir "README.org"))))) + (oreodave/literate/tangle buffer-file-name (oreodave/literate/destination buffer-file-name)))) + +(after! org + (add-hook 'after-save-hook #'oreodave/literate/compile-hook)) #+END_SRC -This is not fitted onto the parser because the parser could be fitted to -multiple /differing/ outputs easily if it isn't specified a destination. * Procedure for all files A procedure that parses all the org files in a given directory into Emacs lisp files, using the parser function made. Assume all org files in the "location" @@ -68,22 +84,6 @@ directory contribute to the config. #+END_SRC The location is not set because this function could be easily programmed to use multiple /differing/ sources to produce the config. -* Hook on save -Now we need to make a hook function that, when the current buffer is an org file -in the doom directory, will run the literate config procedure from above. Use -this hook function and add it to the after-save-hook once org mode has been -loaded. README.org has been added as an exception because it doesn't contain -literate contents. -#+BEGIN_SRC elisp -(defun oreodave/literate/compile-hook () - (when (and (eq major-mode 'org-mode) - (file-in-directory-p buffer-file-name doom-private-dir) - (not (string= buffer-file-name (expand-file-name (concat doom-private-dir "README.org"))))) - (oreodave/literate/tangle buffer-file-name (oreodave/literate/destination buffer-file-name)))) - -(after! org - (add-hook 'after-save-hook #'oreodave/literate/compile-hook)) -#+END_SRC * Load configuration Final step of the literate cycle: load the config for the first time. #+BEGIN_SRC elisp -- cgit v1.2.3-13-gbd6f