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.
LaTeX
, plus lots of diagrams a-laTikz
andPGF
, 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