2

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.

4

2 回答 2

9

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

:mkdirp yes
于 2013-08-18T19:12:13.087 回答
0

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

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

于 2014-03-05T15:57:30.847 回答