Browse Source

how to change Clojure working directory in ob-clojure.

stardiviner 10 months ago
1 changed files with 20 additions and 0 deletions
  1. 20 0

+ 20 - 0

@@ -287,6 +287,26 @@ You can see the second code block still us individual namespace.
 : nil#'kk2/he#namespace[kk2
+* Change Clojure cwd in Org-mode way
+As this blog post [[][Clojure Plotting to Org inline image in ob-clojure]] mentioned.
+Because Clojure is based on JVM, can JVM does not allow to dynamically
+change current working directory (=cwd=). So if you use =ob-clojure= in
+Org-mode, and need to interact with path, directory, file etc. You
+need to figure other ways. Here is an Org-mode way, use header
+argument ~:var~ to pass current buffer's path into Clojure, then use
+this dir variable in Clojure to construct a correct path.
+#+begin_src org
+,#+begin_src clojure :results graphics :dir "data/images" :file "ob-clojure-literate.png" :var dir=(concat (file-name-directory (buffer-file-name)) "data/images/")
+(use '(incanter core stats datasets charts io pdf))
+(def hist (histogram (sample-normal 1000)))
+(save hist (str dir "ob-clojure-literate.png"))
 * Additional Examples
 The above set-up and examples were intended for the beginner to achieve success