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

前端 未结 4 823
梦毁少年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:33

    There is now https://github.com/weavejester/cljfmt for that purpose

    Instructions

    Add it in your Leiningen plugins:

    :plugins [[lein-cljfmt "0.6.1"]]
    

    Then, to autoformat all code in your project:

    lein cljfmt fix
    

    Sample

    Your sample code will become:

    (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)))])))))
    

    After adding some linebreaks and reformatting again:

    (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)))])))))
    

提交回复
热议问题