Is there an online tool to auto-indent and format Clojure code like there are many for JSON?

前端 未结 4 810
梦毁少年i
梦毁少年i 2021-02-19 00:23

There are a lot of tools online that take a JSON text and show you formatted and well indented format of the same.

Some go even further and make a nice tree-like structu

4条回答
  •  情歌与酒
    2021-02-19 00:46

    Have a look at https://github.com/xsc/rewrite-clj It is brand new and does exactly what you are asking for.

    EDIT I am still getting upvotes for this. I believe I found a better solution: You can easily do this with clojure.pprint utilizing code-dispatch without using an external library.

    (clojure.pprint/write '(defn prime? [n known](loop [cnt (dec (count known)) acc []](if (< cnt 0) (not (any? acc))                                                                                                 (recur (dec cnt) (concat acc [(zero? (mod n (nth known cnt)))]))))) 
      :dispatch clojure.pprint/code-dispatch)
    => 
    (defn prime? [n known]
      (loop [cnt (dec (count known)) acc []]
        (if (< cnt 0)
          (not (any? acc))
          (recur
            (dec cnt)
            (concat acc [(zero? (mod n (nth known cnt)))])))))
    

提交回复
热议问题