2
votes

We want to automate the production of a Leiningen project tree entirely from an org-mode babel file. We want to do this so that we can also create beautiful, typeset documentation via org-latex-export-to-pdf. We want no less than full literate programming in Clojure from org-mode.

The following command:

$ lein new ex1

produces a tree that looks like this:

ex1
ex1/.gitignore
ex1/doc
ex1/doc/intro.md
ex1/project.clj
ex1/README.md
ex1/resources
ex1/src
ex1/src/ex1
ex1/src/ex1/core.clj
ex1/test
ex1/test/ex1
ex1/test/ex1/core_test.clj

We want to do the identical thing just by running org-babel-tangle, and no more, in our org-mode buffer in emacs.

A difficulty arises: whereas tangle is happy to produce files in existing subdirectories like src and test, it seems reluctant to produce the subdirectories if they don't exist. That means we must create the directory structure by some other means -- unless we can get tangle to do it for us, and that's the subject of this StackOverflow question.

There are six files in the directory structure created by Leiningen. I can remove them all and re-create them from my org-file with BEGIN_SRC blocks such as the following

#+BEGIN_SRC clojure :tangle ./ex1/src/ex1/core.clj
(ns ex1.core)

(defn foo
  "I don't do a whole lot."
  [x]
  (println x "Hello, World!"))
#+END_SRC

Notice particularly the name of the subdirectory path

#+BEGIN_SRC clojure :tangle ./ex1/src/ex1/core.clj

All is well if our directory structure already exists. org-mode's tangle will create or update all six files described above and create new files in any existing directory. We don't know how to get tangle to produce the directories; it complains that there is no such directory.

A copy of the desired .org file can be found here if you would like more details.

2
Have you considered fogus.github.io/marginalia/ as a starting point?Leon Grapenthin
looking at it now -- didn't know about itReb.Cabin
my .2c org-babel is much more powerfull than marginaliaHamza Yerlikaya
Our use-case for babel is the we have a lot of mathematics that we need type-set in LaTeX, plus lots of diagrams a-la Tikz and PGF, and we really want the Clojure code right next door so we have a fighting chance that the code and the documentation will not drift. Our document / code / project will run to well over 1k pages.Reb.Cabin

2 Answers

9
votes

It is possible use the following header in the begin_src section,

:mkdirp yes
0
votes

FYI There's now a lein project template for using org based projects:

https://github.com/thi-ng/thing-babel