0

I'd like to tangle the emacs configuration externally, instead of doing it from inside emacs.

It's really hard to debug if the tangle is done in init.el

How can I tangle the configuration org-file from outside of Emacs, then call that .el file from init.el?;)

1 Answer 1

0

Org literate configs rely on babel to tangle their source into a .el file that emacs reads. That means that, luckily for us, there is no reason that the tangling process has to stay within just emacs. There are plenty of org-tangle implementations available online to choose from.

I will show a method available to Doom Emacs users, since that project has an accessible on/off switch for literate configs. The org-tangle script can be used from the command line. (If you are using doom emacs, org-tangle is provided in .emacs.d/bin/org-tangle.)

From the docstring of org-tangle:

;; Usage: org-tangle [[-l|--lang] LANG] some-file.org another.org
;; Examples:
;;   org-tangle -l sh modules/some/module/README.org > install_module.sh
;;   org-tangle -l sh modules/lang/go/README.org | sh
;;   org-tangle --and tagA --and tagB my/literate/config.org

In summary: Use a org-tangle script from your terminal to tangle your config outside emacs.

Edit: As @mmmmmm has noted in the comments below, the tanglers I posted here do not have noweb support for references. This may pose limitations on certain use cases for tangling outside emacs. If you know of an org-tangler with noweb_ref support, please post a comment to this answer.

8
  • 1
    Unfortunately no of these support noweb references so are in effect not of much use.
    – mmmmmm
    Oct 26, 2022 at 17:05
  • great, but how about calling this org-tangle from inside emacs, but actually calling the resulting .el file for the config? That would mean emacs could give sensible errors when something goes wrong?;) Oct 26, 2022 at 18:46
  • Like any other shell command, you can use M-x shell-command to run a script from emacs. You can then load your resulting config using (setq user-init-file "path/here") and (load user-init-file). If you aren't looking to load the config (I am not sure what "run the resulting file" means for elisp source), you can run a standard eval command with the expected file name as input.
    – Malle Yeno
    Oct 26, 2022 at 21:43
  • @mmmmmm If noweb is needed, I found worgle which claims to support noweb. I have not tested it myself so I can't confirm the claim, but here's the link: paulbatchelor.github.io/proj/worgle
    – Malle Yeno
    Oct 26, 2022 at 21:49
  • 1
    @MalleYeno That does not seem to allow noweb_ref - just names via NAME
    – mmmmmm
    Oct 26, 2022 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.