clojure.pprint/write
与 一起使用code-dispatch
。
(clojure.pprint/write
'(apply + 0 [1 2 3 4])
:dispatch clojure.pprint/code-dispatch)
它不会给你你想要的缩进,因为应用形式太短,而且你的换行符只对最后一个参数是相当随意的。但是,如果您想打印 Clojure 代码,这是正确的做法。它将正确打印 let- 和其他各种表格。
这是一个较长形式的示例
(clojure.pprint/write
'(defn plugin
"A leiningen plugin project template."
[name]
(let [render (renderer "plugin")
unprefixed (if (.startsWith name "lein-")
(subs name 5)
name)
data {:name name,
:unprefixed-name unprefixed,
:sanitized (sanitize unprefixed),
:year (year)}]
(main/info
(str "Generating a fresh Leiningen plugin called " name "."))
(->files
data
["project.clj" (render "project.clj" data)]
["README.md" (render "README.md" data)]
[".gitignore" (render "gitignore" data)]
["src/leiningen/{{sanitized}}.clj" (render "name.clj" data)]
["LICENSE" (render "LICENSE" data)])))
:dispatch
clojure.pprint/code-dispatch)
=>
(defn plugin
"A leiningen plugin project template."
[name]
(let [render (renderer "plugin")
unprefixed (if (.startsWith name "lein-") (subs name 5) name)
data {:name name,
:unprefixed-name unprefixed,
:sanitized (sanitize unprefixed),
:year (year)}]
(main/info
(str "Generating a fresh Leiningen plugin called " name "."))
(->files
data
["project.clj" (render "project.clj" data)]
["README.md" (render "README.md" data)]
[".gitignore" (render "gitignore" data)]
["src/leiningen/{{sanitized}}.clj" (render "name.clj" data)]
["LICENSE" (render "LICENSE" data)])))