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
This commit is contained in:
parent
df3c221c73
commit
8424e0a780
2 changed files with 20 additions and 58 deletions
|
@ -86,21 +86,6 @@ echo Hello world
|
||||||
You'll find more information about babel src blocks and what parameters they
|
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]].
|
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
|
* Troubleshooting
|
||||||
** How to tangle to =DOOMDIR/init.el=
|
** How to tangle to =DOOMDIR/init.el=
|
||||||
If your literate needs are more complex (e.g. you want to make your init.el
|
If your literate needs are more complex (e.g. you want to make your init.el
|
||||||
|
|
|
@ -24,55 +24,32 @@ byte-compiled from.")
|
||||||
(target +literate-config-file)
|
(target +literate-config-file)
|
||||||
(cache +literate-config-cache-file)
|
(cache +literate-config-cache-file)
|
||||||
(dest (expand-file-name (concat doom-module-config-file ".el")))
|
(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
|
;; Ensure output conforms to the formatting of all doom CLIs
|
||||||
(defun message (msg &rest args)
|
(defun message (msg &rest args)
|
||||||
(when msg
|
(when msg
|
||||||
(print! (info "%s") (apply #'format msg args)))))
|
(print! (info "%s") (apply #'format msg args)))))
|
||||||
(print! (start "Compiling your literate config..."))
|
(print! (start "Compiling your literate config..."))
|
||||||
(print-group!
|
(print-group!
|
||||||
(unwind-protect
|
(let (;; Do as little unnecessary work as possible in these org files.
|
||||||
(with-temp-file backup
|
(org-startup-indented nil)
|
||||||
(insert-file-contents target)
|
(org-startup-folded nil)
|
||||||
(let ((buffer-file-name backup)
|
(vc-handled-backends nil)
|
||||||
;; Prevent unwanted entries in recentf, or formatters, or
|
;; Prevent unwanted entries in recentf, or formatters, or
|
||||||
;; anything that could be on these hooks, really. Nothing
|
;; anything that could be on these hooks, really. Nothing else
|
||||||
;; else should be touching these files (particularly in
|
;; should be touching these files (particularly in interactive
|
||||||
;; interactive sessions).
|
;; sessions).
|
||||||
(write-file-functions nil)
|
(write-file-functions nil)
|
||||||
(before-save-hook nil)
|
(before-save-hook nil)
|
||||||
(after-save-hook nil)
|
(after-save-hook nil)
|
||||||
;; Prevent infinite recursion due to recompile-on-save
|
;; Prevent infinite recursion due to recompile-on-save hooks
|
||||||
;; hooks later, and speed up `org-mode' init.
|
;; later, and speed up `org-mode' init.
|
||||||
(org-mode-hook nil)
|
(org-mode-hook nil)
|
||||||
(org-inhibit-startup t)
|
(org-inhibit-startup t)
|
||||||
;; Allow evaluation of src blocks at tangle-time (would
|
;; Allow evaluation of src blocks at tangle-time (would abort
|
||||||
;; abort them otherwise). This is a security hazard, but
|
;; them otherwise). This is a security hazard, but Doom will
|
||||||
;; Doom will trust that you know what you're doing!
|
;; trust that you know what you're doing!
|
||||||
(org-confirm-babel-evaluate nil))
|
(org-confirm-babel-evaluate nil))
|
||||||
(org-mode)
|
(org-babel-tangle-file target dest))
|
||||||
(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)))
|
|
||||||
;; Write an empty file to serve as our mtime cache
|
;; Write an empty file to serve as our mtime cache
|
||||||
(with-temp-file cache)
|
(with-temp-file cache)
|
||||||
(if doom-interactive-p t
|
(if doom-interactive-p t
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue