From 8424e0a780534de89f44dbe5b5e90f6b77fffdee Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 24 May 2021 17:52:27 -0400 Subject: [PATCH] config/literate: simplify tangle process This removes expansion of #+INCLUDE directives at tangle time because it's too much trouble to maintain a workflow that org doesn't support, without modifying the user's files, which goes against Doom's "your system your rules" mantra. The tangling process is just too brittle to hack without compounding edge cases. Fixes #5089 --- modules/config/literate/README.org | 15 ------- modules/config/literate/autoload.el | 63 +++++++++-------------------- 2 files changed, 20 insertions(+), 58 deletions(-) diff --git a/modules/config/literate/README.org b/modules/config/literate/README.org index b723f6dca..61d320d14 100644 --- a/modules/config/literate/README.org +++ b/modules/config/literate/README.org @@ -86,21 +86,6 @@ echo Hello world You'll find more information about babel src blocks and what parameters they support [[https://orgmode.org/manual/Working-with-Source-Code.html][in the manual]]. -** Modularizing your literate config with ~#+INCLUDE~ directives -Literate configs can be split up into separate files and imported into a central -=config.org= using the ~#+INCLUDE~ org directive. Here are some examples: -#+BEGIN_SRC org -,#+INCLUDE other-file.org -,#+INCLUDE: "~/my-book/chapter2.org" :minlevel 1 -,#+INCLUDE: "~/.emacs" :lines "5-10" -,#+INCLUDE: "~/.emacs" :lines "-10" -,#+INCLUDE: "~/.emacs" :lines "10-" -,#+INCLUDE: "./paper.org::*conclusion" :lines 1-20 -,#+INCLUDE: "./paper.org::#theory" :only-contents t -#+END_SRC - -See [[https://orgmode.org/manual/Include-Files.html][this entry in the Emacs manual]] for more on this directive. - * Troubleshooting ** How to tangle to =DOOMDIR/init.el= If your literate needs are more complex (e.g. you want to make your init.el diff --git a/modules/config/literate/autoload.el b/modules/config/literate/autoload.el index 4b7e5b3f8..72a00436f 100644 --- a/modules/config/literate/autoload.el +++ b/modules/config/literate/autoload.el @@ -24,55 +24,32 @@ byte-compiled from.") (target +literate-config-file) (cache +literate-config-cache-file) (dest (expand-file-name (concat doom-module-config-file ".el"))) - ;; Operate on a copy because `org-babel-tangle' has - ;; side-effects we need to undo immediately as not to - ;; overwrite the user's config; it's bad ettiquite. - (backup (make-temp-file (concat (file-name-nondirectory target) "."))) - - ;; HACK A hack to prevent ob-tangle from operating relative to - ;; the backup file and thus tangling to the wrong - ;; destinations. - (defun org-babel-tangle-single-block (&rest args) - (let* ((spec (apply org-babel-tangle-single-block args)) - (file (nth 1 spec)) - (file (if (file-equal-p file backup) target file)) - (file (if org-babel-tangle-use-relative-file-links - (file-relative-name file) - file))) - (setf (nth 1 spec) file) - spec)) ;; Ensure output conforms to the formatting of all doom CLIs (defun message (msg &rest args) (when msg (print! (info "%s") (apply #'format msg args))))) (print! (start "Compiling your literate config...")) (print-group! - (unwind-protect - (with-temp-file backup - (insert-file-contents target) - (let ((buffer-file-name backup) - ;; Prevent unwanted entries in recentf, or formatters, or - ;; anything that could be on these hooks, really. Nothing - ;; else should be touching these files (particularly in - ;; interactive sessions). - (write-file-functions nil) - (before-save-hook nil) - (after-save-hook nil) - ;; Prevent infinite recursion due to recompile-on-save - ;; hooks later, and speed up `org-mode' init. - (org-mode-hook nil) - (org-inhibit-startup t) - ;; Allow evaluation of src blocks at tangle-time (would - ;; abort them otherwise). This is a security hazard, but - ;; Doom will trust that you know what you're doing! - (org-confirm-babel-evaluate nil)) - (org-mode) - (with-silent-modifications - ;; Tangling won't ordinarily expand #+INCLUDE directives, - ;; so I do it myself. - (org-export-expand-include-keyword) - (org-babel-tangle nil dest)))) - (ignore-errors (delete-file backup))) + (let (;; Do as little unnecessary work as possible in these org files. + (org-startup-indented nil) + (org-startup-folded nil) + (vc-handled-backends nil) + ;; Prevent unwanted entries in recentf, or formatters, or + ;; anything that could be on these hooks, really. Nothing else + ;; should be touching these files (particularly in interactive + ;; sessions). + (write-file-functions nil) + (before-save-hook nil) + (after-save-hook nil) + ;; Prevent infinite recursion due to recompile-on-save hooks + ;; later, and speed up `org-mode' init. + (org-mode-hook nil) + (org-inhibit-startup t) + ;; Allow evaluation of src blocks at tangle-time (would abort + ;; them otherwise). This is a security hazard, but Doom will + ;; trust that you know what you're doing! + (org-confirm-babel-evaluate nil)) + (org-babel-tangle-file target dest)) ;; Write an empty file to serve as our mtime cache (with-temp-file cache) (if doom-interactive-p t