Is there an easy way to dump code blocks in org-mode to files? Somehow naming them via markup near code-blocks perhaps? Maybe an export or something?
Use the :tangle keyword in your source block (see https://orgmode.org/manual/Extracting-Source-Code.html)
Example:
#+begin_src emacs-lisp :tangle "init.el"
(defmacro add-hook! (hook &rest body)
"Nicer add-hooking that prevents writing lambdas explicitly.
Add a lambda containing BODY to hook HOOK."
(declare (indent 1))
`(add-hook ,hook
(lambda () ,@body)))
#+end_src
After doing M-x org-babel-tangle, the code block is exported to "init.el"
The above is part of my init.org file. At the end of my init.org, I have this:
* COMMENT Local Variables for auto-tangle :ARCHIVE:
# Local Variables:
# eval: (add-hook 'after-save-hook (lambda ()(org-babel-tangle)) nil t)
# End:
init.el
This updates the init.el after each safe of my init.org automatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With