-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Make doom +org tangle
CLI load any available ob-<lang>
libraries for the source langs of noweb-addressable blocks
#8406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
doom +org tangle
CLI load any available ob-<lang>
libraries for the source langs of noweb-addressable blocks
modules/lang/org/cli.el
Outdated
;; evaluated even if it will not be tangled per se | ||
(if-let ((src-noweb-ref) | ||
(ob-library-name (concat "ob-" src-lang)) | ||
(locate-library ob-library-name)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is binding ob-library-name
to locate-library
, it isn't calling the locate-library
function. Wrap in another set of parentheses:
(if-let ((src-noweb-ref)
(ob-library-name (concat "ob-" src-lang))
- (locate-library ob-library-name))
+ ((locate-library ob-library-name)))
(require (intern ob-library-name)))
modules/lang/org/cli.el
Outdated
(cdr (assq :noweb-ref (nth 2 info)))))) | ||
;; a block which can be referenced via noweb may need to be | ||
;; evaluated even if it will not be tangled per se | ||
(if-let ((src-noweb-ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please swap out if-let
with when-let*
when the else
branch isn't used.
For performance reasons, Doom CLI runs in a minimal environment wherein no `ob-<language>` libraries are initially loaded; but tangling a document with noweb-enabled blocks can trigger an org-babel evaluation of any noweb-addressable block; and any such evaluation will fail tangling with an error unless the correct `ob-<language>` library has been loaded. So. This changes the tangle CLI function to note any noweb-addressable labels (i.e. any `#+NAME:` or `:noweb-ref` associated with a block) when iterating through the source document's blocks; for each block where one is found, it conditionally attempts to `require` the corresponding `ob-<src-lang>` library.
d1ff35b
to
9802a65
Compare
Good catches both! I tested some noweb-injected content with
Fixed up the commit and re-pushed. |
the issue here
It's a three-prong problem:
doom +org tangle
run in a minimal environment in which only strictly necessary libraries are preloadedob-<language>
library has not been loadedPut it all together and, well, 💥
how to fix that
This updates the code inside tangle CLI's
org-babel-tangle-collect-blocks
function; its per-blocklet*
form gets a newsrc-noweb-ref
binding to store noweb-addressable labels (i.e. any#+NAME:
or:noweb-ref
associated with a block) when iterating through the source document's src blocks; when such a label and a correspondingob-<labeled src block's lang>
library can be found, itrequire
s the library, making it available for future noweb expansion.no pre-existing issues or PRs for this
A search for
tangle cli
in the repo's issues shows no results of any sort besides #4273, which is pretty specifically centered on the config bootstrapping behavior ofdoom {install,sync}
.how I found it, plus a minimal repro and some test output in a dropdown
I personally ran into this when experimenting with using
doom +org tangle
to automate generating some dotfiles; it was specifically triggered by a kmonad config I tangled from an org file so I could git-track and share a single, hardware-independent1 source of truth between an old macbook and a thinkpad while still dynamically generating a hardware-specifickmonad.kbd
for each.To reproduce the bug I made this minimal version of the offending kmonad literate config:
I put those lines in a file—I used
/tmp/org/test.org
—and tried tangling it via CLI on both themaster
andrequire-all-potentially-needed-ob-libraries-in-org-tangle-cli
branches2. I've included the shell output of my own test run below:Shell output of manually reproducing the bug and testing the fix (not in that order, though)
Footnotes
well, the hardware has to run linux ↩
a fun sideplot to dipping into CLI code is that the same sandboxed environment that makes doom CLI's startup time doom-config-independent means there's no need to wait on any
doom sync
runs when A/B testing a change. ↩