#+title: Org Babel: Literate Programming #+date: [2024-04-05 Fri] #+filetags: :org:babel: #+identifier: 20240405T140000 * What is Org Babel Org Babel lets you embed executable code blocks inside org files and run them directly. Results are captured inline below the block. * Supported languages Python, Emacs Lisp, Shell, SQL, R, Julia, Haskell, and dozens more. #+begin_src emacs-lisp (org-babel-do-load-languages 'org-babel-load-languages '((python . t) (shell . t) (sql . t) (emacs-lisp . t))) #+end_src * Example: Python block #+begin_src python :results output words = ["denote", "emacs", "org", "babel"] for w in words: print(w.upper()) #+end_src * Example: Shell #+begin_src sh :results output ls ~/notes/ | head -5 #+end_src * Tangle: exporting code to files The =:tangle= header exports the code block to a file on disk. #+begin_src emacs-lisp :tangle ~/.emacs.d/init.el (setq inhibit-startup-message t) (menu-bar-mode -1) (tool-bar-mode -1) #+end_src Running =C-c C-v t= writes the block to the target file.