UP | HOME
Kristian Alexander P

Kristian Alexander

Free Software Enthusiast | GNU Emacs User

Conditional Code-block in Org-mode

Published on Jun 02, 2022 by Kristian Alexander P.

Literate Programming   org mode codeblocks

Two classical operations in literate programming1:

Tangle
Extract the source code blocks and generate real working code files for further compilation or execution, eventually outside of Emacs.
Weave
Export the whole Org file as literate, human-readable documentation (generally in HTML or LaTeX).

Furthermore, we can conditionally instruct which code blocks to evaluate by using emacs lisp in the code block header arguments.

Example

#+begin_src emacs-lisp :exports (if (string= "freebsd" (downcase (substring (shell-command-to-string "uname -s") 0 -1))) "both" "none") :results verbatim
  (print "this will only evaluated on freebsd")
#+end_src

Footnotes: