是否有一种方法可以在clojure sublimeREPL中使用pprint代替常规打印?
目前,我必须这样包装代码才能这样做:
(clojure.pprint/pprint (for [i (range 10)] {i {:times2 (* i 2) :times3 (* i 3)}}))
=> ({0 {:times2 0, :times3 0}}
{1 {:times2 2, :times3 3}}
{2 {:times2 4, :times3 6}}
{3 {:times2 6, :times3 9}}
{4 {:times2 8, :times3 12}}
{5 {:times2 10, :times3 15}}
{6 {:times2 12, :times3 18}}
{7 {:times2 14, :times3 21}}
{8 {:times2 16, :times3 24}}
{9 {:times2 18, :times3 27}})很抱歉给你举了个假例子
发布于 2013-12-17 15:58:29
您可以使用简单的nrepl中间件来完成,例如:
(defn pprint-middleware [h]
(fn [{:keys [code op] :as msg}]
(if (and (= op "eval") (not (empty? code)))
(->> #(str "(clojure.pprint/pprint " % ")")
(update-in msg [:code])
h)
(h msg))))将其添加到repl中的最简单方法是在您的repl-options中配置project.clj。
:repl-options {:nrepl-middleware [nrepl.utils/pprint-middleware]})下面是完整的project.clj示例:
(defproject sample "0.1.0"
:dependencies [[org.clojure/clojure "1.4.0"]]
:repl-options {:nrepl-middleware [sample.utils/pprint-middleware]})https://stackoverflow.com/questions/20630034
复制相似问题